### Create and Serialize Ext Type Source: https://github.com/hideakitai/msgpack/blob/main/README.md Demonstrates how to create a MsgPack Ext type object and serialize it using MsgPack::Packer. Also shows how to deserialize it back into an object. ```C++ 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 ``` -------------------------------- ### Packing and Unpacking Values as Arrays Source: https://github.com/hideakitai/msgpack/blob/main/README.md Shows how to pack individual values into an array format and unpack them back. Use `MsgPack::arr_size_t` to specify the array size during serialization and deserialization. ```C++ 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 ``` ```C++ packer.serialize(MsgPack::arr_size_t(3), i, f, s); // [i, f, s] unpacker.deserialize(MsgPack::arr_size_t(3), ii, ff, ss); ``` -------------------------------- ### Serialize JSON to MessagePack and Deserialize Source: https://context7.com/hideakitai/msgpack/llms.txt Demonstrates converting Arduino JSON documents to MessagePack format and back. Ensure ArduinoJson.h is included before MsgPack.h. ```cpp #include #include void setup() { Serial.begin(115200); // Create JSON document StaticJsonDocument<200> doc_in; doc_in["sensor"] = "temperature"; doc_in["value"] = 25.5; doc_in["unit"] = "celsius"; // Serialize JSON to MessagePack MsgPack::Packer packer; packer.serialize(doc_in); Serial.print("MessagePack size: "); Serial.println(packer.size()); // Deserialize MessagePack back to JSON StaticJsonDocument<200> doc_out; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); unpacker.deserialize(doc_out); // Print result serializeJsonPretty(doc_out, Serial); } void loop() {} ``` -------------------------------- ### Packing and Unpacking Values as Maps Source: https://github.com/hideakitai/msgpack/blob/main/README.md Demonstrates packing individual values into a map format with string keys and unpacking them. Use `MsgPack::map_size_t` to specify the map size during serialization and deserialization. ```C++ 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 ``` ```C++ 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); ``` -------------------------------- ### Basic Serialization and Deserialization Source: https://github.com/hideakitai/msgpack/blob/main/README.md Demonstrates the typical usage of MsgPack for serializing primitive types and containers to a byte array and deserializing them back. Ensure 'Stream' class is used with MsgPacketizer for data transmission. ```C++ #include // input to msgpack int i = 123; float f = 1.23; MsgPack::str_t s = "str"; // std::string or String MsgPack::arr_t v {1, 2, 3}; // std::vector or arx::stdx::vector MsgPack::map_t m {{"one", 1.1}, {"two", 2.2}, {"three", 3.3}}; // std::map or arx::stdx::map // output from msgpack int ri; float rf; MsgPack::str_t rs; MsgPack::arr_t rv; MsgPack::map_t rm; void setup() { 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"); if (m != rm) Serial.println("failed: map"); Serial.println("msgpack test success"); } void loop() {} ``` -------------------------------- ### Save and Load Data to EEPROM Source: https://github.com/hideakitai/msgpack/blob/main/README.md Use the MsgPack EEPROM utility to persist configuration structures. ```C++ struct MyConfig { Meta meta; Data data; MSGPACK_DEFINE(meta, data); }; MyConfig config; void setup() { EEPROM.begin(); // load current config MsgPack::eeprom::load(config); // change your configuration... // save MsgPack::eeprom::save(config); EEPROM.end(); } ``` -------------------------------- ### Save and Load Data to File Systems Source: https://github.com/hideakitai/msgpack/blob/main/README.md Directly persist configuration structures to JSON files on supported file systems like SD cards. ```C++ #include #include struct MyConfig { Meta meta; Data data; MSGPACK_DEFINE(meta, data); }; MyConfig config; void setup() { 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); } ``` -------------------------------- ### Configure Memory Limits for Non-STL Boards in C++ Source: https://context7.com/hideakitai/msgpack/llms.txt Define preprocessor macros before including MsgPack.h to set memory constraints on boards lacking STL support. Use reserve_buffer and reserve_indices for performance optimization. ```cpp // Configure before including MsgPack.h #define MSGPACK_MAX_PACKET_BYTE_SIZE 256 // Max serialized binary size #define MSGPACK_MAX_ARRAY_SIZE 16 // Max MsgPack::arr_t elements #define MSGPACK_MAX_MAP_SIZE 16 // Max MsgPack::map_t elements #define MSGPACK_MAX_OBJECT_SIZE 32 // Max msgpack objects per packet #include void setup() { Serial.begin(115200); // Reserve buffer for better performance MsgPack::Packer packer; packer.reserve_buffer(128); // Pre-allocate internal buffer // Reserve indices buffer for unpacker MsgPack::Unpacker unpacker; unpacker.reserve_indices(32); // Pre-allocate index storage // Use normally MsgPack::arr_t data {1, 2, 3, 4, 5}; packer.serialize(data); MsgPack::arr_t received; unpacker.feed(packer.data(), packer.size()); unpacker.deserialize(received); } void loop() {} ``` -------------------------------- ### Integrate MsgPack with ArduinoJson Source: https://github.com/hideakitai/msgpack/blob/main/README.md Serialize and deserialize ArduinoJson documents directly using the MsgPack library. ```C++ #include // include before MsgPack.h #include void setup() { 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 } ``` -------------------------------- ### MsgPack Utility Functions Source: https://github.com/hideakitai/msgpack/blob/main/README.md Utilities for estimating size and performing file-based JSON serialization or EEPROM storage operations. ```C++ template inline size_t estimate_size(const T& msg); namespace file { template inline bool save_as_json(FsType& fs, const String& path, const T& value, JsonDocument& doc); template inline bool save_as_json_static(FsType& fs, const String& path, const T& value); template inline bool save_as_json_dynamic(FsType& fs, const String& path, const T& value, const size_t json_size = 512); template inline bool load_from_json(FsType& fs, const String& path, T& value, JsonDocument& doc, const size_t num_max_string_type = 32); template inline bool load_from_json_static(FsType& fs, const String& path, T& value); template inline bool load_from_json_dynamic(FsType& fs, const String& path, T& value, const size_t json_size = 512); } namespace eeprom { template inline bool save(const T& value, const size_t index_offset = 0); template inline bool load(T& value, const size_t index_offset = 0); template inline void clear(const T& value, const size_t index_offset = 0); inline void clear_size(const size_t size, const size_t index_offset = 0); } ``` -------------------------------- ### Serialize Custom Class with MSGPACK_DEFINE_MAP (Map Format) Source: https://context7.com/hideakitai/msgpack/llms.txt Employ MSGPACK_DEFINE_MAP for serializing custom classes into MsgPack's map format, using string keys. List keys and their corresponding values in pairs. ```cpp #include struct Config { MsgPack::str_t key_name; MsgPack::str_t name; MsgPack::str_t key_enabled; bool enabled; MsgPack::str_t key_value; int value; MSGPACK_DEFINE_MAP(key_name, name, key_enabled, enabled, key_value, value); Config() : key_name("name"), key_enabled("enabled"), key_value("value") {} }; void setup() { Serial.begin(115200); // Create config with map format: {"name": "sensor", "enabled": true, "value": 42} Config cfg; cfg.name = "sensor"; cfg.enabled = true; cfg.value = 42; // Serialize MsgPack::Packer packer; packer.serialize(cfg); // Deserialize Config received; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); unpacker.deserialize(received); Serial.println(received.name); // sensor Serial.println(received.enabled); // 1 (true) Serial.println(received.value); // 42 } void loop() {} ``` -------------------------------- ### Save and Load Struct as JSON File Source: https://context7.com/hideakitai/msgpack/llms.txt Saves and loads custom struct data to/from JSON files on a filesystem like SD card. Requires ArduinoJson and filesystem support. ```cpp #include #include #include struct DeviceConfig { MsgPack::str_t name; int interval; MsgPack::arr_t pins; MSGPACK_DEFINE(name, interval, pins); }; void setup() { Serial.begin(115200); SD.begin(); // Create config DeviceConfig config; config.name = "sensor_node"; config.interval = 1000; config.pins = {2, 4, 5, 12}; // Save as JSON file if (MsgPack::file::save_as_json_static<256>(SD, "/config.json", config)) { Serial.println("Config saved as JSON"); } // Load from JSON file DeviceConfig loaded; if (MsgPack::file::load_from_json_static<256>(SD, "/config.json", loaded)) { Serial.print("Name: "); Serial.println(loaded.name); Serial.print("Interval: "); Serial.println(loaded.interval); Serial.print("Pins: "); for (auto pin : loaded.pins) { Serial.print(pin); Serial.print(" "); } Serial.println(); } } void loop() {} ``` -------------------------------- ### Define Custom Classes with Inheritance Source: https://github.com/hideakitai/msgpack/blob/main/README.md Use MSGPACK_BASE to include base class members in serialization. Add keys to MSGPACK_BASE when using Map format. ```C++ struct Base { int i; float f; MSGPACK_DEFINE(i, f); }; struct Derived : public Base { 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) }; ``` ```C++ struct Derived : public Base { MsgPack::str_t key_s; MsgPack::str_t s; MsgPack::str_t key_b; // key for base class MSGPACK_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) }; ``` -------------------------------- ### Handle MsgPack Compatibility Source: https://github.com/hideakitai/msgpack/blob/main/README.md Use explicit array or map sizes to ensure compatibility with non-plain MsgPack implementations. ```C++ 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 ``` -------------------------------- ### Map Collections with to_map and from_map Source: https://context7.com/hideakitai/msgpack/llms.txt Serialize and deserialize key-value pairs as MessagePack Map format using to_map() and from_map(). Ensure arguments are provided in key-value pairs (an even number of arguments). ```cpp #include void setup() { Serial.begin(115200); int i = 123; float f = 4.56; // Serialize as map format: {"int": 123, "float": 4.56} MsgPack::Packer packer; packer.to_map("int", i, "float", f); // Alternative using map_size_t // packer.serialize(MsgPack::map_size_t(2), "int", i, "float", f); // Deserialize from map MsgPack::str_t key_i, key_f; int ri; float rf; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); unpacker.from_map(key_i, ri, key_f, rf); Serial.println(key_i); // int Serial.println(ri); // 123 Serial.println(key_f); // float Serial.println(rf); // 4.56 } void loop() {} ``` -------------------------------- ### Estimate Serialized Size in C++ Source: https://context7.com/hideakitai/msgpack/llms.txt Calculate the required buffer size for a data structure using MsgPack::estimate_size() before performing the actual serialization. ```cpp #include void setup() { Serial.begin(115200); struct MyData { int id; MsgPack::str_t name; MsgPack::arr_t values; MSGPACK_DEFINE(id, name, values); }; MyData data; data.id = 123; data.name = "sensor"; data.values = {1.1, 2.2, 3.3}; // Estimate size without actually packing size_t estimated_size = MsgPack::estimate_size(data); Serial.print("Estimated size: "); Serial.println(estimated_size); // Verify with actual packing MsgPack::Packer packer; packer.serialize(data); Serial.print("Actual size: "); Serial.println(packer.size()); } void loop() {} ``` -------------------------------- ### Save and Load Struct to EEPROM Source: https://context7.com/hideakitai/msgpack/llms.txt Persists custom struct data to EEPROM using MsgPack utilities. Requires EEPROM.h. Ensure EEPROM.begin() and EEPROM.end() are called. ```cpp #include #include struct Settings { int brightness; bool auto_mode; float threshold; MSGPACK_DEFINE(brightness, auto_mode, threshold); }; void setup() { Serial.begin(115200); EEPROM.begin(512); // Required for ESP32/ESP8266 // Save settings to EEPROM Settings settings; settings.brightness = 75; settings.auto_mode = true; settings.threshold = 0.5; if (MsgPack::eeprom::save(settings)) { Serial.println("Settings saved to EEPROM"); } // Load settings from EEPROM Settings loaded; if (MsgPack::eeprom::load(loaded)) { Serial.print("Brightness: "); Serial.println(loaded.brightness); Serial.print("Auto mode: "); Serial.println(loaded.auto_mode); Serial.print("Threshold: "); Serial.println(loaded.threshold); } // Clear EEPROM data // MsgPack::eeprom::clear(settings); EEPROM.end(); } void loop() {} ``` -------------------------------- ### Basic Deserialization with MsgPack::Unpacker Source: https://context7.com/hideakitai/msgpack/llms.txt Use MsgPack::Unpacker to deserialize MessagePack binary data back into C++ values. Feed data using feed() and extract values with deserialize() in the original order. Check the decoded status to confirm success. ```cpp #include void setup() { Serial.begin(115200); // Serialize data int i = 123; float f = 1.23; MsgPack::str_t s = "hello"; MsgPack::Packer packer; packer.serialize(i, f, s); // Deserialize data int ri; float rf; MsgPack::str_t rs; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); if (unpacker.deserialize(ri, rf, rs)) { Serial.print("Int: "); Serial.println(ri); // 123 Serial.print("Float: "); Serial.println(rf); // 1.23 Serial.print("String: "); Serial.println(rs); // hello } // Check decode status if (unpacker.decoded()) { Serial.println("Deserialization successful"); } } void loop() {} ``` -------------------------------- ### Enable MsgPack Debug Logging Source: https://github.com/hideakitai/msgpack/blob/main/README.md Shows how to enable detailed error information reporting in MsgPack by defining the MSGPACK_DEBUGLOG_ENABLE macro. This is useful for debugging. ```C++ #define MSGPACK_DEBUGLOG_ENABLE ``` -------------------------------- ### EEPROM Storage Utilities Source: https://github.com/hideakitai/msgpack/blob/main/README.md Functions for persistent storage of data in EEPROM. ```APIDOC ## EEPROM Operations ### Description Functions to save, load, and clear data stored in EEPROM at specific offsets. ### Methods - save(value, index_offset) -> bool - load(value, index_offset) -> bool - clear(value, index_offset) -> void - clear_size(size, index_offset) -> void ``` -------------------------------- ### Serialize and Deserialize Timestamps in C++ Source: https://context7.com/hideakitai/msgpack/llms.txt Utilize MsgPack::object::timespec for nanosecond precision time data. Ensure the object is populated with seconds and nanoseconds before serialization. ```cpp #include void setup() { Serial.begin(115200); // Create timestamp MsgPack::object::timespec timestamp; timestamp.tv_sec = 1609459200; // Unix timestamp (seconds) timestamp.tv_nsec = 500000000; // Nanoseconds // Serialize timestamp MsgPack::Packer packer; packer.serialize(timestamp); Serial.print("Timestamp size: "); Serial.println(packer.size()); // Deserialize timestamp MsgPack::object::timespec received; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); unpacker.deserialize(received); Serial.print("Seconds: "); Serial.println((long)received.tv_sec); Serial.print("Nanoseconds: "); Serial.println(received.tv_nsec); } void loop() {} ``` -------------------------------- ### Nested Array and Map Serialization/Deserialization Source: https://github.com/hideakitai/msgpack/blob/main/README.md Illustrates how to serialize and deserialize nested data structures, such as a map containing an array. `MsgPack::arr_size_t` and `MsgPack::map_size_t` are used to define the structure. ```C++ // {"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); ``` -------------------------------- ### Modify boards.txt build flags Source: https://github.com/hideakitai/msgpack/blob/main/MsgPack/util/TeensyDirtySTLErrorSolution/README.md Update the build flags in boards.txt to include the -lstdc++ library for STL support. ```text teensy36.build.flags.libs=-larm_cortexM4lf_math -lm teensy35.build.flags.libs=-larm_cortexM4lf_math -lm teensy31.build.flags.libs=-larm_cortexM4l_math -lm ``` ```text teensy36.build.flags.libs=-larm_cortexM4lf_math -lm -lstdc++ teensy35.build.flags.libs=-larm_cortexM4lf_math -lm -lstdc++ teensy31.build.flags.libs=-larm_cortexM4l_math -lm -lstdc++ ``` -------------------------------- ### Serialize and Deserialize Extension Types in C++ Source: https://context7.com/hideakitai/msgpack/llms.txt Use MsgPack::object::ext to handle custom binary data with specific type tags. The type tag is an 8-bit identifier for application-specific data. ```cpp #include void setup() { Serial.begin(115200); // Create extension data uint8_t custom_data[] = {0x01, 0x02, 0x03, 0x04}; int8_t type_tag = 42; // Application-specific type identifier MsgPack::object::ext ext_obj(type_tag, custom_data, sizeof(custom_data)); // Serialize extension MsgPack::Packer packer; packer.serialize(ext_obj); // Deserialize extension MsgPack::object::ext received; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); unpacker.deserialize(received); Serial.print("Type: "); Serial.println(received.type()); Serial.print("Size: "); Serial.println(received.size()); Serial.print("Data: "); for (size_t i = 0; i < received.size(); i++) { Serial.print(received.data()[i], HEX); Serial.print(" "); } Serial.println(); } void loop() {} ``` -------------------------------- ### MsgPack::Packer - Core Serialization Methods Source: https://github.com/hideakitai/msgpack/blob/main/README.md Methods for reserving buffer space and performing general-purpose serialization of various data types. ```APIDOC ## MsgPack::Packer - Core Serialization Methods ### Description Methods for reserving buffer space and performing general-purpose serialization of various data types. ### Methods - `void reserve_buffer(const size_t size)`: Reserves internal buffer space. - `template void serialize(const First& first, Rest&&... rest)`: Variable sized serializer for any type. - `template void serialize(const arr_size_t& arr_size, Args&&... args)`: Serializes an array with a specified size. - `template void serialize(const map_size_t& map_size, Args&&... args)`: Serializes a map with a specified size. - `template void serialize(const StaticJsonDocument& doc, const size_t num_max_string_type = 32)`: Serializes a static JSON document. - `void serialize(const DynamicJsonDocument& doc, const size_t num_max_string_type = 32)`: Serializes a dynamic JSON document. - `void serialize_arduinojson(const JsonDocument& doc, const size_t num_max_string_type = 32)`: Serializes an Arduino JSON document. ``` -------------------------------- ### Attach Debug Log Stream Source: https://github.com/hideakitai/msgpack/blob/main/README.md Demonstrates how to redirect the MsgPack debug log output from the default stream (Serial) to a different stream, such as Serial1, using the DEBUG_LOG_ATTACH_STREAM macro. ```C++ DEBUG_LOG_ATTACH_STREAM(Serial1); ``` -------------------------------- ### Array Collections with to_array and from_array Source: https://context7.com/hideakitai/msgpack/llms.txt Serialize and deserialize values as MessagePack Array format using to_array() and from_array() for compatibility with other MessagePack implementations. This method avoids using C++ containers directly. ```cpp #include void setup() { Serial.begin(115200); int i = 1; float f = 2.2; MsgPack::str_t s = "three"; // Serialize as array format: [1, 2.2, "three"] MsgPack::Packer packer; packer.to_array(i, f, s); // Alternative using arr_size_t // packer.serialize(MsgPack::arr_size_t(3), i, f, s); // Deserialize from array int ri; float rf; MsgPack::str_t rs; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); unpacker.from_array(ri, rf, rs); Serial.println(ri); // 1 Serial.println(rf); // 2.2 Serial.println(rs); // three } void loop() {} ``` -------------------------------- ### Create and Serialize Timestamp Type Source: https://github.com/hideakitai/msgpack/blob/main/README.md Illustrates the creation and serialization of a MsgPack Timestamp type using MsgPack::object::timespec and MsgPack::Packer. It also covers deserialization. ```C++ 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 ``` -------------------------------- ### Basic Serialization with MsgPack::Packer Source: https://context7.com/hideakitai/msgpack/llms.txt Use MsgPack::Packer to serialize C++ values into MessagePack binary format. The serialize() method handles multiple values, and data() and size() provide access to the binary output. The packer can be cleared and reused. ```cpp #include void setup() { Serial.begin(115200); // Create packer and serialize multiple types MsgPack::Packer packer; int i = 123; float f = 1.23; MsgPack::str_t s = "hello"; MsgPack::arr_t v {1, 2, 3}; MsgPack::map_t m {{"one", 1.1}, {"two", 2.2}}; // Serialize all values in one call packer.serialize(i, f, s, v, m); // Access binary data const uint8_t* data = packer.data(); size_t size = packer.size(); Serial.print("Serialized size: "); Serial.println(size); // Clear and reuse packer packer.clear(); } void loop() {} ``` -------------------------------- ### MsgPack::Packer - Detailed Format Serializers Source: https://github.com/hideakitai/msgpack/blob/main/README.md Methods for packing specific MsgPack formats, including nil, booleans, integers, floats, strings, binary, arrays, maps, and extensions. ```APIDOC ## MsgPack::Packer - Detailed Format Serializers ### Description Methods for packing specific MsgPack formats, including nil, booleans, integers, floats, strings, binary, arrays, maps, and extensions. ### Methods - `void packTimestamp(const object::timespec& time)`: Packs a timestamp. - `void packNil()`: Packs a nil value. - `void packNil(const object::nil_t& n)`: Packs a nil value using a nil_t object. - `void packBool(const bool b)`: Packs a boolean value. - `void packUInt7(const uint8_t value)`: Packs an unsigned integer in uint7 format. - `void packUInt8(const uint8_t value)`: Packs an unsigned integer in uint8 format. - `void packUInt16(const uint16_t value)`: Packs an unsigned integer in uint16 format. - `void packUInt32(const uint32_t value)`: Packs an unsigned integer in uint32 format. - `void packUInt64(const uint64_t value)`: Packs an unsigned integer in uint64 format. - `void packInt5(const int8_t value)`: Packs a signed integer in int5 format. - `void packInt8(const int8_t value)`: Packs a signed integer in int8 format. - `void packInt16(const int16_t value)`: Packs a signed integer in int16 format. - `void packInt32(const int32_t value)`: Packs a signed integer in int32 format. - `void packInt64(const int64_t value)`: Packs a signed integer in int64 format. - `void packFloat32(const float value)`: Packs a 32-bit float. - `void packFloat64(const double value)`: Packs a 64-bit float (double). - `void packString5(const str_t& str)`: Packs a string in str5 format. - `void packString5(const str_t& str, const size_t len)`: Packs a string with a specified length in str5 format. - `void packString5(const char* value)`: Packs a C-style string in str5 format. - `void packString5(const char* value, const size_t len)`: Packs a C-style string with a specified length in str5 format. - `void packString8(const str_t& str)`: Packs a string in str8 format. - `void packString8(const str_t& str, const size_t len)`: Packs a string with a specified length in str8 format. - `void packString8(const char* value)`: Packs a C-style string in str8 format. - `void packString8(const char* value, const size_t len)`: Packs a C-style string with a specified length in str8 format. - `void packString16(const str_t& str)`: Packs a string in str16 format. - `void packString16(const str_t& str, const size_t len)`: Packs a string with a specified length in str16 format. - `void packString16(const char* value)`: Packs a C-style string in str16 format. - `void packString16(const char* value, const size_t len)`: Packs a C-style string with a specified length in str16 format. - `void packString32(const str_t& str)`: Packs a string in str32 format. - `void packString32(const str_t& str, const size_t len)`: Packs a string with a specified length in str32 format. - `void packString32(const char* value)`: Packs a C-style string in str32 format. - `void packString32(const char* value, const size_t len)`: Packs a C-style string with a specified length in str32 format. - `void packString5(const __FlashStringHelper* str)`: Packs a Flash string in str5 format. - `void packString5(const __FlashStringHelper* str, const size_t len)`: Packs a Flash string with a specified length in str5 format. - `void packString8(const __FlashStringHelper* str)`: Packs a Flash string in str8 format. - `void packString8(const __FlashStringHelper* str, const size_t len)`: Packs a Flash string with a specified length in str8 format. - `void packString16(const __FlashStringHelper* str)`: Packs a Flash string in str16 format. - `void packString16(const __FlashStringHelper* str, const size_t len)`: Packs a Flash string with a specified length in str16 format. - `void packString32(const __FlashStringHelper* str)`: Packs a Flash string in str32 format. - `void packString32(const __FlashStringHelper* str, const size_t len)`: Packs a Flash string with a specified length in str32 format. - `void packBinary8(const uint8_t* value, const uint8_t size)`: Packs binary data in bin8 format. - `void packBinary16(const uint8_t* value, const uint16_t size)`: Packs binary data in bin16 format. - `void packBinary32(const uint8_t* value, const uint32_t size)`: Packs binary data in bin32 format. - `void packArraySize4(const uint8_t value)`: Packs an array size in array4 format. - `void packArraySize16(const uint16_t value)`: Packs an array size in array16 format. - `void packArraySize32(const uint32_t value)`: Packs an array size in array32 format. - `void packMapSize4(const uint8_t value)`: Packs a map size in map4 format. - `void packMapSize16(const uint16_t value)`: Packs a map size in map16 format. - `void packMapSize32(const uint32_t value)`: Packs a map size in map32 format. - `void packFixExt1(const int8_t type, const uint8_t value)`: Packs a fixed-size extension type (1 byte) with a uint8 value. - `void packFixExt2(const int8_t type, const uint16_t value)`: Packs a fixed-size extension type (2 bytes) with a uint16 value. - `void packFixExt2(const int8_t type, const uint8_t* ptr)`: Packs a fixed-size extension type (2 bytes) with a byte pointer. - `void packFixExt2(const int8_t type, const uint16_t* ptr)`: Packs a fixed-size extension type (2 bytes) with a uint16 pointer. - `void packFixExt4(const int8_t type, const uint32_t value)`: Packs a fixed-size extension type (4 bytes) with a uint32 value. - `void packFixExt4(const int8_t type, const uint8_t* ptr)`: Packs a fixed-size extension type (4 bytes) with a byte pointer. - `void packFixExt4(const int8_t type, const uint32_t* ptr)`: Packs a fixed-size extension type (4 bytes) with a uint32 pointer. - `void packFixExt8(const int8_t type, const uint64_t value)`: Packs a fixed-size extension type (8 bytes) with a uint64 value. ``` -------------------------------- ### MsgPack::Packer - Accessor and Utility Methods Source: https://github.com/hideakitai/msgpack/blob/main/README.md Methods for accessing the serialized binary data and managing the packer's state. ```APIDOC ## MsgPack::Packer - Accessor and Utility Methods ### Description Methods for accessing the serialized binary data and managing the packer's state. ### Methods - `const bin_t& packet() const`: Returns a constant reference to the serialized binary data. - `const uint8_t* data() const`: Returns a pointer to the beginning of the serialized binary data. - `size_t size() const`: Returns the size of the serialized binary data. - `size_t indices() const`: Returns the current index or position within the buffer. - `void clear()`: Clears the internal buffer and resets the packer. ``` -------------------------------- ### MsgPack::Packer - Abstract Serializers Source: https://github.com/hideakitai/msgpack/blob/main/README.md Low-level methods for packing abstract MsgPack types like integers, floats, strings, and binary data. ```APIDOC ## MsgPack::Packer - Abstract Serializers ### Description Low-level methods for packing abstract MsgPack types like integers, floats, strings, and binary data. ### Methods - `void packInteger(const T& value)`: Packs an integer (accepts both uint and int). - `void packFloat(const T& value)`: Packs a floating-point number. - `void packString(const T& str)`: Packs a string. - `void packString(const T& str, const size_t len)`: Packs a string with a specified length. - `void packBinary(const uint8_t* bin, const size_t size)`: Packs binary data. - `void packArraySize(const size_t size)`: Packs the size of an array. - `void packMapSize(const size_t size)`: Packs the size of a map. - `void packFixExt(const int8_t type, const T value)`: Packs a fixed-size extension type with a value. - `void packFixExt(const int8_t type, const uint64_t value_h, const uint64_t value_l)`: Packs a fixed-size extension type with two uint64 values. - `void packFixExt(const int8_t type, const uint8_t* ptr, const uint8_t size)`: Packs a fixed-size extension type with a byte array. - `void packFixExt(const int8_t type, const uint16_t* ptr, const uint8_t size)`: Packs a fixed-size extension type with a uint16 array. - `void packFixExt(const int8_t type, const uint32_t* ptr, const uint8_t size)`: Packs a fixed-size extension type with a uint32 array. - `void packFixExt(const int8_t type, const uint64_t* ptr, const uint8_t size)`: Packs a fixed-size extension type with a uint64 array. - `void packExt(const int8_t type, const T* ptr, const U size)`: Packs an extension type with a pointer and size. - `void packExt(const object::ext& e)`: Packs an extension object. ``` -------------------------------- ### MsgPack::Unpacker Core Methods Source: https://github.com/hideakitai/msgpack/blob/main/README.md Core methods for managing the internal buffer and performing general deserialization of MessagePack data. ```APIDOC ## MsgPack::Unpacker Core Methods ### Description Methods for initializing the unpacker buffer, feeding data, and performing high-level deserialization. ### Methods - **reserve_indices(size_t size)**: Reserves internal buffer space for indices. - **feed(const uint8_t* data, size_t size)**: Feeds raw data into the unpacker for processing. - **deserialize(First& first, Rest&&... rest)**: Variable-sized deserializer for multiple arguments. - **deserialize(StaticJsonDocument& doc)**: Deserializes into a static JSON document. - **deserialize(DynamicJsonDocument& doc)**: Deserializes into a dynamic JSON document. - **unpack(T& value)**: Single argument deserializer. ``` -------------------------------- ### Serialize Custom Class with MSGPACK_DEFINE (Array Format) Source: https://context7.com/hideakitai/msgpack/llms.txt Use MSGPACK_DEFINE to serialize custom classes into MsgPack's array format. Ensure all member variables intended for serialization are listed within the macro. ```cpp #include struct SensorData { int id; float temperature; float humidity; MsgPack::str_t location; MSGPACK_DEFINE(id, temperature, humidity, location); }; void setup() { Serial.begin(115200); // Create and populate custom class SensorData sensor; sensor.id = 1; sensor.temperature = 25.5; sensor.humidity = 60.0; sensor.location = "Room A"; // Serialize custom class MsgPack::Packer packer; packer.serialize(sensor); // Deserialize to new instance SensorData received; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); unpacker.deserialize(received); Serial.print("ID: "); Serial.println(received.id); Serial.print("Temp: "); Serial.println(received.temperature); Serial.print("Humidity: "); Serial.println(received.humidity); Serial.print("Location: "); Serial.println(received.location); } void loop() {} ``` -------------------------------- ### Serialize and Deserialize Nested Custom Classes Source: https://github.com/hideakitai/msgpack/blob/main/README.md Define nested structures using MSGPACK_DEFINE or MSGPACK_DEFINE_MAP to represent complex data hierarchies. ```C++ // serialize and deserialize nested structure // {"i":i, "f":f, "a":["str", {"first":1, "second":"two"}]} // {"first":1, "second":"two"} struct MyMap { 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"}] struct MyArr { MsgPack::str_t s; MyMap m; MSGPACK_DEFINE(s, m): }; // {"i":i, "f":f, "a":["str", {"first":1, "second":"two"}]} struct MyNestedClass { 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); }; ``` ```C++ MyNestedClass c; MsgPack::Packer packer; packer.serialize(c); MyNestedClass cc; MsgPack::Unpacker unpacker; unpacker.feed(packer.data(), packer.size()); unpacker.deserialize(cc); ``` -------------------------------- ### JSON File Utilities Source: https://github.com/hideakitai/msgpack/blob/main/README.md Functions for saving and loading data structures to and from JSON files. ```APIDOC ## JSON File Operations ### Description Utilities for serializing and deserializing objects to JSON files using various memory strategies. ### Methods - save_as_json(fs, path, value, doc) -> bool - save_as_json_static(fs, path, value) -> bool - save_as_json_dynamic(fs, path, value, json_size) -> bool - load_from_json(fs, path, value, doc, num_max_string_type) -> bool - load_from_json_static(fs, path, value) -> bool - load_from_json_dynamic(fs, path, value, json_size) -> bool ```