Zakero's C++ Header Libraries
A collection of reusable C++ libraries
Public Attributes | List of all members
zakero::messagepack::Ext Struct Reference

Extension Data. More...

Public Attributes

std::vector< uint8_t > data
 Extension binary data.
 
int8_t type
 A unique identifier for the extension.
 

Detailed Description

The MessagePack specification defines a structure to hold new data-types and this structure implements that feature. To add a new data-type, set the Ext::type to a positive value and then fill the Ext::data with the information to be stored.

Note
Negative Ext::type value are reserved for use by the MessagePack specification.

As an example, to add a GIF data-type, define the type value then fill the Ext::data with the GIF.

Example
#define TYPE_GIF 2
#define INDEX_NAME 0
#define INDEX_FILE 1
#define INDEX_IMAGE 2
array.append({std::string_view("Super-Sonic Scooter")});
array.append({std::string_view("super_sonic_scooter.gif")});
gif.type = TYPE_GIF;
gif.data = loadGif("super_sonic_scooter.gif");
array.append(gif);
// ...somewhere later...
zakero::messagepack::Array image = object.asArray();
std::string image_name = image.object(INDEX_NAME).asString();
std::string image_file = image.object(INDEX_FILE).asString();
zakero::messagepack::Ext raw_data = image.object(INDEX_IMAGE).asExt();
Image image;
if(raw_data.type == TYPE_GIF)
{
image = parseGif(raw_data.data);
}
Object deserialize(const std::vector< uint8_t > &) noexcept
Deserialize MessagePack data.
Definition: Zakero_MessagePack.h:4678
std::vector< uint8_t > serialize(const messagepack::Array &) noexcept
Serialize Array data.
Definition: Zakero_MessagePack.h:5943
An array of Objects.
Definition: Zakero_MessagePack.h:272
Object & object(const size_t index) noexcept
Access a data object.
Definition: Zakero_MessagePack.h:291
size_t append(const bool) noexcept
Append a boolean value.
Definition: Zakero_MessagePack.h:1425
Extension Data.
Definition: Zakero_MessagePack.h:304
std::vector< uint8_t > data
Extension binary data.
Definition: Zakero_MessagePack.h:305
int8_t type
A unique identifier for the extension.
Definition: Zakero_MessagePack.h:306
A Data Object.
Definition: Zakero_MessagePack.h:337
const std::string & asString() const noexcept
Convert to a std::string.
Definition: Zakero_MessagePack.h:364
messagepack::Ext & asExt() noexcept
Convert to an Ext.
Definition: Zakero_MessagePack.h:358

Member Data Documentation

◆ data

zakero::messagepack::Ext::data

◆ type

zakero::messagepack::Ext::type

The documentation for this struct was generated from the following file: