WPILibC++ 2024.3.2
mpack.h File Reference

Abstracts all platform-specific code from MPack and handles configuration options. More...

Go to the source code of this file.

Namespaces

namespace  mpack
 

Macros

#define MPACK_AMALGAMATED   1
 The MIT License (MIT) More...
 
#define MPACK_PLATFORM_H   1
 
#define MPACK_COMMON_H   1
 
#define MPACK_PRINT_BYTE_COUNT   12
 
#define MPACK_VERSION_MAJOR   1
 The major version number of MPack. More...
 
#define MPACK_VERSION_MINOR   1
 The minor version number of MPack. More...
 
#define MPACK_VERSION_PATCH   1
 The patch version number of MPack. More...
 
#define MPACK_VERSION
 A number containing the version number of MPack for comparison purposes. More...
 
#define MPACK_VERSION_AT_LEAST(major, minor, patch)    (MPACK_VERSION >= (((major) * 10000) + ((minor) * 100) + (patch)))
 A macro to test for a minimum version of MPack. More...
 
#define MPACK_VERSION_STRING
 A string containing the MPack version. More...
 
#define MPACK_LIBRARY_STRING
 A string describing MPack, containing the library name, version and debug mode. More...
 
#define MPACK_WRITER_H   1
 
#define MPACK_WRITER_MINIMUM_BUFFER_SIZE   32
 The minimum buffer size for a writer with a flush function. More...
 
#define MPACK_READER_H   1
 
#define MPACK_READER_SMALL_FRACTION_DENOMINATOR   32
 
#define MPACK_READER_MINIMUM_BUFFER_SIZE   32
 The minimum buffer size for a reader with a fill function. More...
 
#define MPACK_EXPECT_H   1
 
#define MPACK_NODE_H   1
 
File Configuration
#define MPACK_HAS_CONFIG   0
 Causes MPack to include a file you create called mpack-config.h . More...
 
Features
#define MPACK_READER   1
 Enables compilation of the base Tag Reader. More...
 
#define MPACK_EXPECT   1
 Enables compilation of the static Expect API. More...
 
#define MPACK_NODE   1
 Enables compilation of the dynamic Node API. More...
 
#define MPACK_WRITER   1
 Enables compilation of the Writer. More...
 
#define MPACK_COMPATIBILITY   0
 Enables compatibility features for reading and writing older versions of MessagePack. More...
 
#define MPACK_EXTENSIONS   0
 Enables the use of extension types. More...
 
#define MPACK_BUILDER   1
 Enables compilation of the Builder. More...
 
Dependencies
#define MPACK_CONFORMING   1
 Enables the inclusion of basic C headers to define standard types and macros. More...
 
#define MPACK_STDLIB   1
 Enables the use of the C stdlib. More...
 
#define MPACK_STDIO   1
 Enables the use of C stdio. More...
 
#define MPACK_FLOAT   1
 Whether the 'float' type and floating point operations are supported. More...
 
#define MPACK_DOUBLE   1
 Whether the 'double' type is supported. More...
 
Allocation Functions
#define MPACK_MALLOC   malloc
 Defines the memory allocation function used by MPack. More...
 
#define MPACK_REALLOC   realloc
 Defines the realloc function used by MPack. More...
 
#define MPACK_FREE   free
 Defines the memory free function used by MPack. More...
 
System Functions
#define MPACK_MEMCMP   memcmp
 The function MPack will use to provide memcmp(). More...
 
#define MPACK_MEMCPY   memcpy
 The function MPack will use to provide memcpy(). More...
 
#define MPACK_MEMMOVE   memmove
 The function MPack will use to provide memmove(). More...
 
#define MPACK_MEMSET   memset
 The function MPack will use to provide memset(). More...
 
#define MPACK_STRLEN   strlen
 The function MPack will use to provide strlen(). More...
 
Debugging Options
#define MPACK_DEBUG   0
 Enables debug features. More...
 
#define MPACK_STRINGS   1
 Enables descriptive error and type strings. More...
 
#define MPACK_CUSTOM_ASSERT   0
 Set this to 1 to implement a custom mpack_assert_fail() function. More...
 
#define MPACK_READ_TRACKING   0
 Enables compound type size tracking for readers. More...
 
#define MPACK_WRITE_TRACKING   0
 Enables compound type size tracking for writers. More...
 
Miscellaneous Options
#define MPACK_OPTIMIZE_FOR_SIZE   0
 Whether to optimize for size or speed. More...
 
#define MPACK_STACK_SIZE   4096
 Stack space in bytes to use when initializing a reader or writer with a stack-allocated buffer. More...
 
#define MPACK_BUFFER_SIZE   4096
 Buffer size to use for allocated buffers (such as for a file writer.) More...
 
#define MPACK_PAGE_SIZE   4096
 Minimum size for paged allocations in bytes. More...
 
#define MPACK_NODE_PAGE_SIZE   MPACK_PAGE_SIZE
 Minimum size of an allocated node page in bytes. More...
 
#define MPACK_BUILDER_PAGE_SIZE   MPACK_PAGE_SIZE
 Minimum size of an allocated builder page in bytes. More...
 
#define MPACK_BUILDER_INTERNAL_STORAGE   0
 Enables a small amount of internal storage within the writer to avoid some allocations when using builders. More...
 
#define MPACK_BUILDER_INTERNAL_STORAGE_SIZE   256
 Amount of space reserved inside mpack_writer_t for the Builders. More...
 
#define MPACK_NODE_INITIAL_DEPTH   8
 The initial depth for the node parser. More...
 
#define MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC   32
 The maximum depth for the node parser if MPACK_MALLOC is not available. More...
 

Typedefs

typedef enum mpack_error_t mpack_error_t
 Error states for MPack objects. More...
 
typedef enum mpack_type_t mpack_type_t
 Defines the type of a MessagePack tag. More...
 
typedef struct mpack_tag_t mpack_tag_t
 An MPack tag is a MessagePack object header. More...
 
typedef struct mpack_writer_t mpack_writer_t
 A buffered MessagePack encoder. More...
 
typedef void(* mpack_writer_flush_t) (mpack_writer_t *writer, const char *buffer, size_t count)
 The MPack writer's flush function to flush the buffer to the output stream. More...
 
typedef void(* mpack_writer_error_t) (mpack_writer_t *writer, mpack_error_t error)
 An error handler function to be called when an error is flagged on the writer. More...
 
typedef void(* mpack_writer_teardown_t) (mpack_writer_t *writer)
 A teardown function to be called when the writer is destroyed. More...
 
typedef struct mpack_reader_t mpack_reader_t
 A buffered MessagePack decoder. More...
 
typedef size_t(* mpack_reader_fill_t) (mpack_reader_t *reader, char *buffer, size_t count)
 The MPack reader's fill function. More...
 
typedef void(* mpack_reader_skip_t) (mpack_reader_t *reader, size_t count)
 The MPack reader's skip function. More...
 
typedef void(* mpack_reader_error_t) (mpack_reader_t *reader, mpack_error_t error)
 An error handler function to be called when an error is flagged on the reader. More...
 
typedef void(* mpack_reader_teardown_t) (mpack_reader_t *reader)
 A teardown function to be called when the reader is destroyed. More...
 
typedef struct mpack_node_t mpack_node_t
 A handle to node data in a parsed MPack tree. More...
 
typedef struct mpack_node_data_t mpack_node_data_t
 The storage for nodes in an MPack tree. More...
 
typedef struct mpack_tree_t mpack_tree_t
 An MPack tree parser to parse a blob or stream of MessagePack. More...
 
typedef void(* mpack_tree_error_t) (mpack_tree_t *tree, mpack_error_t error)
 An error handler function to be called when an error is flagged on the tree. More...
 
typedef size_t(* mpack_tree_read_t) (mpack_tree_t *tree, char *buffer, size_t count)
 The MPack tree's read function. More...
 
typedef void(* mpack_tree_teardown_t) (mpack_tree_t *tree)
 A teardown function to be called when the tree is destroyed. More...
 

Enumerations

enum  mpack_error_t {
  mpack_ok = 0 , mpack_error_io = 2 , mpack_error_invalid , mpack_error_unsupported ,
  mpack_error_type , mpack_error_too_big , mpack_error_memory , mpack_error_bug ,
  mpack_error_data , mpack_error_eof
}
 Error states for MPack objects. More...
 
enum  mpack_type_t {
  mpack_type_missing = 0 , mpack_type_nil , mpack_type_bool , mpack_type_int ,
  mpack_type_uint , mpack_type_float , mpack_type_double , mpack_type_str ,
  mpack_type_bin , mpack_type_array , mpack_type_map
}
 Defines the type of a MessagePack tag. More...
 

Functions

const char * mpack_error_to_string (mpack_error_t error)
 Converts an MPack error to a string. More...
 
const char * mpack_type_to_string (mpack_type_t type)
 Converts an MPack type to a string. More...
 
Tag Querying Functions
MPACK_INLINE mpack_type_t mpack_tag_type (mpack_tag_t *tag)
 Gets the type of a tag. More...
 
MPACK_INLINE bool mpack_tag_bool_value (mpack_tag_t *tag)
 Gets the boolean value of a bool-type tag. More...
 
MPACK_INLINE int64_t mpack_tag_int_value (mpack_tag_t *tag)
 Gets the signed integer value of an int-type tag. More...
 
MPACK_INLINE uint64_t mpack_tag_uint_value (mpack_tag_t *tag)
 Gets the unsigned integer value of a uint-type tag. More...
 
MPACK_INLINE float mpack_tag_float_value (mpack_tag_t *tag)
 Gets the float value of a float-type tag. More...
 
MPACK_INLINE double mpack_tag_double_value (mpack_tag_t *tag)
 Gets the double value of a double-type tag. More...
 
MPACK_INLINE uint32_t mpack_tag_array_count (mpack_tag_t *tag)
 Gets the number of elements in an array tag. More...
 
MPACK_INLINE uint32_t mpack_tag_map_count (mpack_tag_t *tag)
 Gets the number of key-value pairs in a map tag. More...
 
MPACK_INLINE uint32_t mpack_tag_str_length (mpack_tag_t *tag)
 Gets the length in bytes of a str-type tag. More...
 
MPACK_INLINE uint32_t mpack_tag_bin_length (mpack_tag_t *tag)
 Gets the length in bytes of a bin-type tag. More...
 
MPACK_INLINE uint32_t mpack_tag_bytes (mpack_tag_t *tag)
 Gets the length in bytes of a str-, bin- or ext-type tag. More...
 
Other tag functions
int mpack_tag_cmp (mpack_tag_t left, mpack_tag_t right)
 Compares two tags with an arbitrary fixed ordering. More...
 
MPACK_INLINE bool mpack_tag_equal (mpack_tag_t left, mpack_tag_t right)
 Compares two tags for equality. More...
 
Deprecated Tag Generators
MPACK_INLINE mpack_tag_t mpack_tag_nil (void)
 
MPACK_INLINE mpack_tag_t mpack_tag_bool (bool value)
 
MPACK_INLINE mpack_tag_t mpack_tag_true (void)
 
MPACK_INLINE mpack_tag_t mpack_tag_false (void)
 
MPACK_INLINE mpack_tag_t mpack_tag_int (int64_t value)
 
MPACK_INLINE mpack_tag_t mpack_tag_uint (uint64_t value)
 
MPACK_INLINE mpack_tag_t mpack_tag_float (float value)
 
MPACK_INLINE mpack_tag_t mpack_tag_double (double value)
 
MPACK_INLINE mpack_tag_t mpack_tag_array (int32_t count)
 
MPACK_INLINE mpack_tag_t mpack_tag_map (int32_t count)
 
MPACK_INLINE mpack_tag_t mpack_tag_str (int32_t length)
 
MPACK_INLINE mpack_tag_t mpack_tag_bin (int32_t length)
 
Configuration
MPACK_INLINE void mpack_writer_set_context (mpack_writer_t *writer, void *context)
 Sets the custom pointer to pass to the writer callbacks, such as flush or teardown. More...
 
MPACK_INLINE void * mpack_writer_context (mpack_writer_t *writer)
 Returns the custom context for writer callbacks. More...
 
void mpack_writer_set_flush (mpack_writer_t *writer, mpack_writer_flush_t flush)
 Sets the flush function to write out the data when the buffer is full. More...
 
MPACK_INLINE void mpack_writer_set_error_handler (mpack_writer_t *writer, mpack_writer_error_t error_fn)
 Sets the error function to call when an error is flagged on the writer. More...
 
MPACK_INLINE void mpack_writer_set_teardown (mpack_writer_t *writer, mpack_writer_teardown_t teardown)
 Sets the teardown function to call when the writer is destroyed. More...
 
Core Writer Functions
void mpack_writer_flush_message (mpack_writer_t *writer)
 Flushes any buffered data to the underlying stream. More...
 
MPACK_INLINE size_t mpack_writer_buffer_used (mpack_writer_t *writer)
 Returns the number of bytes currently stored in the buffer. More...
 
MPACK_INLINE size_t mpack_writer_buffer_left (mpack_writer_t *writer)
 Returns the amount of space left in the buffer. More...
 
MPACK_INLINE size_t mpack_writer_buffer_size (mpack_writer_t *writer)
 Returns the (current) size of the buffer. More...
 
void mpack_writer_flag_error (mpack_writer_t *writer, mpack_error_t error)
 Places the writer in the given error state, calling the error callback if one is set. More...
 
MPACK_INLINE mpack_error_t mpack_writer_error (mpack_writer_t *writer)
 Queries the error state of the MPack writer. More...
 
void mpack_write_tag (mpack_writer_t *writer, mpack_tag_t tag)
 Writes a MessagePack object header (an MPack Tag.) More...
 
Integers
void mpack_write_i8 (mpack_writer_t *writer, int8_t value)
 Writes an 8-bit integer in the most efficient packing available. More...
 
void mpack_write_i16 (mpack_writer_t *writer, int16_t value)
 Writes a 16-bit integer in the most efficient packing available. More...
 
void mpack_write_i32 (mpack_writer_t *writer, int32_t value)
 Writes a 32-bit integer in the most efficient packing available. More...
 
void mpack_write_i64 (mpack_writer_t *writer, int64_t value)
 Writes a 64-bit integer in the most efficient packing available. More...
 
MPACK_INLINE void mpack_write_int (mpack_writer_t *writer, int64_t value)
 Writes an integer in the most efficient packing available. More...
 
void mpack_write_u8 (mpack_writer_t *writer, uint8_t value)
 Writes an 8-bit unsigned integer in the most efficient packing available. More...
 
void mpack_write_u16 (mpack_writer_t *writer, uint16_t value)
 Writes an 16-bit unsigned integer in the most efficient packing available. More...
 
void mpack_write_u32 (mpack_writer_t *writer, uint32_t value)
 Writes an 32-bit unsigned integer in the most efficient packing available. More...
 
void mpack_write_u64 (mpack_writer_t *writer, uint64_t value)
 Writes an 64-bit unsigned integer in the most efficient packing available. More...
 
MPACK_INLINE void mpack_write_uint (mpack_writer_t *writer, uint64_t value)
 Writes an unsigned integer in the most efficient packing available. More...
 
Other Basic Types
void mpack_write_float (mpack_writer_t *writer, float value)
 Writes a float. More...
 
void mpack_write_double (mpack_writer_t *writer, double value)
 Writes a double. More...
 
void mpack_write_bool (mpack_writer_t *writer, bool value)
 Writes a boolean. More...
 
void mpack_write_true (mpack_writer_t *writer)
 Writes a boolean with value true. More...
 
void mpack_write_false (mpack_writer_t *writer)
 Writes a boolean with value false. More...
 
void mpack_write_nil (mpack_writer_t *writer)
 Writes a nil. More...
 
void mpack_write_object_bytes (mpack_writer_t *writer, const char *data, size_t bytes)
 Write a pre-encoded messagepack object. More...
 
void mpack_expect_nil (mpack_reader_t *reader)
 Reads a nil, raising mpack_error_type if the value is not nil. More...
 
bool mpack_expect_bool (mpack_reader_t *reader)
 Reads a boolean. More...
 
void mpack_expect_true (mpack_reader_t *reader)
 Reads a boolean, raising mpack_error_type if its value is not true. More...
 
void mpack_expect_false (mpack_reader_t *reader)
 Reads a boolean, raising mpack_error_type if its value is not false. More...
 
Map and Array Functions
void mpack_start_array (mpack_writer_t *writer, uint32_t count)
 Opens an array. More...
 
void mpack_start_map (mpack_writer_t *writer, uint32_t count)
 Opens a map. More...
 
MPACK_INLINE void mpack_builder_compound_push (mpack_writer_t *writer)
 
MPACK_INLINE void mpack_builder_compound_pop (mpack_writer_t *writer)
 
MPACK_INLINE void mpack_finish_array (mpack_writer_t *writer)
 Finishes writing an array. More...
 
MPACK_INLINE void mpack_finish_map (mpack_writer_t *writer)
 Finishes writing a map. More...
 
void mpack_build_array (struct mpack_writer_t *writer)
 Starts building an array. More...
 
void mpack_build_map (struct mpack_writer_t *writer)
 Starts building a map. More...
 
void mpack_complete_array (struct mpack_writer_t *writer)
 Completes an array being built. More...
 
void mpack_complete_map (struct mpack_writer_t *writer)
 Completes a map being built. More...
 
Data Helpers
void mpack_write_str (mpack_writer_t *writer, const char *str, uint32_t length)
 Writes a string. More...
 
void mpack_write_utf8 (mpack_writer_t *writer, const char *str, uint32_t length)
 Writes a string, ensuring that it is valid UTF-8. More...
 
void mpack_write_cstr (mpack_writer_t *writer, const char *cstr)
 Writes a null-terminated string. More...
 
void mpack_write_cstr_or_nil (mpack_writer_t *writer, const char *cstr)
 Writes a null-terminated string, or a nil node if the given cstr pointer is NULL. More...
 
void mpack_write_utf8_cstr (mpack_writer_t *writer, const char *cstr)
 Writes a null-terminated string, ensuring that it is valid UTF-8. More...
 
void mpack_write_utf8_cstr_or_nil (mpack_writer_t *writer, const char *cstr)
 Writes a null-terminated string ensuring that it is valid UTF-8, or writes nil if the given cstr pointer is NULL. More...
 
void mpack_write_bin (mpack_writer_t *writer, const char *data, uint32_t count)
 Writes a binary blob. More...
 
Chunked Data Functions
void mpack_start_str (mpack_writer_t *writer, uint32_t count)
 Opens a string. More...
 
void mpack_start_bin (mpack_writer_t *writer, uint32_t count)
 Opens a binary blob. More...
 
void mpack_write_bytes (mpack_writer_t *writer, const char *data, size_t count)
 Writes a portion of bytes for a string, binary blob or extension type which was opened by mpack_write_tag() or one of the mpack_start_*() functions. More...
 
MPACK_INLINE void mpack_finish_str (mpack_writer_t *writer)
 Finishes writing a string. More...
 
MPACK_INLINE void mpack_finish_bin (mpack_writer_t *writer)
 Finishes writing a binary blob. More...
 
MPACK_INLINE void mpack_finish_type (mpack_writer_t *writer, mpack_type_t type)
 Finishes writing the given compound type. More...
 
C++ write overloads
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, int8_t value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, int16_t value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, int32_t value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, int64_t value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, uint8_t value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, uint16_t value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, uint32_t value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, uint64_t value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, bool value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, float value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, double value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, char *value)
 
MPACK_INLINE void mpack::mpack_write (mpack_writer_t *writer, const char *value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, int8_t value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, int16_t value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, int32_t value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, int64_t value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, uint8_t value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, uint16_t value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, uint32_t value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, uint64_t value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, bool value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, float value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, double value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, char *value)
 
MPACK_INLINE void mpack::mpack_write_kv (mpack_writer_t *writer, const char *key, const char *value)
 
Callbacks
MPACK_INLINE void mpack_reader_set_context (mpack_reader_t *reader, void *context)
 Sets the custom pointer to pass to the reader callbacks, such as fill or teardown. More...
 
MPACK_INLINE void * mpack_reader_context (mpack_reader_t *reader)
 Returns the custom context for reader callbacks. More...
 
void mpack_reader_set_fill (mpack_reader_t *reader, mpack_reader_fill_t fill)
 Sets the fill function to refill the data buffer when it runs out of data. More...
 
void mpack_reader_set_skip (mpack_reader_t *reader, mpack_reader_skip_t skip)
 Sets the skip function to discard bytes from the source stream. More...
 
MPACK_INLINE void mpack_reader_set_error_handler (mpack_reader_t *reader, mpack_reader_error_t error_fn)
 Sets the error function to call when an error is flagged on the reader. More...
 
MPACK_INLINE void mpack_reader_set_teardown (mpack_reader_t *reader, mpack_reader_teardown_t teardown)
 Sets the teardown function to call when the reader is destroyed. More...
 
Core Reader Functions
MPACK_INLINE mpack_error_t mpack_reader_error (mpack_reader_t *reader)
 Queries the error state of the MPack reader. More...
 
void mpack_reader_flag_error (mpack_reader_t *reader, mpack_error_t error)
 Places the reader in the given error state, calling the error callback if one is set. More...
 
MPACK_INLINE mpack_error_t mpack_reader_flag_if_error (mpack_reader_t *reader, mpack_error_t error)
 Places the reader in the given error state if the given error is not mpack_ok, returning the resulting error state of the reader. More...
 
size_t mpack_reader_remaining (mpack_reader_t *reader, const char **data)
 Returns bytes left in the reader's buffer. More...
 
mpack_tag_t mpack_read_tag (mpack_reader_t *reader)
 Reads a MessagePack object header (an MPack tag.) More...
 
mpack_tag_t mpack_peek_tag (mpack_reader_t *reader)
 Parses the next MessagePack object header (an MPack tag) without advancing the reader. More...
 
MPACK_INLINE void mpack_done_type (mpack_reader_t *reader, mpack_type_t type)
 
MPACK_INLINE void mpack_done_array (mpack_reader_t *reader)
 Finishes reading an array. More...
 
MPACK_INLINE void mpack_done_map (mpack_reader_t *reader)
 Finishes reading a map. More...
 
MPACK_INLINE void mpack_done_str (mpack_reader_t *reader)
 Finishes reading a string. More...
 
MPACK_INLINE void mpack_done_bin (mpack_reader_t *reader)
 Finishes reading a binary data blob. More...
 
void mpack_discard (mpack_reader_t *reader)
 Reads and discards the next object. More...
 
String and Data Functions
void mpack_skip_bytes (mpack_reader_t *reader, size_t count)
 Skips bytes from the underlying stream. More...
 
void mpack_read_bytes (mpack_reader_t *reader, char *p, size_t count)
 Reads bytes from a string, binary blob or extension object, copying them into the given buffer. More...
 
void mpack_read_utf8 (mpack_reader_t *reader, char *p, size_t byte_count)
 Reads bytes from a string, ensures that the string is valid UTF-8, and copies the bytes into the given buffer. More...
 
void mpack_read_cstr (mpack_reader_t *reader, char *buf, size_t buffer_size, size_t byte_count)
 Reads bytes from a string, ensures that the string contains no NUL bytes, copies the bytes into the given buffer and adds a null-terminator. More...
 
void mpack_read_utf8_cstr (mpack_reader_t *reader, char *buf, size_t buffer_size, size_t byte_count)
 Reads bytes from a string, ensures that the string is valid UTF-8 with no NUL bytes, copies the bytes into the given buffer and adds a null-terminator. More...
 
MPACK_INLINE char * mpack_read_bytes_alloc (mpack_reader_t *reader, size_t count)
 Reads bytes from a string, binary blob or extension object, allocating storage for them and returning the allocated pointer. More...
 
const char * mpack_read_bytes_inplace (mpack_reader_t *reader, size_t count)
 Reads bytes from a string, binary blob or extension object in-place in the buffer. More...
 
const char * mpack_read_utf8_inplace (mpack_reader_t *reader, size_t count)
 Reads bytes from a string in-place in the buffer and ensures they are valid UTF-8. More...
 
MPACK_INLINE bool mpack_should_read_bytes_inplace (mpack_reader_t *reader, size_t count)
 Returns true if it's a good idea to read the given number of bytes in-place. More...
 
Basic Number Functions
uint8_t mpack_expect_u8 (mpack_reader_t *reader)
 Reads an 8-bit unsigned integer. More...
 
uint16_t mpack_expect_u16 (mpack_reader_t *reader)
 Reads a 16-bit unsigned integer. More...
 
uint32_t mpack_expect_u32 (mpack_reader_t *reader)
 Reads a 32-bit unsigned integer. More...
 
uint64_t mpack_expect_u64 (mpack_reader_t *reader)
 Reads a 64-bit unsigned integer. More...
 
int8_t mpack_expect_i8 (mpack_reader_t *reader)
 Reads an 8-bit signed integer. More...
 
int16_t mpack_expect_i16 (mpack_reader_t *reader)
 Reads a 16-bit signed integer. More...
 
int32_t mpack_expect_i32 (mpack_reader_t *reader)
 Reads a 32-bit signed integer. More...
 
int64_t mpack_expect_i64 (mpack_reader_t *reader)
 Reads a 64-bit signed integer. More...
 
float mpack_expect_float (mpack_reader_t *reader)
 Reads a number, returning the value as a float. More...
 
double mpack_expect_double (mpack_reader_t *reader)
 Reads a number, returning the value as a double. More...
 
float mpack_expect_float_strict (mpack_reader_t *reader)
 Reads a float. More...
 
double mpack_expect_double_strict (mpack_reader_t *reader)
 Reads a double. More...
 
MPACK_INLINE unsigned int mpack_expect_uint (mpack_reader_t *reader)
 Reads an unsigned int. More...
 
MPACK_INLINE int mpack_expect_int (mpack_reader_t *reader)
 Reads a signed int. More...
 
Ranged Number Functions
uint8_t mpack_expect_u8_range (mpack_reader_t *reader, uint8_t min_value, uint8_t max_value)
 Reads an 8-bit unsigned integer, ensuring that it falls within the given range. More...
 
uint16_t mpack_expect_u16_range (mpack_reader_t *reader, uint16_t min_value, uint16_t max_value)
 Reads a 16-bit unsigned integer, ensuring that it falls within the given range. More...
 
uint32_t mpack_expect_u32_range (mpack_reader_t *reader, uint32_t min_value, uint32_t max_value)
 Reads a 32-bit unsigned integer, ensuring that it falls within the given range. More...
 
uint64_t mpack_expect_u64_range (mpack_reader_t *reader, uint64_t min_value, uint64_t max_value)
 Reads a 64-bit unsigned integer, ensuring that it falls within the given range. More...
 
MPACK_INLINE unsigned int mpack_expect_uint_range (mpack_reader_t *reader, unsigned int min_value, unsigned int max_value)
 Reads an unsigned integer, ensuring that it falls within the given range. More...
 
MPACK_INLINE uint8_t mpack_expect_u8_max (mpack_reader_t *reader, uint8_t max_value)
 Reads an 8-bit unsigned integer, ensuring that it is at most max_value. More...
 
MPACK_INLINE uint16_t mpack_expect_u16_max (mpack_reader_t *reader, uint16_t max_value)
 Reads a 16-bit unsigned integer, ensuring that it is at most max_value. More...
 
MPACK_INLINE uint32_t mpack_expect_u32_max (mpack_reader_t *reader, uint32_t max_value)
 Reads a 32-bit unsigned integer, ensuring that it is at most max_value. More...
 
MPACK_INLINE uint64_t mpack_expect_u64_max (mpack_reader_t *reader, uint64_t max_value)
 Reads a 64-bit unsigned integer, ensuring that it is at most max_value. More...
 
MPACK_INLINE unsigned int mpack_expect_uint_max (mpack_reader_t *reader, unsigned int max_value)
 Reads an unsigned integer, ensuring that it is at most max_value. More...
 
int8_t mpack_expect_i8_range (mpack_reader_t *reader, int8_t min_value, int8_t max_value)
 Reads an 8-bit signed integer, ensuring that it falls within the given range. More...
 
int16_t mpack_expect_i16_range (mpack_reader_t *reader, int16_t min_value, int16_t max_value)
 Reads a 16-bit signed integer, ensuring that it falls within the given range. More...
 
int32_t mpack_expect_i32_range (mpack_reader_t *reader, int32_t min_value, int32_t max_value)
 Reads a 32-bit signed integer, ensuring that it falls within the given range. More...
 
int64_t mpack_expect_i64_range (mpack_reader_t *reader, int64_t min_value, int64_t max_value)
 Reads a 64-bit signed integer, ensuring that it falls within the given range. More...
 
MPACK_INLINE int mpack_expect_int_range (mpack_reader_t *reader, int min_value, int max_value)
 Reads a signed integer, ensuring that it falls within the given range. More...
 
MPACK_INLINE int8_t mpack_expect_i8_max (mpack_reader_t *reader, int8_t max_value)
 Reads an 8-bit signed integer, ensuring that it is at least zero and at most max_value. More...
 
MPACK_INLINE int16_t mpack_expect_i16_max (mpack_reader_t *reader, int16_t max_value)
 Reads a 16-bit signed integer, ensuring that it is at least zero and at most max_value. More...
 
MPACK_INLINE int32_t mpack_expect_i32_max (mpack_reader_t *reader, int32_t max_value)
 Reads a 32-bit signed integer, ensuring that it is at least zero and at most max_value. More...
 
MPACK_INLINE int64_t mpack_expect_i64_max (mpack_reader_t *reader, int64_t max_value)
 Reads a 64-bit signed integer, ensuring that it is at least zero and at most max_value. More...
 
MPACK_INLINE int mpack_expect_int_max (mpack_reader_t *reader, int max_value)
 Reads an int, ensuring that it is at least zero and at most max_value. More...
 
float mpack_expect_float_range (mpack_reader_t *reader, float min_value, float max_value)
 Reads a number, ensuring that it falls within the given range and returning the value as a float. More...
 
double mpack_expect_double_range (mpack_reader_t *reader, double min_value, double max_value)
 Reads a number, ensuring that it falls within the given range and returning the value as a double. More...
 
Matching Number Functions
void mpack_expect_uint_match (mpack_reader_t *reader, uint64_t value)
 Reads an unsigned integer, ensuring that it exactly matches the given value. More...
 
void mpack_expect_int_match (mpack_reader_t *reader, int64_t value)
 Reads a signed integer, ensuring that it exactly matches the given value. More...
 
String Functions
uint32_t mpack_expect_str (mpack_reader_t *reader)
 Reads the start of a string, returning its size in bytes. More...
 
size_t mpack_expect_str_buf (mpack_reader_t *reader, char *buf, size_t bufsize)
 Reads a string of at most the given size, writing it into the given buffer and returning its size in bytes. More...
 
size_t mpack_expect_utf8 (mpack_reader_t *reader, char *buf, size_t bufsize)
 Reads a string into the given buffer, ensuring it is a valid UTF-8 string and returning its size in bytes. More...
 
MPACK_INLINE uint32_t mpack_expect_str_max (mpack_reader_t *reader, uint32_t maxsize)
 Reads the start of a string, raising an error if its length is not at most the given number of bytes (not including any null-terminator.) More...
 
MPACK_INLINE void mpack_expect_str_length (mpack_reader_t *reader, uint32_t count)
 Reads the start of a string, raising an error if its length is not exactly the given number of bytes (not including any null-terminator.) More...
 
void mpack_expect_str_match (mpack_reader_t *reader, const char *str, size_t length)
 Reads a string, ensuring it exactly matches the given string. More...
 
void mpack_expect_cstr (mpack_reader_t *reader, char *buf, size_t size)
 Reads a string into the given buffer, ensures it has no null bytes, and adds a null-terminator at the end. More...
 
void mpack_expect_utf8_cstr (mpack_reader_t *reader, char *buf, size_t size)
 Reads a string into the given buffer, ensures it is a valid UTF-8 string without NUL characters, and adds a null-terminator at the end. More...
 
char * mpack_expect_cstr_alloc (mpack_reader_t *reader, size_t maxsize)
 Reads a string with the given total maximum size (including space for a null-terminator), allocates storage for it, ensures it has no null-bytes, and adds a null-terminator at the end. More...
 
char * mpack_expect_utf8_cstr_alloc (mpack_reader_t *reader, size_t maxsize)
 Reads a string with the given total maximum size (including space for a null-terminator), allocates storage for it, ensures it is valid UTF-8 with no null-bytes, and adds a null-terminator at the end. More...
 
MPACK_INLINE void mpack_expect_cstr_match (mpack_reader_t *reader, const char *cstr)
 Reads a string, ensuring it exactly matches the given null-terminated string. More...
 
Binary Data
uint32_t mpack_expect_bin (mpack_reader_t *reader)
 Reads the start of a binary blob, returning its size in bytes. More...
 
MPACK_INLINE uint32_t mpack_expect_bin_max (mpack_reader_t *reader, uint32_t maxsize)
 Reads the start of a binary blob, raising an error if its length is not at most the given number of bytes. More...
 
MPACK_INLINE void mpack_expect_bin_size (mpack_reader_t *reader, uint32_t count)
 Reads the start of a binary blob, raising an error if its length is not exactly the given number of bytes. More...
 
size_t mpack_expect_bin_buf (mpack_reader_t *reader, char *buf, size_t size)
 Reads a binary blob into the given buffer, returning its size in bytes. More...
 
void mpack_expect_bin_size_buf (mpack_reader_t *reader, char *buf, uint32_t size)
 Reads a binary blob with the exact given size into the given buffer. More...
 
char * mpack_expect_bin_alloc (mpack_reader_t *reader, size_t maxsize, size_t *size)
 Reads a binary blob with the given total maximum size, allocating storage for it. More...
 
Special Functions
void mpack_expect_tag (mpack_reader_t *reader, mpack_tag_t tag)
 Reads a MessagePack object header (an MPack tag), expecting it to exactly match the given tag. More...
 
size_t mpack_expect_enum (mpack_reader_t *reader, const char *strings[], size_t count)
 Expects a string matching one of the strings in the given array, returning its array index. More...
 
size_t mpack_expect_enum_optional (mpack_reader_t *reader, const char *strings[], size_t count)
 Expects a string matching one of the strings in the given array returning its array index, or count if no strings match. More...
 
size_t mpack_expect_key_uint (mpack_reader_t *reader, bool found[], size_t count)
 Expects an unsigned integer map key between 0 and count-1, marking it as found in the given bool array and returning it. More...
 
size_t mpack_expect_key_cstr (mpack_reader_t *reader, const char *keys[], bool found[], size_t count)
 Expects a string map key matching one of the strings in the given key list, marking it as found in the given bool array and returning its index. More...
 
Tree Initialization
void mpack_tree_init_data (mpack_tree_t *tree, const char *data, size_t length)
 Initializes a tree parser with the given data. More...
 
MPACK_INLINE void mpack_tree_init (mpack_tree_t *tree, const char *data, size_t length)
 Deprecated. More...
 
void mpack_tree_init_stream (mpack_tree_t *tree, mpack_tree_read_t read_fn, void *context, size_t max_message_size, size_t max_message_nodes)
 Initializes a tree parser from an unbounded stream, or a stream of unknown length. More...
 
void mpack_tree_init_pool (mpack_tree_t *tree, const char *data, size_t length, mpack_node_data_t *node_pool, size_t node_pool_count)
 Initializes a tree parser with the given data, using the given node data pool to store the results. More...
 
void mpack_tree_init_error (mpack_tree_t *tree, mpack_error_t error)
 Initializes an MPack tree directly into an error state. More...
 
void mpack_tree_init_filename (mpack_tree_t *tree, const char *filename, size_t max_bytes)
 Initializes a tree to parse the given file. More...
 
MPACK_INLINE void mpack_tree_init_file (mpack_tree_t *tree, const char *filename, size_t max_bytes)
 Deprecated. More...
 
void mpack_tree_init_stdfile (mpack_tree_t *tree, FILE *stdfile, size_t max_bytes, bool close_when_done)
 Initializes a tree to parse the given libc FILE. More...
 
Tree Functions
void mpack_tree_set_limits (mpack_tree_t *tree, size_t max_message_size, size_t max_message_nodes)
 Sets the maximum byte size and maximum number of nodes allowed per message. More...
 
void mpack_tree_parse (mpack_tree_t *tree)
 Parses a MessagePack message into a tree of immutable nodes. More...
 
bool mpack_tree_try_parse (mpack_tree_t *tree)
 Attempts to parse a MessagePack message from a non-blocking stream into a tree of immutable nodes. More...
 
mpack_node_t mpack_tree_root (mpack_tree_t *tree)
 Returns the root node of the tree, if the tree is not in an error state. More...
 
MPACK_INLINE mpack_error_t mpack_tree_error (mpack_tree_t *tree)
 Returns the error state of the tree. More...
 
MPACK_INLINE size_t mpack_tree_size (mpack_tree_t *tree)
 Returns the size in bytes of the current parsed message. More...
 
mpack_error_t mpack_tree_destroy (mpack_tree_t *tree)
 Destroys the tree. More...
 
MPACK_INLINE void mpack_tree_set_context (mpack_tree_t *tree, void *context)
 Sets the custom pointer to pass to the tree callbacks, such as teardown. More...
 
MPACK_INLINE void * mpack_tree_context (mpack_tree_t *tree)
 Returns the custom context for tree callbacks. More...
 
MPACK_INLINE void mpack_tree_set_error_handler (mpack_tree_t *tree, mpack_tree_error_t error_fn)
 Sets the error function to call when an error is flagged on the tree. More...
 
MPACK_INLINE void mpack_tree_set_teardown (mpack_tree_t *tree, mpack_tree_teardown_t teardown)
 Sets the teardown function to call when the tree is destroyed. More...
 
void mpack_tree_flag_error (mpack_tree_t *tree, mpack_error_t error)
 Places the tree in the given error state, calling the error callback if one is set. More...
 
Node Core Functions
void mpack_node_flag_error (mpack_node_t node, mpack_error_t error)
 Places the node's tree in the given error state, calling the error callback if one is set. More...
 
MPACK_INLINE mpack_error_t mpack_node_error (mpack_node_t node)
 Returns the error state of the node's tree. More...
 
mpack_tag_t mpack_node_tag (mpack_node_t node)
 Returns a tag describing the given node, or a nil tag if the tree is in an error state. More...
 
Node Primitive Value Functions
mpack_type_t mpack_node_type (mpack_node_t node)
 Returns the type of the node. More...
 
bool mpack_node_is_nil (mpack_node_t node)
 Returns true if the given node is a nil node; false otherwise. More...
 
bool mpack_node_is_missing (mpack_node_t node)
 Returns true if the given node handle indicates a missing node; false otherwise. More...
 
void mpack_node_nil (mpack_node_t node)
 Checks that the given node is of nil type, raising mpack_error_type otherwise. More...
 
void mpack_node_missing (mpack_node_t node)
 Checks that the given node indicates a missing node, raising mpack_error_type otherwise. More...
 
bool mpack_node_bool (mpack_node_t node)
 Returns the bool value of the node. More...
 
void mpack_node_true (mpack_node_t node)
 Checks if the given node is of bool type with value true, raising mpack_error_type otherwise. More...
 
void mpack_node_false (mpack_node_t node)
 Checks if the given node is of bool type with value false, raising mpack_error_type otherwise. More...
 
uint8_t mpack_node_u8 (mpack_node_t node)
 Returns the 8-bit unsigned value of the node. More...
 
int8_t mpack_node_i8 (mpack_node_t node)
 Returns the 8-bit signed value of the node. More...
 
uint16_t mpack_node_u16 (mpack_node_t node)
 Returns the 16-bit unsigned value of the node. More...
 
int16_t mpack_node_i16 (mpack_node_t node)
 Returns the 16-bit signed value of the node. More...
 
uint32_t mpack_node_u32 (mpack_node_t node)
 Returns the 32-bit unsigned value of the node. More...
 
int32_t mpack_node_i32 (mpack_node_t node)
 Returns the 32-bit signed value of the node. More...
 
uint64_t mpack_node_u64 (mpack_node_t node)
 Returns the 64-bit unsigned value of the node. More...
 
int64_t mpack_node_i64 (mpack_node_t node)
 Returns the 64-bit signed value of the node. More...
 
unsigned int mpack_node_uint (mpack_node_t node)
 Returns the unsigned int value of the node. More...
 
int mpack_node_int (mpack_node_t node)
 Returns the int value of the node. More...
 
float mpack_node_float (mpack_node_t node)
 Returns the float value of the node. More...
 
double mpack_node_double (mpack_node_t node)
 Returns the double value of the node. More...
 
float mpack_node_float_strict (mpack_node_t node)
 Returns the float value of the node. More...
 
double mpack_node_double_strict (mpack_node_t node)
 Returns the double value of the node. More...
 
Node String and Data Functions
void mpack_node_check_utf8 (mpack_node_t node)
 Checks that the given node contains a valid UTF-8 string. More...
 
void mpack_node_check_utf8_cstr (mpack_node_t node)
 Checks that the given node contains a valid UTF-8 string with no NUL bytes. More...
 
size_t mpack_node_bin_size (mpack_node_t node)
 Returns the number of bytes in the given bin node. More...
 
uint32_t mpack_node_data_len (mpack_node_t node)
 Returns the length of the given str, bin or ext node. More...
 
size_t mpack_node_strlen (mpack_node_t node)
 Returns the length in bytes of the given string node. More...
 
const char * mpack_node_str (mpack_node_t node)
 Returns a pointer to the data contained by this node, ensuring the node is a string. More...
 
const char * mpack_node_data (mpack_node_t node)
 Returns a pointer to the data contained by this node. More...
 
const char * mpack_node_bin_data (mpack_node_t node)
 Returns a pointer to the data contained by this bin node. More...
 
size_t mpack_node_copy_data (mpack_node_t node, char *buffer, size_t bufsize)
 Copies the bytes contained by this node into the given buffer, returning the number of bytes in the node. More...
 
size_t mpack_node_copy_utf8 (mpack_node_t node, char *buffer, size_t bufsize)
 Checks that the given node contains a valid UTF-8 string and copies the string into the given buffer, returning the number of bytes in the string. More...
 
void mpack_node_copy_cstr (mpack_node_t node, char *buffer, size_t size)
 Checks that the given node contains a string with no NUL bytes, copies the string into the given buffer, and adds a null terminator. More...
 
void mpack_node_copy_utf8_cstr (mpack_node_t node, char *buffer, size_t size)
 Checks that the given node contains a valid UTF-8 string with no NUL bytes, copies the string into the given buffer, and adds a null terminator. More...
 
char * mpack_node_data_alloc (mpack_node_t node, size_t maxsize)
 Allocates a new chunk of data using MPACK_MALLOC() with the bytes contained by this node. More...
 
char * mpack_node_cstr_alloc (mpack_node_t node, size_t maxsize)
 Allocates a new null-terminated string using MPACK_MALLOC() with the string contained by this node. More...
 
char * mpack_node_utf8_cstr_alloc (mpack_node_t node, size_t maxsize)
 Allocates a new null-terminated string using MPACK_MALLOC() with the UTF-8 string contained by this node. More...
 
size_t mpack_node_enum (mpack_node_t node, const char *strings[], size_t count)
 Searches the given string array for a string matching the given node and returns its index. More...
 
size_t mpack_node_enum_optional (mpack_node_t node, const char *strings[], size_t count)
 Searches the given string array for a string matching the given node, returning its index or count if no strings match. More...
 
Compound Node Functions
size_t mpack_node_array_length (mpack_node_t node)
 Returns the length of the given array node. More...
 
mpack_node_t mpack_node_array_at (mpack_node_t node, size_t index)
 Returns the node in the given array at the given index. More...
 
size_t mpack_node_map_count (mpack_node_t node)
 Returns the number of key/value pairs in the given map node. More...
 
mpack_node_t mpack_node_map_key_at (mpack_node_t node, size_t index)
 Returns the key node in the given map at the given index. More...
 
mpack_node_t mpack_node_map_value_at (mpack_node_t node, size_t index)
 Returns the value node in the given map at the given index. More...
 
mpack_node_t mpack_node_map_int (mpack_node_t node, int64_t num)
 Returns the value node in the given map for the given integer key. More...
 
mpack_node_t mpack_node_map_int_optional (mpack_node_t node, int64_t num)
 Returns the value node in the given map for the given integer key, or a missing node if the map does not contain the given key. More...
 
mpack_node_t mpack_node_map_uint (mpack_node_t node, uint64_t num)
 Returns the value node in the given map for the given unsigned integer key. More...
 
mpack_node_t mpack_node_map_uint_optional (mpack_node_t node, uint64_t num)
 Returns the value node in the given map for the given unsigned integer key, or a missing node if the map does not contain the given key. More...
 
mpack_node_t mpack_node_map_str (mpack_node_t node, const char *str, size_t length)
 Returns the value node in the given map for the given string key. More...
 
mpack_node_t mpack_node_map_str_optional (mpack_node_t node, const char *str, size_t length)
 Returns the value node in the given map for the given string key, or a missing node if the map does not contain the given key. More...
 
mpack_node_t mpack_node_map_cstr (mpack_node_t node, const char *cstr)
 Returns the value node in the given map for the given null-terminated string key. More...
 
mpack_node_t mpack_node_map_cstr_optional (mpack_node_t node, const char *cstr)
 Returns the value node in the given map for the given null-terminated string key, or a missing node if the map does not contain the given key. More...
 
bool mpack_node_map_contains_int (mpack_node_t node, int64_t num)
 Returns true if the given node map contains exactly one entry with the given integer key. More...
 
bool mpack_node_map_contains_uint (mpack_node_t node, uint64_t num)
 Returns true if the given node map contains exactly one entry with the given unsigned integer key. More...
 
bool mpack_node_map_contains_str (mpack_node_t node, const char *str, size_t length)
 Returns true if the given node map contains exactly one entry with the given string key. More...
 
bool mpack_node_map_contains_cstr (mpack_node_t node, const char *cstr)
 Returns true if the given node map contains exactly one entry with the given null-terminated string key. More...
 

Tag Generators

#define MPACK_TAG_ZERO   {(mpack_type_t)0, {0}}
 An mpack_tag_t initializer that zeroes the given tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_nil (void)
 Generates a nil tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_bool (bool value)
 Generates a bool tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_true (void)
 Generates a bool tag with value true. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_false (void)
 Generates a bool tag with value false. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_int (int64_t value)
 Generates a signed int tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_uint (uint64_t value)
 Generates an unsigned int tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_float (float value)
 Generates a float tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_double (double value)
 Generates a double tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_array (uint32_t count)
 Generates an array tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_map (uint32_t count)
 Generates a map tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_str (uint32_t length)
 Generates a str tag. More...
 
MPACK_INLINE mpack_tag_t mpack_tag_make_bin (uint32_t length)
 Generates a bin tag. More...
 

Lifecycle Functions

#define mpack_reader_init_stack(reader)
 Initializes an MPack reader using stack space as a buffer. More...
 
void mpack_writer_init (mpack_writer_t *writer, char *buffer, size_t size)
 Initializes an MPack writer with the given buffer. More...
 
void mpack_writer_init_growable (mpack_writer_t *writer, char **data, size_t *size)
 Initializes an MPack writer using a growable buffer. More...
 
void mpack_writer_init_error (mpack_writer_t *writer, mpack_error_t error)
 Initializes an MPack writer directly into an error state. More...
 
void mpack_writer_init_filename (mpack_writer_t *writer, const char *filename)
 Initializes an MPack writer that writes to a file. More...
 
MPACK_INLINE void mpack_writer_init_file (mpack_writer_t *writer, const char *filename)
 Deprecated. More...
 
void mpack_writer_init_stdfile (mpack_writer_t *writer, FILE *stdfile, bool close_when_done)
 Initializes an MPack writer that writes to a libc FILE. More...
 
mpack_error_t mpack_writer_destroy (mpack_writer_t *writer)
 Cleans up the MPack writer, flushing and closing the underlying stream, if any. More...
 
void mpack_reader_init (mpack_reader_t *reader, char *buffer, size_t size, size_t count)
 Initializes an MPack reader with the given buffer. More...
 
void mpack_reader_init_error (mpack_reader_t *reader, mpack_error_t error)
 Initializes an MPack reader directly into an error state. More...
 
void mpack_reader_init_data (mpack_reader_t *reader, const char *data, size_t count)
 Initializes an MPack reader to parse a pre-loaded contiguous chunk of data. More...
 
void mpack_reader_init_filename (mpack_reader_t *reader, const char *filename)
 Initializes an MPack reader that reads from a file. More...
 
MPACK_INLINE void mpack_reader_init_file (mpack_reader_t *reader, const char *filename)
 Deprecated. More...
 
void mpack_reader_init_stdfile (mpack_reader_t *reader, FILE *stdfile, bool close_when_done)
 Initializes an MPack reader that reads from a libc FILE. More...
 
mpack_error_t mpack_reader_destroy (mpack_reader_t *reader)
 Cleans up the MPack reader, ensuring that all compound elements have been completely read. More...
 

Compound Types

#define mpack_expect_array_alloc(reader, Type, max_count, out_count)
 Reads the start of an array and allocates storage for it, placing its size in out_count. More...
 
#define mpack_expect_array_or_nil_alloc(reader, Type, max_count, out_count)
 Reads a nil node or the start of an array and allocates storage for it, placing its size in out_count. More...
 
uint32_t mpack_expect_map (mpack_reader_t *reader)
 Reads the start of a map, returning its element count. More...
 
uint32_t mpack_expect_map_range (mpack_reader_t *reader, uint32_t min_count, uint32_t max_count)
 Reads the start of a map with a number of elements in the given range, returning its element count. More...
 
MPACK_INLINE uint32_t mpack_expect_map_max (mpack_reader_t *reader, uint32_t max_count)
 Reads the start of a map with a number of elements at most max_count, returning its element count. More...
 
void mpack_expect_map_match (mpack_reader_t *reader, uint32_t count)
 Reads the start of a map of the exact size given. More...
 
bool mpack_expect_map_or_nil (mpack_reader_t *reader, uint32_t *count)
 Reads a nil node or the start of a map, returning whether a map was read and placing its number of key/value pairs in count. More...
 
bool mpack_expect_map_max_or_nil (mpack_reader_t *reader, uint32_t max_count, uint32_t *count)
 Reads a nil node or the start of a map with a number of elements at most max_count, returning whether a map was read and placing its number of key/value pairs in count. More...
 
uint32_t mpack_expect_array (mpack_reader_t *reader)
 Reads the start of an array, returning its element count. More...
 
uint32_t mpack_expect_array_range (mpack_reader_t *reader, uint32_t min_count, uint32_t max_count)
 Reads the start of an array with a number of elements in the given range, returning its element count. More...
 
MPACK_INLINE uint32_t mpack_expect_array_max (mpack_reader_t *reader, uint32_t max_count)
 Reads the start of an array with a number of elements at most max_count, returning its element count. More...
 
void mpack_expect_array_match (mpack_reader_t *reader, uint32_t count)
 Reads the start of an array of the exact size given. More...
 
bool mpack_expect_array_or_nil (mpack_reader_t *reader, uint32_t *count)
 Reads a nil node or the start of an array, returning whether an array was read and placing its number of elements in count. More...
 
bool mpack_expect_array_max_or_nil (mpack_reader_t *reader, uint32_t max_count, uint32_t *count)
 Reads a nil node or the start of an array with a number of elements at most max_count, returning whether an array was read and placing its number of key/value pairs in count. More...
 

Detailed Description

Abstracts all platform-specific code from MPack and handles configuration options.

Declares the MPack dynamic Node API.

Declares the MPack static Expect API.

Declares the core MPack Tag Reader.

Declares the MPack Writer.

Defines types and functions shared by the MPack reader and writer.

This verifies the configuration and sets defaults based on the platform, contains implementations of standard C functions when libc is not available, and provides wrappers to all library functions.

Documentation for configuration options is available here:

https://ludocode.github.io/mpack/group__config.html

Macro Definition Documentation

◆ MPACK_AMALGAMATED

#define MPACK_AMALGAMATED   1

The MIT License (MIT)

Copyright (c) 2015-2021 Nicholas Fraser and the MPack authors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

◆ MPACK_COMMON_H

#define MPACK_COMMON_H   1

◆ MPACK_EXPECT_H

#define MPACK_EXPECT_H   1

◆ MPACK_NODE_H

#define MPACK_NODE_H   1

◆ MPACK_PLATFORM_H

#define MPACK_PLATFORM_H   1

◆ MPACK_PRINT_BYTE_COUNT

#define MPACK_PRINT_BYTE_COUNT   12

◆ MPACK_READER_H

#define MPACK_READER_H   1

◆ MPACK_READER_SMALL_FRACTION_DENOMINATOR

#define MPACK_READER_SMALL_FRACTION_DENOMINATOR   32

◆ MPACK_WRITER_H

#define MPACK_WRITER_H   1