Description

measureMsgPack() computes the length of the MessagePack document that serializeMsgPack() produces.

This function is handy to fill the Content-Length header in an HTTP message.

Signature

size_t measureMsgPack(const JsonDocument& doc);

Arguments

doc: the JsonDocument to serialize (in fact, you can also use a JsonArray, a JsonObject, or a JsonVariant).

Return value

The number of bytes that serializeMsgPack() produces.

Example

// Send headers
client.println("Content-Type: application/msgpack");
client.print("Content-Length: ");
client.println(measureMsgPack(doc));

// Terminate headers
client.println();

// Send body
serializeMsgPack(doc, client);

See also

 X online