![]() |
ezEngine Release 26.9
|
Writes the JSON that tool results and protocol responses are made of. More...
#include <McpJsonWriter.h>

Public Member Functions | |
| ezStringView | GetResult () |
| The JSON written so far. | |
| virtual void | WriteVariant (const ezVariant &value) override |
Public Member Functions inherited from ezStandardJSONWriter | |
| ezStandardJSONWriter () | |
| Constructor. | |
| ~ezStandardJSONWriter () | |
| Destructor. | |
| void | SetOutputStream (ezStreamWriter *pOutput) |
| All output is written to this binary stream. | |
| virtual void | WriteBool (bool value) override |
| Writes a bool to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteInt32 (ezInt32 value) override |
| Writes an int32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteUInt32 (ezUInt32 value) override |
| Writes a uint32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteInt64 (ezInt64 value) override |
| Writes an int64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteUInt64 (ezUInt64 value) override |
| Writes a uint64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteFloat (float value) override |
| Writes a float to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteDouble (double value) override |
| Writes a double to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteString (ezStringView value) override |
| Writes a string to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteNULL () override |
| Writes the value 'null' to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteTime (ezTime value) override |
| Writes the time value as a double (i.e. redirects to WriteDouble()). | |
| virtual void | WriteColor (const ezColor &value) override |
| Writes {"r":..,"g":..,"b":..,"a":..} with the linear float components. | |
| virtual void | WriteColorGamma (const ezColorGammaUB &value) override |
| Writes {"r":..,"g":..,"b":..,"a":..} with the gamma space components, i.e. 0 to 255. | |
| virtual void | WriteVec2 (const ezVec2 &value) override |
| Writes {"x":..,"y":..}. | |
| virtual void | WriteVec3 (const ezVec3 &value) override |
| Writes {"x":..,"y":..,"z":..}. | |
| virtual void | WriteVec4 (const ezVec4 &value) override |
| Writes {"x":..,"y":..,"z":..,"w":..}. | |
| virtual void | WriteVec2I32 (const ezVec2I32 &value) override |
| Writes {"x":..,"y":..}. | |
| virtual void | WriteVec3I32 (const ezVec3I32 &value) override |
| Writes {"x":..,"y":..,"z":..}. | |
| virtual void | WriteVec4I32 (const ezVec4I32 &value) override |
| Writes {"x":..,"y":..,"z":..,"w":..}. | |
| virtual void | WriteQuat (const ezQuat &value) override |
| Writes {"x":..,"y":..,"z":..,"w":..}, the same layout the property system uses. | |
| virtual void | WriteMat3 (const ezMat3 &value) override |
| Writes the matrix row by row, as an array of arrays. | |
| virtual void | WriteMat4 (const ezMat4 &value) override |
| Writes the matrix row by row, as an array of arrays. | |
| virtual void | WriteUuid (const ezUuid &value) override |
| Writes the hyphenated string form, i.e. what ezConversionUtils::ToString() produces. | |
| virtual void | WriteAngle (ezAngle value) override |
| Writes the angle in degrees (i.e. redirects to WriteFloat()). | |
| virtual void | WriteDataBuffer (const ezDataBuffer &value) override |
| Writes the bytes as a hex string, which is twice the size of the data. | |
| virtual void | WriteBinaryData (ezStringView sDataType, const void *pData, ezUInt32 uiBytes, ezStringView sValueString=nullptr) override |
| Implements the MongoDB way of writing binary data. First writes a "$type" variable, then a "$binary" variable that represents the raw data (Hex encoded, little endian). | |
| virtual void | BeginVariable (ezStringView sName) override |
| Begins outputting a variable. szName is the variable name. | |
| virtual void | EndVariable () override |
| Ends outputting a variable. | |
| virtual void | BeginArray (ezStringView sName={}) override |
| Begins outputting an array variable. | |
| virtual void | EndArray () override |
| Ends outputting an array variable. | |
| virtual void | BeginObject (ezStringView sName={}) override |
| Begins outputting an object variable. | |
| virtual void | EndObject () override |
| Ends outputting an object variable. | |
| void | WriteRawJson (ezStringView sJson) |
| Writes text that is already valid JSON in place, without any escaping of special characters. | |
| void | AddVariableRawJson (ezStringView sName, ezStringView sJson) |
| Shorthand for "BeginVariable(sName); WriteRawJson(sJson); EndVariable();". | |
| void | EndAll () |
| Closes every object and array that is still open, so that the output becomes valid JSON. | |
Public Member Functions inherited from ezJSONWriter | |
| ezJSONWriter () | |
| Constructor. | |
| virtual | ~ezJSONWriter () |
| Destructor. | |
| void | SetWhitespaceMode (WhitespaceMode whitespaceMode) |
| Configures how much whitespace is output. | |
| void | SetArrayMode (ArrayMode arrayMode) |
| Configures how arrays are written. | |
| void | AddVariableBool (ezStringView sName, bool value) |
| Shorthand for "BeginVariable(szName); WriteBool(value); EndVariable(); ". | |
| void | AddVariableInt32 (ezStringView sName, ezInt32 value) |
| Shorthand for "BeginVariable(szName); WriteInt32(value); EndVariable(); ". | |
| void | AddVariableUInt32 (ezStringView sName, ezUInt32 value) |
| Shorthand for "BeginVariable(szName); WriteUInt32(value); EndVariable(); ". | |
| void | AddVariableInt64 (ezStringView sName, ezInt64 value) |
| Shorthand for "BeginVariable(szName); WriteInt64(value); EndVariable(); ". | |
| void | AddVariableUInt64 (ezStringView sName, ezUInt64 value) |
| Shorthand for "BeginVariable(szName); WriteUInt64(value); EndVariable(); ". | |
| void | AddVariableFloat (ezStringView sName, float value) |
| Shorthand for "BeginVariable(szName); WriteFloat(value); EndVariable(); ". | |
| void | AddVariableDouble (ezStringView sName, double value) |
| Shorthand for "BeginVariable(szName); WriteDouble(value); EndVariable(); ". | |
| void | AddVariableString (ezStringView sName, ezStringView value) |
| Shorthand for "BeginVariable(szName); WriteString(value); EndVariable(); ". | |
| void | AddVariableNULL (ezStringView sName) |
| Shorthand for "BeginVariable(szName); WriteNULL(value); EndVariable(); ". | |
| void | AddVariableTime (ezStringView sName, ezTime value) |
| Shorthand for "BeginVariable(szName); WriteTime(value); EndVariable(); ". | |
| void | AddVariableUuid (ezStringView sName, ezUuid value) |
| Shorthand for "BeginVariable(szName); WriteUuid(value); EndVariable(); ". | |
| void | AddVariableAngle (ezStringView sName, ezAngle value) |
| Shorthand for "BeginVariable(szName); WriteAngle(value); EndVariable(); ". | |
| void | AddVariableColor (ezStringView sName, const ezColor &value) |
| Shorthand for "BeginVariable(szName); WriteColor(value); EndVariable(); ". | |
| void | AddVariableColorGamma (ezStringView sName, const ezColorGammaUB &value) |
| Shorthand for "BeginVariable(szName); WriteColorGamma(value); EndVariable(); ". | |
| void | AddVariableVec2 (ezStringView sName, const ezVec2 &value) |
| Shorthand for "BeginVariable(szName); WriteVec2(value); EndVariable(); ". | |
| void | AddVariableVec3 (ezStringView sName, const ezVec3 &value) |
| Shorthand for "BeginVariable(szName); WriteVec3(value); EndVariable(); ". | |
| void | AddVariableVec4 (ezStringView sName, const ezVec4 &value) |
| Shorthand for "BeginVariable(szName); WriteVec4(value); EndVariable(); ". | |
| void | AddVariableVec2I32 (ezStringView sName, const ezVec2I32 &value) |
| Shorthand for "BeginVariable(szName); WriteVec2I32(value); EndVariable(); ". | |
| void | AddVariableVec3I32 (ezStringView sName, const ezVec3I32 &value) |
| Shorthand for "BeginVariable(szName); WriteVec3I32(value); EndVariable(); ". | |
| void | AddVariableVec4I32 (ezStringView sName, const ezVec4I32 &value) |
| Shorthand for "BeginVariable(szName); WriteVec4I32(value); EndVariable(); ". | |
| void | AddVariableQuat (ezStringView sName, const ezQuat &value) |
| Shorthand for "BeginVariable(szName); WriteQuat(value); EndVariable(); ". | |
| void | AddVariableMat3 (ezStringView sName, const ezMat3 &value) |
| Shorthand for "BeginVariable(szName); WriteMat3(value); EndVariable(); ". | |
| void | AddVariableMat4 (ezStringView sName, const ezMat4 &value) |
| Shorthand for "BeginVariable(szName); WriteMat4(value); EndVariable(); ". | |
| void | AddVariableDataBuffer (ezStringView sName, const ezDataBuffer &value) |
| Shorthand for "BeginVariable(szName); WriteDataBuffer(value); EndVariable(); ". | |
| void | AddVariableVariant (ezStringView sName, const ezVariant &value) |
| Shorthand for "BeginVariable(szName); WriteVariant(value); EndVariable(); ". | |
| bool | HadWriteError () const |
| Indicates if an error was encountered while writing. | |
| void | Abandon () |
| Gives up on the output, so that the writer may be destroyed with containers still open. | |
Additional Inherited Members | |
Public Types inherited from ezJSONWriter | |
| enum class | WhitespaceMode { All , LessIndentation , NoIndentation , NewlinesOnly , None } |
| Modes to configure how much whitespace the JSON writer will output. More... | |
| enum class | ArrayMode { InOneLine , OneLinePerItem } |
| Modes to configure how arrays are written. More... | |
Protected Types inherited from ezStandardJSONWriter | |
| enum | State { Invalid , Empty , Variable , Object , NamedObject , Array , NamedArray } |
Protected Member Functions inherited from ezStandardJSONWriter | |
| void | End () |
| void | WriteFloatComponents (const float *pValues, ezUInt32 uiCount, ezStringView sComponentNames) |
| Writes an object with one float member per component, e.g. {"x":1,"y":2}. | |
| void | WriteMatrix (const float *pValues, ezUInt32 uiRowsAndColumns) |
| Writes a square matrix row by row, as an array of arrays. | |
| void | OutputString (ezStringView s) |
| void | OutputEscapedString (ezStringView s) |
| void | OutputIndentation () |
Protected Member Functions inherited from ezJSONWriter | |
| void | SetWriteErrorState () |
| called internally when there was an error during writing | |
Protected Attributes inherited from ezStandardJSONWriter | |
| ezInt32 | m_iIndentation |
| ezStreamWriter * | m_pOutput |
| ezHybridArray< JSONState, 16 > | m_StateStack |
Protected Attributes inherited from ezJSONWriter | |
| WhitespaceMode | m_WhitespaceMode = WhitespaceMode::All |
| ArrayMode | m_ArrayMode = ArrayMode::InOneLine |
Writes the JSON that tool results and protocol responses are made of.
| ezStringView ezMcpJsonWriter::GetResult | ( | ) |
The JSON written so far.
Only meaningful once every Begin* has been matched by its End*, because the closing brace is written by the latter.
|
overridevirtual |
Adds the variant types that the base class asserts on: pointers and embedded objects, which turn up when reflection data is written generically. The base class' assert is fine for a caller that knows what it writes, but a tool reading arbitrary reflection data cannot know, and an assert in a tool call takes the whole editor down.
Reimplemented from ezJSONWriter.