Description

Parses a MessagePack document and populates a JsonDocument with the content of the document

This function behaves differently depending on the input type:

  • For a read-only input, it duplicates the input string, this consume more space in the JsonDocument.
  • For a writeable input, it alter the string to insert null-terminators and replace escaped chars. This is the zero-copy mode

Prefer the first mode when input comes from a Stream; prefer the second when the input document is in a buffer.

Signatures

// writable input => zero-copy
DeserializationError deserializeMsgPack(JsonDocument& doc, char* input);
DeserializationError deserializeMsgPack(JsonDocument& doc, char* input, size_t inputSize);

// read-only input => duplication
DeserializationError deserializeMsgPack(JsonDocument& doc, const char* input);
DeserializationError deserializeMsgPack(JsonDocument& doc, const char* input, size_t inputSize);
DeserializationError deserializeMsgPack(JsonDocument& doc, const __FlashStringHelper* input);
DeserializationError deserializeMsgPack(JsonDocument& doc, const __FlashStringHelper* input, size_t inputSize);
DeserializationError deserializeMsgPack(JsonDocument& doc, const String& input);
DeserializationError deserializeMsgPack(JsonDocument& doc, const std::string& input);
DeserializationError deserializeMsgPack(JsonDocument& doc, Stream& input);
DeserializationError deserializeMsgPack(JsonDocument& doc, std::istream& input);

Arguments

doc: the JsonDocument that will store the memory representation of the MessagePack document.

input: the MessagePack document to parse.

inputSize: the maximum number of bytes to read from input

Return value

Returns a DeserializationError.

Example

char input[] = "\x81\xA5hello\xA5world";
StaticJsonDocument<200> doc;
deserializeMsgPack(doc, input);
JsonObject object = doc.as<JsonObject>();
const char* world = object["hello"];

See also