Skip to content

Repository files navigation

MsgPack

MessagePack implementation for Arduino (compatible with other C++ apps)

Feature

  • one-line [serialize / deserialize] for almost all standard type of C++ same as msgpack-c
  • support custom class [serialization / deserialization]
  • support working with ArduinoJSON
  • one-line [save / load] between custom serializable MsgPack class and JSON file
  • one-line [save / load] custom serializable MsgPack class [to / from] EEPROM

Typical Usage

This library is only for serialize / deserialize. To send / receive serialized data with Stream class, please use MsgPacketizer.

#include<MsgPack.h>// input to msgpackint i = 123;
float f = 1.23;
MsgPack::str_t s = "str"; // std::string or String
MsgPack::arr_t<int> v {1, 2, 3}; // std::vector or arx::stdx::vector
MsgPack::map_t<String, float> m {{"one", 1.1}, {"two", 2.2}, {"three", 3.3}}; // std::map or arx::stdx::map// output from msgpackint ri;
float rf;
MsgPack::str_t rs;
MsgPack::arr_t<int> rv;
MsgPack::map_t<String, float> rm;
voidsetup() {
delay(2000);
Serial.begin(115200);
Serial.println("msgpack test start");
// serialize to msgpack
MsgPack::Packer packer;
packer.serialize(i, f, s, v, m);
// deserialize from msgpack
MsgPack::Unpacker unpacker;
unpacker.feed(packer.data(), packer.size());
unpacker.deserialize(ri, rf, rs, rv, rm);
if (i != ri) Serial.println("failed: int");
if (f != rf) Serial.println("failed: float");
if (s != rs) Serial.println("failed: string");
if (v != rv) Serial.println("failed: vector<int>");
if (m != rm) Serial.println("failed: map<string, int>");
Serial.println("msgpack test success");
}
voidloop() {}

Encode / Decode to Collections without Container

In msgpack, there are two collection types: Array and Map. C++ containers will be converted to one of them but you can do that from individual parameters. To pack / unpack values as such collections in a simple way, please use these functions.

packer.to_array(i, f, s); // becoms array format [i, f, s];
unpacker.from_array(ii, ff, ss); // unpack from array format to ii, ff, ss
packer.to_map("i", i, "f", f); // becoms {"i":i, "f":f}
unpacker.from_map(ki, ii, kf, ff); // unpack from map to ii, ff, ss

The same conversion can be achieved using serialize and deserialize.

packer.serialize(MsgPack::arr_size_t(3), i, f, s); // [i, f, s]
unpacker.deserialize(MsgPack::arr_size_t(3), ii, ff, ss);
packer.serialize(MsgPack::map_size_t(2), "i", i, "f", f); // {"i":i, "f":f}
unpacker.deserialize(MsgPack::map_size_t(2), ki, ii, kf, ff);

Here, MsgPack::arr_size_t and MsgPack::map_size_t are used to identify the size of Array and Map format in serialize or deserialize. This way is expandable to pack and unpack complex data structure because it can be nested.

// {"i":i, "arr":[ii, iii]}
packer.serialize(MsgPack::map_size_t(2), "i", i, "arr", MsgPack::arr_size_t(2), ii, iii);
unpacker.deserialize(MsgPack::map_size_t(2), ki, i, karr, MsgPack::arr_size_t(2), ii, iii);

Custom Class Adaptation

To serialize / deserialize custom type you defined, please use MSGPACK_DEFINE() macro inside of your class. This macro enables you to convert your custom class to Array format.

structCustomClass {
int i;
float f;
MsgPack::str_t s;
MSGPACK_DEFINE(i, f, s); // -> [i, f, s]
};

After that, you can serialize your class completely same as other types.

int i;
float f;
MsgPack::str_t s;
CustomClass c;
MsgPack::Packer packer;
packer.serialize(i, f, s, c);
// -> packer.serialize(i, f, s, arr_size_t(3), c.i, c.f, c.s)int ii;
float ff;
MsgPack::str_t ss;
CustomClass cc;
MsgPack::Unpacker unpacker;
unpacker.feed(packer.data(), packer.size());
unpacker.deserialize(ii, ff, ss, cc);

You can also wrap your custom class to Map format by using MSGPACK_DEFINE_MAP macro. Please note that you need "key" string for Map format.

structCustomClass {
MsgPack::str_t key_i {"i"}; int i;
MsgPack::str_t key_f {"f"}; float f;
MSGPACK_DEFINE_MAP(key_i, i, key_f, f); // -> {"i":i, "f":f}
};
CustomClass c;
MsgPack::Packer packer;
packer.serialize(c);
// -> packer.serialize(map_size_t(2), c.key_i, c.i, c.key_f, c.f)
CustomClass cc;
MsgPack::Unpacker unpacker;
unpacker.feed(packer.data(), packer.size());
unpacker.deserialize(cc);

Custom Class with Inheritance

Also you can use MSGPACK_BASE() macro to pack values of base class.

structBase {
int i;
float f;
MSGPACK_DEFINE(i, f);
};
structDerived : publicBase {
MsgPack::str_t s;
MSGPACK_DEFINE(s, MSGPACK_BASE(Base));
// -> packer.serialize(arr_size_t(2), s, arr_size_t(2), Base::i, Base::f)
};

If you wamt to use Map format in derived class, add "key" for your MSGPACK_BASE.

structDerived : publicBase {
MsgPack::str_t key_s; MsgPack::str_t s;
MsgPack::str_t key_b; // key for base classMSGPACK_DEFINE_MAP(key_s, s, key_b, MSGPACK_BASE(Base));
// -> packer.serialize(map_size_t(2), key_s, s, key_b, arr_size_t(2), Base::i, Base::f)
};

Nested Custom Class

You can nest custom classes to express complex data structure.

// serialize and deserialize nested structure// {"i":i, "f":f, "a":["str", {"first":1, "second":"two"}]}// {"first":1, "second":"two"}structMyMap {
MsgPack::str_t key_first; int i;
MsgPack::str_t key_second; MsgPack::str_t s;
MSGPACK_DEFINE_MAP(key_first, i, key_second, s);
};
// ["str", {"first":1, "second":"two"}]structMyArr {
MsgPack::str_t s;
MyMap m;
MSGPACK_DEFINE(s, m):
};
// {"i":i, "f":f, "a":["str", {"first":1, "second":"two"}]}structMyNestedClass {
MsgPack::str_t key_i; int i;
MsgPack::str_t key_f; int f;
MsgPack::str_t key_a;
MyArr arr;
MSGPACK_DEFINE_MAP(key_i, i, key_f, f, key_a, arr);
};

And you can serialize / deserialize as same as other types.

MyNestedClass c;
MsgPack::Packer packer;
packer.serialize(c);
MyNestedClass cc;
MsgPack::Unpacker unpacker;
unpacker.feed(packer.data(), packer.size());
unpacker.deserialize(cc);

JSON and Other language's msgpack compatibility

In other languages like JavaScript, Python and etc. has also library for msgpack. But some libraries can NOT convert msgpack in "plain" style. They always wrap them into collections like Array or Map by default. For example, you can't convert "plain" format in other languages.

packer.serialize(i, f, s); // "plain" format is NOT unpackable
packer.serialize(arr_size_t(3), i, f, s); // unpackable if you wrap that into Array

It is because the msgpack is used as based on JSON (I think). So you need to use Array format for JSON array, and Map for Json Object. To achieve that, there are several ways.

  • use to_array or to_map to convert to simple structure
  • use serialize() or deserialize() with arr_size_t / map_size_t for complex structure
  • use custom class as JSON array / object which is wrapped into Array / Map
  • use custom class nest recursively for more complex structure
  • use ArduinoJson for more flexible handling of JSON

Use MsgPack with ArduinoJson

  • you can [serialize / deserialize] StaticJsonDocument<N> and DynamicJsonDocument directly
#include<ArduinoJson.h>// include before MsgPack.h
#include<MsgPack.h>voidsetup() {
StaticJsonDocument<200> doc_in;
MsgPack::Packer packer;
packer.serialize(doc_in); // serialize directly
StaticJsonDocument<200> doc;
MsgPack::Unpacker unpacker;
unpacker.feed(packer.data(), packer.size());
unpacker.deserialize(doc); // deserialize directly
}

Utilities

Save/Load to/from JSON file directly from/to MsgPack

You can directly save/load to/from JSON file with this library. SD, SdFat, SD_MMC, SPIFFS, etc. are available for the target file system. Please see save_load_as_json_file example for more details.

#include<SD.h>
#include<MsgPack.h>structMyConfig {
Meta meta;
Data data;
MSGPACK_DEFINE(meta, data);
};
MyConfig config;
voidsetup() {
SD.begin();
// load json data from /config.txt to config struct directly
MsgPack::file::load_from_json_static<256>(SD, "/config.txt", config);
// change your configuration...// save config data from config struct to /config.txt as json directly
MsgPack::file::save_as_json_static<256>(SD, "/config.txt", config);
}

Save/Load to/from EEPROM with MsgPack

In Arduino, you can use the MsgPack utility to save/load to/from EEPROM. Following code shows how to use them. Please see save_load_eeprom example for more details.

structMyConfig {
Meta meta;
Data data;
MSGPACK_DEFINE(meta, data);
};
MyConfig config;
voidsetup() {
EEPROM.begin();
// load current configMsgPack::eeprom::load(config);
// change your configuration...// saveMsgPack::eeprom::save(config);
EEPROM.end();
}

Supported Type Adaptors

These are the lists of types which can be serialize and deserialize. You can also pack() or unpack() variable one by one.

NIL

  • MsgPack::object::nil_t

Bool

  • bool

Integer

  • char (signed/unsigned)
  • ints (signed/unsigned)

Float

  • float
  • double

Str

  • char*
  • char[]
  • std::string or String(Arduino) (MsgPack::str_t)

Bin

  • unsigned char* (need to serialize(ptr, size) or pack(ptr, size))
  • unsigned char[] (need to serialize(ptr, size) or pack(ptr, size))
  • std::vector<char> (MsgPack::bin_t<char>)
  • std::vector<unsigned char> (MsgPack::bin_t<unsigned char>)
  • std::array<char>
  • std::array<unsigned char>

Array

  • T[] (need to serialize(ptr, size) or pack(ptr, size))
  • std::vector (MsgPack::arr_t<T>)
  • std::array (MsgPack::fix_arr_t<T, N>)
  • std::deque
  • std::pair
  • std::tuple
  • std::list
  • std::forward_list
  • std::set
  • std::multiset
  • std::unordered_set
  • std::unordered_multiset

Map

  • std::map (MsgPack::map_t<T>)
  • std::multimap
  • std::unordered_map
  • std::unordered_multimap

Ext

  • MsgPack::object::ext

TimeStamp

  • MsgPack::object::timespec

N/A

  • std::queue
  • std::priority_queue
  • std::bitset
  • std::stack

Note

  • unordered_xxx cannot be used in all Arduino
  • C-style array and pointers are supported only packing.
  • for NO-STL Arduino, following types can be used
    • all types of NIL, Bool, Integer, Float, Str, Bin
    • for Array, only T[], MsgPack::arr_t<T> (arx::stdx::vector<T>), and MsgPack::fix_arr_t<T, N> (arx::stdx::array<T, N>) can be used
    • for Map, only MsgPack::map_t<T, U> (arx::stdx::map<T, U>) can be used
    • for the detail of arx::stdx::xxx, see ArxContainer

Additional Types for MsgPack

There are some additional types are defined to express msgpack formats easily.

Type Aliases for Str / Bin / Array / Map

These types have type aliases like this:

  • MsgPack::str_t = String (Arduino only)
  • MsgPack::bin_t<T> = std::vector<T>
  • MsgPack::arr_t<T> = std::vector<T>
  • MsgPack::fix_arr_t<T, N> = std::array<T, N>
  • MsgPack::map_t<T, U> = std::map<T, U>

For general C++ apps (not Arduino), str_t is defined as:

  • MsgPack::str_t = std::string

MsgPack::obeject::nil_t

MsgPack::object::nil_t is used to pack and unpack Nil type. This object is just a dummy and do nothing.

MsgPack::obeject::ext

MsgPack::object::ext holds binary data of Ext type.

// create ext type with args: int8_t, const uint8_t*, uint32_t
MsgPack::object::ext e(type, bin_ptr, size);
MsgPack::Packer packer;
packer.serialize(e); // serialize ext type
MsgPack::object::ext r;
msgPack::Unpacker unpacker;
unpacker.feed(packer.data(), packer.size());
unpacker.deserialize(r); // deserialize ext type

MsgPack::obeject::timespec

MsgPack::object::timespec is used to pack and unpack Timestamp type.

MsgPack::object::timespec t = {
.tv_sec = 123456789, /* int64_t */
.tv_usec = 123456789/* uint32_t */
};
MsgPack::Packer packer;
packer.serialize(t); // serialize timestamp type
MsgPack::object::timespec r;
msgPack::Unpacker unpacker;
unpacker.feed(packer.data(), packer.size());
unpacker.deserialize(r); // deserialize timestamp type

Other Options

Enable Error Info

Error information report is disabled by default. You can enable it by defining this macro.

#defineMSGPACK_DEBUGLOG_ENABLE

Also you can change debug info stream by calling this macro (default: Serial).

DEBUG_LOG_ATTACH_STREAM(Serial1);

See DebugLog for details.

Packet Data Storage Class Inside

STL is used to handle packet data by default, but for following boards/architectures, ArxContainer is used to store the packet data because STL can not be used for such boards. The storage size of such boards for max packet binary size and number of msgpack objects are limited.

  • AVR
  • megaAVR
  • SAMD

Memory Management (for NO-STL Boards)

As mentioned above, for such boards like Arduino Uno, the storage sizes are limited. And of course you can manage them by defining following macros. But these default values are optimized for such boards, please be careful not to excess your boards storage/memory.

// msgpack serialized binary size
#defineMSGPACK_MAX_PACKET_BYTE_SIZE128// max size of MsgPack::arr_t
#defineMSGPACK_MAX_ARRAY_SIZE8// max size of MsgPack::map_t
#defineMSGPACK_MAX_MAP_SIZE8// msgpack objects size in one packet
#defineMSGPACK_MAX_OBJECT_SIZE24

These macros have no effect for STL enabled boards.

In addtion for such boards, type aliases for following types are different from others.

  • MsgPack::str_t = String
  • MsgPack::bin_t<T> = arx::stdx::vector<T, N = MSGPACK_MAX_PACKET_BYTE_SIZE>
  • MsgPack::arr_t<T> = arx::stdx::vector<T, N = MSGPACK_MAX_ARRAY_SIZE>
  • MsgPack::map_t<T, U> = arx::stdx::map<T, U, N = MSGPACK_MAX_MAP_SIZE>

Please see "Memory Management" section and ArxContainer for detail.

STL library for Arduino Support

For such boards, there are several STL libraries, like ArduinoSTL, StandardCPlusPlus, and so on. But such libraries are mainly based on uClibc++ and it has many lack of function. I considered to support them but I won't support them unless uClibc++ becomes much better compatibility to standard C++ library. I reccomend to use low cost but much better performance chip like ESP series.

Dependent Libraries

Embedded Libraries

Used Inside of

APIs

MsgPack::Packer

// reserve internal buffervoidreserve_buffer(constsize_t size);
// variable sized serializer for any typetemplate <typename First, typename ...Rest>
voidserialize(const First& first, Rest&&... rest);
template <typename T>
voidserialize(constarr_size_t& arr_size, Args&&... args);
template <typename ...Args>
voidserialize(constmap_size_t& map_size, Args&&... args);
template <size_t N>
voidserialize(const StaticJsonDocument<N>& doc, constsize_t num_max_string_type = 32);
voidserialize(const DynamicJsonDocument& doc, constsize_t num_max_string_type = 32);
voidserialize_arduinojson(const JsonDocument& doc, constsize_t num_max_string_type = 32);
// variable sized serializer to array or map for any typetemplate <typename ...Args>
voidto_array(Args&&... args);
template <typename ...Args>
voidto_map(Args&&... args);
// single arg packer for any typetemplate <typename T>
void pack<T>(const T& t);
template <typename T>
void pack<T>(const T* ptr, constsize_t size); // only for pointer types// accesor and utility for serialized binary dataconstbin_t<uint8_t>& packet() const;
constuint8_t* data() const;
size_tsize() const;
size_tindices() const;
voidclear();
// abstract serializer for msgpack formats// serialize() and pack() are wrapper for these methodsvoidpackInteger(const T& value); // accept both uint and intvoidpackFloat(const T& value);
voidpackString(const T& str);
voidpackString(const T& str, constsize_t len);
voidpackBinary(constuint8_t* bin, constsize_t size);
voidpackArraySize(constsize_t size);
voidpackMapSize(constsize_t size);
voidpackFixExt(constint8_t type, const T value);
voidpackFixExt(constint8_t type, constuint64_t value_h, constuint64_t value_l);
voidpackFixExt(constint8_t type, constuint8_t* ptr, constuint8_t size);
voidpackFixExt(constint8_t type, constuint16_t* ptr, constuint8_t size);
voidpackFixExt(constint8_t type, constuint32_t* ptr, constuint8_t size);
voidpackFixExt(constint8_t type, constuint64_t* ptr, constuint8_t size);
voidpackExt(constint8_t type, const T* ptr, const U size);
voidpackExt(const object::ext& e);
voidpackTimestamp(const object::timespec& time);
// serializer for detailed msgpack format// serialize() and pack() are wrapper for these methodsvoidpackNil();
voidpackNil(const object::nil_t& n);
voidpackBool(constbool b);
voidpackUInt7(constuint8_t value);
voidpackUInt8(constuint8_t value);
voidpackUInt16(constuint16_t value);
voidpackUInt32(constuint32_t value);
voidpackUInt64(constuint64_t value);
voidpackInt5(constint8_t value);
voidpackInt8(constint8_t value);
voidpackInt16(constint16_t value);
voidpackInt32(constint32_t value);
voidpackInt64(constint64_t value);
voidpackFloat32(constfloat value);
voidpackFloat64(constdouble value);
voidpackString5(conststr_t& str);
voidpackString5(conststr_t& str, constsize_t len);
voidpackString5(constchar* value);
voidpackString5(constchar* value, constsize_t len);
voidpackString8(conststr_t& str);
voidpackString8(conststr_t& str, constsize_t len);
voidpackString8(constchar* value);
voidpackString8(constchar* value, constsize_t len);
voidpackString16(conststr_t& str);
voidpackString16(conststr_t& str, constsize_t len);
voidpackString16(constchar* value);
voidpackString16(constchar* value, constsize_t len);
voidpackString32(conststr_t& str);
voidpackString32(conststr_t& str, constsize_t len);
voidpackString32(constchar* value);
voidpackString32(constchar* value, constsize_t len);
voidpackString5(const __FlashStringHelper* str);
voidpackString5(const __FlashStringHelper* str, constsize_t len);
voidpackString8(const __FlashStringHelper* str);
voidpackString8(const __FlashStringHelper* str, constsize_t len);
voidpackString16(const __FlashStringHelper* str);
voidpackString16(const __FlashStringHelper* str, constsize_t len);
voidpackString32(const __FlashStringHelper* str);
voidpackString32(const __FlashStringHelper* str, constsize_t len);
voidpackBinary8(constuint8_t* value, constuint8_t size);
voidpackBinary16(constuint8_t* value, constuint16_t size);
voidpackBinary32(constuint8_t* value, constuint32_t size);
voidpackArraySize4(constuint8_t value);
voidpackArraySize16(constuint16_t value);
voidpackArraySize32(constuint32_t value);
voidpackMapSize4(constuint8_t value);
voidpackMapSize16(constuint16_t value);
voidpackMapSize32(constuint32_t value);
voidpackFixExt1(constint8_t type, constuint8_t value);
voidpackFixExt2(constint8_t type, constuint16_t value);
voidpackFixExt2(constint8_t type, constuint8_t* ptr);
voidpackFixExt2(constint8_t type, constuint16_t* ptr);
voidpackFixExt4(constint8_t type, constuint32_t value);
voidpackFixExt4(constint8_t type, constuint8_t* ptr);
voidpackFixExt4(constint8_t type, constuint32_t* ptr);
voidpackFixExt8(constint8_t type, constuint64_t value);
voidpackFixExt8(constint8_t type, constuint8_t* ptr);
voidpackFixExt8(constint8_t type, constuint64_t* ptr);
voidpackFixExt16(constint8_t type, constuint64_t value_h, constuint64_t value_l);
voidpackFixExt16(constint8_t type, constuint8_t* ptr);
voidpackFixExt16(constint8_t type, constuint64_t* ptr);
voidpackExtSize8(constint8_t type, constuint8_t size);
voidpackExtSize16(constint8_t type, constuint16_t size);
voidpackExtSize32(constint8_t type, constuint32_t size);
voidpackTimestamp32(constuint32_t unix_time_sec);
voidpackTimestamp64(constuint64_t unix_time);
voidpackTimestamp64(constuint64_t unix_time_sec, constuint32_t unix_time_nsec);
voidpackTimestamp96(constint64_t unix_time_sec, constuint32_t unix_time_nsec);

MsgPack::Unpacker

// reserve internal buffer for indicesvoidreserve_indices(constsize_t size);
// feed data to deserializeboolfeed(constuint8_t* data, size_t size);
// variable sized deserializertemplate <typename First, typename ...Rest>
booldeserialize(First& first, Rest&&... rest);
template <size_t N>
booldeserialize(StaticJsonDocument<N>& doc);
booldeserialize(DynamicJsonDocument& doc);
// varibale sized desrializer for array and maptemplate <typename ...Args>
boolfrom_array(Args&&... args);
template <typename ...Args>
boolfrom_map(Args&&... args);
// single arg deserializertemplate <typename T>
boolunpack(T& value);
// check if next arg can be deserialized to valuetemplate <typename T>
boolunpackable(const T& value) const;
// accesor and utility for deserialized msgpack databooldecode_ready() const;
booldecoded() const;
size_tsize() const;
voidindex(constsize_t i);
size_tindex() const;
voidclear();
// abstract deserializer for msgpack formats// deserialize() and unpack() are wrapper for these methods
T unpackUInt();
T unpackInt();
T unpackFloat();
str_tunpackString();
bin_t<T> unpackBinary();
bin_t<T> unpackBinary();
size_tunpackArraySize();
size_tunpackMapSize();
object::ext unpackExt();
object::timespec unpackTimestamp();
// deserializer for detailed msgpack format// these methods check deserialize index overflow and type mismatch// deserialize() and unpack() are wrapper for these methodsboolunpackNil();
boolunpackBool();
uint8_tunpackUInt7();
uint8_tunpackUInt8();
uint16_tunpackUInt16();
uint32_tunpackUInt32();
uint64_tunpackUInt64();
int8_tunpackInt5();
int8_tunpackInt8();
int16_tunpackInt16();
int32_tunpackInt32();
int64_tunpackInt64();
floatunpackFloat32();
doubleunpackFloat64();
str_tunpackString5();
str_tunpackString8();
str_tunpackString16();
str_tunpackString32();
bin_t<T> unpackBinary8();
bin_t<T> unpackBinary16();
bin_t<T> unpackBinary32();
std::array<T, N> unpackBinary8();
std::array<T, N> unpackBinary16();
std::array<T, N> unpackBinary32();
size_tunpackArraySize4();
size_tunpackArraySize16();
size_tunpackArraySize32();
size_tunpackMapSize4();
size_tunpackMapSize16();
size_tunpackMapSize32();
object::ext unpackFixExt1();
object::ext unpackFixExt2();
object::ext unpackFixExt4();
object::ext unpackFixExt8();
object::ext unpackFixExt16();
object::ext unpackExt8();
object::ext unpackExt16();
object::ext unpackExt32();
object::timespec unpackTimestamp32();
object::timespec unpackTimestamp64();
object::timespec unpackTimestamp96();
// deserializer for detailed msgpack format// these methods does NOT check index overflow and type mismatchboolunpackNilUnchecked();
boolunpackBoolUnchecked();
uint8_tunpackUIntUnchecked7();
uint8_tunpackUIntUnchecked8();
uint16_tunpackUIntUnchecked16();
uint32_tunpackUIntUnchecked32();
uint64_tunpackUIntUnchecked64();
int8_tunpackIntUnchecked5();
int8_tunpackIntUnchecked8();
int16_tunpackIntUnchecked16();
int32_tunpackIntUnchecked32();
int64_tunpackIntUnchecked64();
floatunpackFloatUnchecked32();
doubleunpackFloatUnchecked64();
str_tunpackStringUnchecked5();
str_tunpackStringUnchecked8();
str_tunpackStringUnchecked16();
str_tunpackStringUnchecked32();
bin_t<T> unpackBinaryUnchecked8();
bin_t<T> unpackBinaryUnchecked16();
bin_t<T> unpackBinaryUnchecked32();
std::array<T, N> unpackBinaryUnchecked8();
std::array<T, N> unpackBinaryUnchecked16();
std::array<T, N> unpackBinaryUnchecked32();
size_tunpackArraySizeUnchecked4();
size_tunpackArraySizeUnchecked16();
size_tunpackArraySizeUnchecked32();
size_tunpackMapSizeUnchecked4();
size_tunpackMapSizeUnchecked16();
size_tunpackMapSizeUnchecked32();
object::ext unpackFixExtUnchecked1();
object::ext unpackFixExtUnchecked2();
object::ext unpackFixExtUnchecked4();
object::ext unpackFixExtUnchecked8();
object::ext unpackFixExtUnchecked16();
object::ext unpackExtUnchecked8();
object::ext unpackExtUnchecked16();
object::ext unpackExtUnchecked32();
object::timespec unpackTimestampUnchecked32();
object::timespec unpackTimestampUnchecked64();
object::timespec unpackTimestampUnchecked96();
// checks types of next msgpack objectboolisNil() const;
boolisBool() const;
boolisUInt7() const;
boolisUInt8() const;
boolisUInt16() const;
boolisUInt32() const;
boolisUInt64() const;
boolisUInt() const;
boolisInt5() const;
boolisInt8() const;
boolisInt16() const;
boolisInt32() const;
boolisInt64() const;
boolisInt() const;
boolisFloat32() const;
boolisFloat64() const;
boolisFloat() const;
boolisStr5() const;
boolisStr8() const;
boolisStr16() const;
boolisStr32() const;
boolisStr() const;
boolisBin8() const;
boolisBin16() const;
boolisBin32() const;
boolisBin() const;
boolisArray4() const;
boolisArray16() const;
boolisArray32() const;
boolisArray() const;
boolisMap4() const;
boolisMap16() const;
boolisMap32() const;
boolisMap() const;
boolisFixExt1() const;
boolisFixExt2() const;
boolisFixExt4() const;
boolisFixExt8() const;
boolisFixExt16() const;
boolisFixExt() const;
boolisExt8() const;
boolisExt16() const;
boolisExt32() const;
boolisExt() const;
boolisTimestamp32() const;
boolisTimestamp64() const;
boolisTimestamp96() const;
boolisTimestamp() const;
MsgPack::Type getType() const

MsgPack Utilities

template <typename T>
inlinesize_testimate_size(const T& msg);
namespacefile {
template <typename FsType, typename T>
inlineboolsave_as_json(FsType& fs, const String& path, const T& value, JsonDocument& doc);
template <size_t N, typename FsType, typename T>
inlineboolsave_as_json_static(FsType& fs, const String& path, const T& value);
template <typename FsType, typename T>
inlineboolsave_as_json_dynamic(FsType& fs, const String& path, const T& value, constsize_t json_size = 512);
template <typename FsType, typename T>
inlineboolload_from_json(FsType& fs, const String& path, T& value, JsonDocument& doc, constsize_t num_max_string_type = 32);
template <size_t N, typename FsType, typename T>
inlineboolload_from_json_static(FsType& fs, const String& path, T& value);
template <typename FsType, typename T>
inlineboolload_from_json_dynamic(FsType& fs, const String& path, T& value, constsize_t json_size = 512);
}
namespaceeeprom {
template <typename T>
inlineboolsave(const T& value, constsize_t index_offset = 0);
template <typename T>
inlineboolload(T& value, constsize_t index_offset = 0);
template <typename T>
inlinevoidclear(const T& value, constsize_t index_offset = 0);
inlinevoidclear_size(constsize_t size, constsize_t index_offset = 0);
}

MsgPack::Type

enumclassType : uint8_t {
NA = 0xC1, // never usedNIL = 0xC0,
BOOL = 0xC2,
UINT7 = 0x00, // same as POSITIVE_FIXINTUINT8 = 0xCC,
UINT16 = 0xCD,
UINT32 = 0xCE,
UINT64 = 0xCF,
INT5 = 0xE0, // same as NEGATIVE_FIXINTINT8 = 0xD0,
INT16 = 0xD1,
INT32 = 0xD2,
INT64 = 0xD3,
FLOAT32 = 0xCA,
FLOAT64 = 0xCB,
STR5 = 0xA0, // same as FIXSTRSTR8 = 0xD9,
STR16 = 0xDA,
STR32 = 0xDB,
BIN8 = 0xC4,
BIN16 = 0xC5,
BIN32 = 0xC6,
ARRAY4 = 0x90, // same as FIXARRAYARRAY16 = 0xDC,
ARRAY32 = 0xDD,
MAP4 = 0x80, // same as FIXMAPMAP16 = 0xDE,
MAP32 = 0xDF,
FIXEXT1 = 0xD4,
FIXEXT2 = 0xD5,
FIXEXT4 = 0xD6,
FIXEXT8 = 0xD7,
FIXEXT16 = 0xD8,
EXT8 = 0xC7,
EXT16 = 0xC8,
EXT32 = 0xC9,
TIMESTAMP32 = 0xD6,
TIMESTAMP64 = 0xD7,
TIMESTAMP96 = 0xC7,
POSITIVE_FIXINT = 0x00,
NEGATIVE_FIXINT = 0xE0,
FIXSTR = 0xA0,
FIXARRAY = 0x90,
FIXMAP = 0x80,
};

Reference

License

MIT

About

MessagePack implementation for Arduino (compatible with other C++ apps) / msgpack.org[Arduino]

Resources

Stars

66 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages