Description

serializeMsgPack() serializes a JsonDocument to create a MessagePack document.

Signatures

size_t serializeMsgPack(const JsonDocument& doc, char* output, size_t outputSize);
size_t serializeMsgPack(const JsonDocument& doc, char output[size]);
size_t serializeMsgPack(const JsonDocument& doc, Print& output);
size_t serializeMsgPack(const JsonDocument& doc, String& output);
size_t serializeMsgPack(const JsonDocument& doc, std::string& output);

Arguments

  • doc: the JsonDocument to serialize (in fact, you can also use a JsonArray, a JsonObject, or a JsonVariant)
  • output: the destination where the JSON document should be written
  • outputSize: the capacity of the destination buffer

Because output can be any implementation of Print, you can uses instances like Serial, EthernetClient, WifiClient

This function treats String and std::string as streams: it doesn’t replace the content, it appends to the end.

Return value

serializeMsgPack() returns the number of bytes written.

Example

StaticJsonDocument<200> doc;
doc["hello"] = "world";
serializeMsgPack(doc, Serial);

will write the following bytes to the serial output:

81 A5 68 65 6C 6C 6F A5 77 6F 72 6C 64

See also