Description

deserializeMsgPack() parses a MessagePack input and puts the result in a JsonDocument.

This function behaves differently depending on the type of the input:

  • For a read-only input, it duplicates the strings in the input document. This duplication consumes additional space in the JsonDocument.
  • For a writeable input, it stores pointers to the strings in the input buffer. This is the zero-copy mode. In this mode, the JsonDocument can be smaller, but ArduinoJson needs to modify the input buffer to insert null-terminators and replace escaped characters.

Prefer the first mode when the input comes from a Stream; prefer the second when the input 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);

// all overloads also accept an optional parameter of type DeserializationOption::NestingLimit (see below)

Arduino’s String doesn’t allow nulls inside the string; don’t use this class for MessagePack documents.

Arguments

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

input: the MessagePack document to parse:

  • const char* is a string in RAM
  • const __FlashStringHelper* is a Flash string, usually created with F()
  • Stream is Arduino’s I/O stream interface, implemented by:

inputSize: the maximum number of bytes to read from input

This function supports an optional argument of type DeserializationOption::NestingLimit to change the maximum number of nesting that the parser will accept. See deserializeJson() for details.

Return value

deserializeMsgPack() returns a DeserializationError.

Example

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

See also