ContentFormatter Class Referenceabstract

#include <Pt/Mcp/ContentType.h>

Writes the wrapper bytes of an MCP content block around a Formatter. More...

Public Member Functions

Pt::FormatterbeginContent (std::ostream &os)
 Writes the opening bytes of the content block to os and returns the Formatter the result is to be decomposed into.
 
void finishContent (std::ostream &os)
 Flushes buffered output and writes the closing bytes of the content array to os.
 

Protected Member Functions

virtual void onBeginContent ()=0
 Writes the opening bytes of the concrete content block. More...
 
virtual Pt::FormatteronBeginFormat ()=0
 Returns the Formatter the decomposed result is drained into. More...
 
virtual void onFinishContent ()=0
 Writes the closing bytes of the concrete content block.
 
void write (const char *s, std::size_t n)
 Writes raw bytes to the output stream.
 
std::ostream & output () const
 Returns the output stream passed to beginContent().
 

Detailed Description

ContentFormatter adds the begin/finish protocol for the enclosing content block (e.g. {"type":"text","text":"...")) around an existing Pt::Formatter: beginFormat() writes the opening bytes and returns the Pt::Formatter the decomposed result is drained into via Decomposer::beginFormat() and Decomposer::advanceFormat(); finishFormat() flushes any buffered output and writes the closing bytes once the result is fully drained. A ContentFormatter does not need to be a Formatter itself - it may wrap an existing one. Instances are created by ContentType::getFormatter() and must be released via ContentType::releaseFormatter().

Member Function Documentation

◆ onBeginContent()

virtual void onBeginContent ( )
protectedpure virtual

Implementations write the type-specific opening JSON, e.g. {"type":"text","text":".

◆ onBeginFormat()

virtual Pt::Formatter& onBeginFormat ( )
protectedpure virtual

Called by beginContent() after onBeginContent() has written the opening bytes.