Description

Serializes the 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 MessagePack 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

Return value

The number of bytes written.

Example

StaticJsonDocument<200> doc;
JsonObject object = doc.to<JsonObject>();
object["hello"] = "world";
object.serializeMsgPack(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