measureMsgPack()
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(TSource src);
Arguments
src
: the value to serialize. It can be aJsonDocument
,JsonArray
,JsonArrayConst
,JsonObject
,JsonObjectConst
,JsonVariant
, orJsonVariantConst
.
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);