35#define MPACK_AMALGAMATED 1
37#if defined(MPACK_HAS_CONFIG) && MPACK_HAS_CONFIG
38#include "mpack-config.h"
59#ifndef MPACK_PLATFORM_H
60#define MPACK_PLATFORM_H 1
106#if defined(_MSC_VER) && _MSC_VER < 1800 && !defined(__cplusplus)
107 #error "In Visual Studio 2012 and earlier, MPack must be compiled as C++. Enable the /Tp compiler flag."
110#if defined(_WIN32) && MPACK_INTERNAL
111 #define _CRT_SECURE_NO_WARNINGS 1
114#ifndef __STDC_LIMIT_MACROS
115 #define __STDC_LIMIT_MACROS 1
117#ifndef __STDC_FORMAT_MACROS
118 #define __STDC_FORMAT_MACROS 1
120#ifndef __STDC_CONSTANT_MACROS
121 #define __STDC_CONSTANT_MACROS 1
142#if defined(MPACK_HAS_CONFIG)
144 #include "mpack-config.h"
147 #define MPACK_HAS_CONFIG 0
156#ifndef MPACK_NO_BUILTINS
157 #define MPACK_NO_BUILTINS 0
174#define MPACK_READER 1
183#define MPACK_EXPECT 1
201#define MPACK_WRITER 1
236#ifndef MPACK_COMPATIBILITY
237#define MPACK_COMPATIBILITY 0
252#ifndef MPACK_EXTENSIONS
253#define MPACK_EXTENSIONS 0
263#if defined(MPACK_DOXYGEN)
270#define MPACK_COMPATIBILITY 0
271#define MPACK_EXTENSIONS 0
304#ifndef MPACK_CONFORMING
305 #define MPACK_CONFORMING 1
332 #if !MPACK_CONFORMING
335 #define MPACK_STDLIB 0
337 #define MPACK_STDLIB 1
348 #if !MPACK_STDLIB || defined(__AVR__)
349 #define MPACK_STDIO 0
351 #define MPACK_STDIO 1
363 #define MPACK_FLOAT 1
378 #if !MPACK_FLOAT || defined(__AVR__)
380 #define MPACK_DOUBLE 0
382 #define MPACK_DOUBLE 1
452#if defined(MPACK_MALLOC) && !defined(MPACK_FREE)
453 #error "MPACK_MALLOC requires MPACK_FREE."
455#if !defined(MPACK_MALLOC) && defined(MPACK_FREE)
456 #error "MPACK_FREE requires MPACK_MALLOC."
461 #error "Define MPACK_MALLOC, not mpack_malloc."
464 #error "Define MPACK_REALLOC, not mpack_realloc."
467 #error "Define MPACK_FREE, not mpack_free."
472 #error "Don't define MPACK_CALLOC. MPack does not use calloc()."
475 #error "Don't define mpack_calloc. MPack does not use calloc()."
479#if defined(MPACK_STDLIB)
480 #if MPACK_STDLIB && !defined(MPACK_MALLOC)
481 #define MPACK_MALLOC malloc
482 #define MPACK_REALLOC realloc
483 #define MPACK_FREE free
495 #if defined(MPACK_MALLOC) && MPACK_WRITER
496 #define MPACK_BUILDER 1
498 #define MPACK_BUILDER 0
573 #error "Define MPACK_MEMCMP, not mpack_memcmp."
576 #error "Define MPACK_MEMCPY, not mpack_memcpy."
579 #error "Define MPACK_MEMMOVE, not mpack_memmove."
582 #error "Define MPACK_MEMSET, not mpack_memset."
585 #error "Define MPACK_STRLEN, not mpack_strlen."
591 #define MPACK_MEMCMP memcmp
594 #define MPACK_MEMCPY memcpy
596 #ifndef MPACK_MEMMOVE
597 #define MPACK_MEMMOVE memmove
600 #define MPACK_MEMSET memset
603 #define MPACK_STRLEN strlen
607#if !MPACK_NO_BUILTINS
609 #if !defined(MPACK_MEMCMP) && __has_builtin(__builtin_memcmp)
610 #define MPACK_MEMCMP __builtin_memcmp
612 #if !defined(MPACK_MEMCPY) && __has_builtin(__builtin_memcpy)
613 #define MPACK_MEMCPY __builtin_memcpy
615 #if !defined(MPACK_MEMMOVE) && __has_builtin(__builtin_memmove)
616 #define MPACK_MEMMOVE __builtin_memmove
618 #if !defined(MPACK_MEMSET) && __has_builtin(__builtin_memset)
619 #define MPACK_MEMSET __builtin_memset
621 #if !defined(MPACK_STRLEN) && __has_builtin(__builtin_strlen)
622 #define MPACK_STRLEN __builtin_strlen
624 #elif defined(__GNUC__)
626 #define MPACK_MEMCMP __builtin_memcmp
629 #define MPACK_MEMCPY __builtin_memcpy
636 #define MPACK_MEMSET __builtin_memset
639 #define MPACK_STRLEN __builtin_strlen
663#if !defined(MPACK_DEBUG)
664 #if defined(DEBUG) || defined(_DEBUG)
665 #define MPACK_DEBUG 1
667 #define MPACK_DEBUG 0
682 #define MPACK_STRINGS 0
684 #define MPACK_STRINGS 1
695#ifndef MPACK_CUSTOM_ASSERT
696#define MPACK_CUSTOM_ASSERT 0
708#if !defined(MPACK_READ_TRACKING)
709 #if MPACK_DEBUG && MPACK_READER && defined(MPACK_MALLOC)
710 #define MPACK_READ_TRACKING 1
712 #define MPACK_READ_TRACKING 0
715#if MPACK_READ_TRACKING && !MPACK_READER
716 #error "MPACK_READ_TRACKING requires MPACK_READER."
733#if !defined(MPACK_WRITE_TRACKING)
734 #if MPACK_DEBUG && MPACK_WRITER && defined(MPACK_MALLOC)
735 #define MPACK_WRITE_TRACKING 1
737 #define MPACK_WRITE_TRACKING 0
740#if MPACK_WRITE_TRACKING && !MPACK_WRITER
741 #error "MPACK_WRITE_TRACKING requires MPACK_WRITER."
766#ifndef MPACK_OPTIMIZE_FOR_SIZE
767 #ifdef __OPTIMIZE_SIZE__
768 #define MPACK_OPTIMIZE_FOR_SIZE 1
770 #define MPACK_OPTIMIZE_FOR_SIZE 0
781#ifndef MPACK_STACK_SIZE
782#define MPACK_STACK_SIZE 4096
793#ifndef MPACK_BUFFER_SIZE
794#define MPACK_BUFFER_SIZE 4096
803#ifndef MPACK_PAGE_SIZE
804#define MPACK_PAGE_SIZE 4096
820#ifndef MPACK_NODE_PAGE_SIZE
821#define MPACK_NODE_PAGE_SIZE MPACK_PAGE_SIZE
830#ifndef MPACK_BUILDER_PAGE_SIZE
831#define MPACK_BUILDER_PAGE_SIZE MPACK_PAGE_SIZE
845#ifndef MPACK_BUILDER_INTERNAL_STORAGE
846#define MPACK_BUILDER_INTERNAL_STORAGE 0
867#ifndef MPACK_BUILDER_INTERNAL_STORAGE_SIZE
868#define MPACK_BUILDER_INTERNAL_STORAGE_SIZE 256
876#ifndef MPACK_NODE_INITIAL_DEPTH
877#define MPACK_NODE_INITIAL_DEPTH 8
883#ifndef MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC
884#define MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC 32
896#if defined(MPACK_DOXYGEN)
898 #define MPACK_NO_BUILTINS 0
925void mpack_assert_fail(
const char* message);
945#ifndef MPACK_CUSTOM_BREAK
946#define MPACK_CUSTOM_BREAK 0
948#ifndef MPACK_EMIT_INLINE_DEFS
949#define MPACK_EMIT_INLINE_DEFS 0
951#ifndef MPACK_AMALGAMATED
952#define MPACK_AMALGAMATED 0
954#ifndef MPACK_RELEASE_VERSION
955#define MPACK_RELEASE_VERSION 0
957#ifndef MPACK_INTERNAL
958#define MPACK_INTERNAL 0
969 #include <inttypes.h>
993 #define MPACK_INT64_C INT64_C
994 #define MPACK_UINT64_C UINT64_C
996 #define MPACK_INT8_MIN INT8_MIN
997 #define MPACK_INT16_MIN INT16_MIN
998 #define MPACK_INT32_MIN INT32_MIN
999 #define MPACK_INT64_MIN INT64_MIN
1000 #define MPACK_INT_MIN INT_MIN
1002 #define MPACK_INT8_MAX INT8_MAX
1003 #define MPACK_INT16_MAX INT16_MAX
1004 #define MPACK_INT32_MAX INT32_MAX
1005 #define MPACK_INT64_MAX INT64_MAX
1006 #define MPACK_INT_MAX INT_MAX
1008 #define MPACK_UINT8_MAX UINT8_MAX
1009 #define MPACK_UINT16_MAX UINT16_MAX
1010 #define MPACK_UINT32_MAX UINT32_MAX
1011 #define MPACK_UINT64_MAX UINT64_MAX
1012 #define MPACK_UINT_MAX UINT_MAX
1016 #define MPACK_INT64_C(x) ((int64_t)(x##LL))
1017 #define MPACK_UINT64_C(x) ((uint64_t)(x##LLU))
1019 #define MPACK_INT8_MIN ((int8_t)(0x80))
1020 #define MPACK_INT16_MIN ((int16_t)(0x8000))
1021 #define MPACK_INT32_MIN ((int32_t)(0x80000000))
1022 #define MPACK_INT64_MIN MPACK_INT64_C(0x8000000000000000)
1023 #define MPACK_INT_MIN MPACK_INT32_MIN
1025 #define MPACK_INT8_MAX ((int8_t)(0x7f))
1026 #define MPACK_INT16_MAX ((int16_t)(0x7fff))
1027 #define MPACK_INT32_MAX ((int32_t)(0x7fffffff))
1028 #define MPACK_INT64_MAX MPACK_INT64_C(0x7fffffffffffffff)
1029 #define MPACK_INT_MAX MPACK_INT32_MAX
1031 #define MPACK_UINT8_MAX ((uint8_t)(0xffu))
1032 #define MPACK_UINT16_MAX ((uint16_t)(0xffffu))
1033 #define MPACK_UINT32_MAX ((uint32_t)(0xffffffffu))
1034 #define MPACK_UINT64_MAX MPACK_UINT64_C(0xffffffffffffffff)
1035 #define MPACK_UINT_MAX MPACK_UINT32_MAX
1044#if MPACK_DOUBLE && !MPACK_FLOAT
1045 #error "MPACK_DOUBLE requires MPACK_FLOAT."
1053 #pragma GCC poison float
1056 #pragma GCC poison double
1068 #define MPACK_EXTERN_C_BEGIN namespace mpack {
1069 #define MPACK_EXTERN_C_END }
1071 #define MPACK_EXTERN_C_BEGIN
1072 #define MPACK_EXTERN_C_END
1081#if defined(__GNUC__)
1083 #if defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1084 #define MPACK_SILENCE_WARNINGS_PUSH _Pragma ("GCC diagnostic push")
1085 #define MPACK_SILENCE_WARNINGS_POP _Pragma ("GCC diagnostic pop")
1087#elif defined(_MSC_VER)
1089 #define MPACK_SILENCE_WARNINGS_PUSH __pragma(warning(push))
1090 #define MPACK_SILENCE_WARNINGS_POP __pragma(warning(pop))
1093#if defined(_MSC_VER)
1096 #define MPACK_SILENCE_WARNINGS_MSVC_W4 \
1097 __pragma(warning(disable:4996)) \
1098 __pragma(warning(disable:4127)) \
1099 __pragma(warning(disable:4702)) \
1100 __pragma(warning(disable:4310))
1102 #define MPACK_SILENCE_WARNINGS_MSVC_W4
1107#if defined(__GNUC__) && !defined(__clang__)
1108 #if __GNUC__ < 5 || (__GNUC__ == 5 && __GNUC_MINOR__ < 1)
1110 #define MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES \
1111 _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"")
1113 #define MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES \
1114 _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"")
1118#ifndef MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES
1119 #define MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES
1124#if defined(__GNUC__) && !defined(__clang__)
1125 #if __GNUC__ == 4 && __GNUC_MINOR__ < 8
1126 #define MPACK_SILENCE_WARNINGS_SHADOW \
1127 _Pragma ("GCC diagnostic ignored \"-Wshadow\"")
1130#ifndef MPACK_SILENCE_WARNINGS_SHADOW
1131 #define MPACK_SILENCE_WARNINGS_SHADOW
1137 #define MPACK_SILENCE_WARNINGS_TYPE_LIMITS \
1138 _Pragma ("GCC diagnostic ignored \"-Wtype-limits\"")
1140 #define MPACK_SILENCE_WARNINGS_TYPE_LIMITS
1145#if defined(__GNUC__) && !defined(__cplusplus)
1146 #define MPACK_SILENCE_WARNINGS_DECLARATION_AFTER_STATEMENT \
1147 _Pragma ("GCC diagnostic ignored \"-Wdeclaration-after-statement\"")
1149 #define MPACK_SILENCE_WARNINGS_DECLARATION_AFTER_STATEMENT
1152#ifdef MPACK_SILENCE_WARNINGS_PUSH
1158 #define MPACK_SILENCE_WARNINGS_BEGIN \
1159 MPACK_SILENCE_WARNINGS_PUSH \
1160 MPACK_SILENCE_WARNINGS_MSVC_W4 \
1161 MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES \
1162 MPACK_SILENCE_WARNINGS_SHADOW \
1163 MPACK_SILENCE_WARNINGS_TYPE_LIMITS \
1164 MPACK_SILENCE_WARNINGS_DECLARATION_AFTER_STATEMENT
1166 #define MPACK_SILENCE_WARNINGS_END \
1167 MPACK_SILENCE_WARNINGS_POP
1169 #define MPACK_SILENCE_WARNINGS_BEGIN
1170 #define MPACK_SILENCE_WARNINGS_END
1173MPACK_SILENCE_WARNINGS_BEGIN
1180#define MPACK_UNUSED(var) ((void)(var))
1182#define MPACK_STRINGIFY_IMPL(arg) #arg
1183#define MPACK_STRINGIFY(arg) MPACK_STRINGIFY_IMPL(arg)
1192#define MPACK_EXPAND(x) x
1196#define MPACK_EXTRACT_ARG0_IMPL(first, ...) first
1197#define MPACK_EXTRACT_ARG0(...) MPACK_EXPAND(MPACK_EXTRACT_ARG0_IMPL( __VA_ARGS__ , ignored))
1201#define MPACK_STRINGIFY_ARG0_impl(first, ...) #first
1202#define MPACK_STRINGIFY_ARG0(...) MPACK_EXPAND(MPACK_STRINGIFY_ARG0_impl( __VA_ARGS__ , ignored))
1239#if defined(__cplusplus)
1247 #define MPACK_INLINE inline
1249#elif defined(_MSC_VER)
1253 #define MPACK_INLINE __inline
1254 #define MPACK_STATIC_INLINE static __inline
1256#elif defined(__GNUC__) && (defined(__GNUC_GNU_INLINE__) || \
1257 (!defined(__GNUC_STDC_INLINE__) && !defined(__GNUC_GNU_INLINE__)))
1259 #if MPACK_EMIT_INLINE_DEFS
1260 #define MPACK_INLINE inline
1262 #define MPACK_INLINE extern inline
1265#elif defined(__TINYC__)
1270 #ifndef MPACK_DISABLE_TINYC_INLINE_WARNING
1271 #warning "Single-definition inline is not supported by tcc. All inlines will be static. Define MPACK_DISABLE_TINYC_INLINE_WARNING to disable this warning."
1273 #define MPACK_INLINE static inline
1277 #if MPACK_EMIT_INLINE_DEFS
1278 #define MPACK_INLINE extern inline
1280 #define MPACK_INLINE inline
1284#ifndef MPACK_STATIC_INLINE
1285#define MPACK_STATIC_INLINE static inline
1288#ifdef MPACK_OPTIMIZE_FOR_SPEED
1289 #error "You should define MPACK_OPTIMIZE_FOR_SIZE, not MPACK_OPTIMIZE_FOR_SPEED."
1303#if !MPACK_NO_BUILTINS
1304 #if defined(_MSC_VER)
1305 #define MPACK_NOINLINE __declspec(noinline)
1306 #elif defined(__GNUC__) || defined(__clang__)
1307 #define MPACK_NOINLINE __attribute__((__noinline__))
1310#ifndef MPACK_NOINLINE
1311 #define MPACK_NOINLINE
1322#if !MPACK_NO_BUILTINS
1323 #if defined(__GNUC__)
1324 #define MPACK_RESTRICT __restrict__
1325 #elif defined(_MSC_VER)
1326 #define MPACK_RESTRICT __restrict
1330#ifndef MPACK_RESTRICT
1332 #define MPACK_RESTRICT
1336#ifndef MPACK_RESTRICT
1342 #define MPACK_RESTRICT
1347#ifndef MPACK_RESTRICT
1348 #define MPACK_RESTRICT restrict
1355#if !MPACK_NO_BUILTINS
1356 #if defined(__GNUC__) || defined(__clang__)
1357 #define MPACK_UNREACHABLE __builtin_unreachable()
1358 #define MPACK_NORETURN(fn) fn __attribute__((__noreturn__))
1359 #elif defined(_MSC_VER)
1360 #define MPACK_UNREACHABLE __assume(0)
1361 #define MPACK_NORETURN(fn) __declspec(noreturn) fn
1365#ifndef MPACK_UNREACHABLE
1366#define MPACK_UNREACHABLE ((void)0)
1368#ifndef MPACK_NORETURN
1369#define MPACK_NORETURN(fn) fn
1382#if !MPACK_NO_BUILTINS
1383 #if defined(__GNUC__) || defined(__clang__)
1384 #ifndef MPACK_LIKELY
1385 #define MPACK_LIKELY(x) __builtin_expect((x),1)
1387 #ifndef MPACK_UNLIKELY
1388 #define MPACK_UNLIKELY(x) __builtin_expect((x),0)
1394 #define MPACK_LIKELY(x) (x)
1396#ifndef MPACK_UNLIKELY
1397 #define MPACK_UNLIKELY(x) (x)
1404#ifndef MPACK_ALIGNOF
1405 #if defined(__STDC_VERSION__)
1406 #if __STDC_VERSION__ >= 201112L
1407 #define MPACK_ALIGNOF(T) (_Alignof(T))
1412#ifndef MPACK_ALIGNOF
1413 #if defined(__cplusplus)
1414 #if __cplusplus >= 201103L
1415 #define MPACK_ALIGNOF(T) (alignof(T))
1420#ifndef MPACK_ALIGNOF
1421 #if defined(__GNUC__) && !defined(MPACK_NO_BUILTINS)
1422 #if defined(__clang__) || __GNUC__ >= 4
1423 #define MPACK_ALIGNOF(T) (__alignof__(T))
1428#ifndef MPACK_ALIGNOF
1430 #define MPACK_ALIGNOF(T) __alignof(T)
1440#ifndef MPACK_STATIC_ASSERT
1441 #if defined(__cplusplus)
1442 #if __cplusplus >= 201103L
1443 #define MPACK_STATIC_ASSERT static_assert
1445 #elif defined(__STDC_VERSION__)
1446 #if __STDC_VERSION__ >= 201112L
1447 #define MPACK_STATIC_ASSERT _Static_assert
1452#if !MPACK_NO_BUILTINS
1453 #ifndef MPACK_STATIC_ASSERT
1454 #if defined(__has_feature)
1455 #if __has_feature(cxx_static_assert)
1456 #define MPACK_STATIC_ASSERT static_assert
1457 #elif __has_feature(c_static_assert)
1458 #define MPACK_STATIC_ASSERT _Static_assert
1463 #ifndef MPACK_STATIC_ASSERT
1464 #if defined(__GNUC__)
1466 #if defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1468 #if defined(__clang__) || __GNUC__ >= 5
1469 #define MPACK_IGNORE_PEDANTIC "GCC diagnostic ignored \"-Wpedantic\""
1471 #define MPACK_IGNORE_PEDANTIC "GCC diagnostic ignored \"-pedantic\""
1473 #define MPACK_STATIC_ASSERT(expr, str) do { \
1474 _Pragma ("GCC diagnostic push") \
1475 _Pragma (MPACK_IGNORE_PEDANTIC) \
1476 _Pragma ("GCC diagnostic ignored \"-Wc++-compat\"") \
1477 _Static_assert(expr, str); \
1478 _Pragma ("GCC diagnostic pop") \
1485 #ifndef MPACK_STATIC_ASSERT
1487 #if _MSC_VER >= 1600
1488 #define MPACK_STATIC_ASSERT static_assert
1494#ifndef MPACK_STATIC_ASSERT
1495 #define MPACK_STATIC_ASSERT(expr, str) (MPACK_UNUSED(sizeof(char[1 - 2*!(expr)])))
1502#ifndef MPACK_HAS_GENERIC
1503 #if defined(__clang__) && defined(__has_feature)
1506 #if __has_feature(c_generic_selections)
1507 #define MPACK_HAS_GENERIC 1
1509 #define MPACK_HAS_GENERIC 0
1514#ifndef MPACK_HAS_GENERIC
1515 #if defined(__STDC_VERSION__)
1516 #if __STDC_VERSION__ >= 201112L
1517 #if defined(__GNUC__) && !defined(__clang__)
1519 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
1520 #define MPACK_HAS_GENERIC 1
1524 #define MPACK_HAS_GENERIC 1
1530#ifndef MPACK_HAS_GENERIC
1531 #define MPACK_HAS_GENERIC 0
1546#ifndef MPACK_FINITE_MATH
1547#if defined(__FINITE_MATH_ONLY__) && __FINITE_MATH_ONLY__
1548#define MPACK_FINITE_MATH 1
1552#ifndef MPACK_FINITE_MATH
1553#define MPACK_FINITE_MATH 0
1570#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
1571 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1572 #define MPACK_NHSWAP16(x) (x)
1573 #define MPACK_NHSWAP32(x) (x)
1574 #define MPACK_NHSWAP64(x) (x)
1575 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1577 #if !MPACK_NO_BUILTINS
1578 #if defined(__clang__)
1579 #ifdef __has_builtin
1582 #if __has_builtin(__builtin_bswap16)
1583 #define MPACK_NHSWAP16(x) __builtin_bswap16(x)
1585 #if __has_builtin(__builtin_bswap32)
1586 #define MPACK_NHSWAP32(x) __builtin_bswap32(x)
1588 #if __has_builtin(__builtin_bswap64)
1589 #define MPACK_NHSWAP64(x) __builtin_bswap64(x)
1593 #elif defined(__GNUC__)
1599 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
1600 #define MPACK_NHSWAP64(x) __builtin_bswap64(x)
1614#elif defined(_MSC_VER) && defined(_WIN32) && MPACK_STDLIB && !MPACK_NO_BUILTINS
1625 #if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64)
1626 #define MPACK_NHSWAP16(x) _byteswap_ushort(x)
1627 #define MPACK_NHSWAP32(x) _byteswap_ulong(x)
1628 #define MPACK_NHSWAP64(x) _byteswap_uint64(x)
1633#if defined(__FLOAT_WORD_ORDER__) && defined(__BYTE_ORDER__)
1643 #define MPACK_CHECK_FLOAT_ORDER() \
1644 MPACK_STATIC_ASSERT(__FLOAT_WORD_ORDER__ == __BYTE_ORDER__, \
1645 "float byte order does not match int byte order! float/double " \
1646 "encoding is not properly implemented on this platform.")
1650#ifndef MPACK_CHECK_FLOAT_ORDER
1651 #define MPACK_CHECK_FLOAT_ORDER()
1690 MPACK_NORETURN(
void mpack_assert_fail_wrapper(
const char* message));
1692 MPACK_NORETURN(
void mpack_assert_fail_format(
const char*
format, ...));
1693 #define mpack_assert_fail_at(line, file, exprstr, format, ...) \
1694 MPACK_EXPAND(mpack_assert_fail_format("mpack assertion failed at " file ":" #line "\n%s\n" format, exprstr, __VA_ARGS__))
1696 #define mpack_assert_fail_at(line, file, exprstr, format, ...) \
1697 mpack_assert_fail_wrapper("mpack assertion failed at " file ":" #line "\n" exprstr "\n")
1700 #define mpack_assert_fail_pos(line, file, exprstr, expr, ...) \
1701 MPACK_EXPAND(mpack_assert_fail_at(line, file, exprstr, __VA_ARGS__))
1716 #define mpack_assert(...) \
1717 MPACK_EXPAND(((!(MPACK_EXTRACT_ARG0(__VA_ARGS__))) ? \
1718 mpack_assert_fail_pos(__LINE__, __FILE__, MPACK_STRINGIFY_ARG0(__VA_ARGS__) , __VA_ARGS__ , "", NULL) : \
1721 void mpack_break_hit(
const char* message);
1723 void mpack_break_hit_format(
const char*
format, ...);
1724 #define mpack_break_hit_at(line, file, ...) \
1725 MPACK_EXPAND(mpack_break_hit_format("mpack breakpoint hit at " file ":" #line "\n" __VA_ARGS__))
1727 #define mpack_break_hit_at(line, file, ...) \
1728 mpack_break_hit("mpack breakpoint hit at " file ":" #line )
1730 #define mpack_break_hit_pos(line, file, ...) MPACK_EXPAND(mpack_break_hit_at(line, file, __VA_ARGS__))
1731 #define mpack_break(...) MPACK_EXPAND(mpack_break_hit_pos(__LINE__, __FILE__, __VA_ARGS__))
1733 #define mpack_assert(...) \
1734 (MPACK_EXPAND((!(MPACK_EXTRACT_ARG0(__VA_ARGS__))) ? \
1735 (MPACK_UNREACHABLE, (void)0) : \
1737 #define mpack_break(...) ((void)0)
1743#if MPACK_STDLIB && defined(MPACK_UNIT_TESTS) && MPACK_INTERNAL && defined(__GNUC__)
1753 #pragma GCC poison memcmp
1754 #pragma GCC poison memcpy
1755 #pragma GCC poison memmove
1756 #pragma GCC poison memset
1757 #pragma GCC poison strlen
1758 #pragma GCC poison malloc
1759 #pragma GCC poison calloc
1760 #pragma GCC poison realloc
1761 #pragma GCC poison free
1770 #define mpack_memcmp MPACK_MEMCMP
1772 int mpack_memcmp(
const void* s1,
const void* s2,
size_t n);
1776 #define mpack_memcpy MPACK_MEMCPY
1778 void* mpack_memcpy(
void* MPACK_RESTRICT s1,
const void* MPACK_RESTRICT s2,
size_t n);
1782 #define mpack_memmove MPACK_MEMMOVE
1784 void* mpack_memmove(
void* s1,
const void* s2,
size_t n);
1788 #define mpack_memset MPACK_MEMSET
1790 void* mpack_memset(
void* s,
int c,
size_t n);
1794 #define mpack_strlen MPACK_STRLEN
1796 size_t mpack_strlen(
const char* s);
1803 #define mpack_snprintf _snprintf
1805 #define mpack_snprintf snprintf
1814 #define mpack_log(...) (MPACK_EXPAND(printf(__VA_ARGS__)), fflush(stdout))
1816 #define mpack_log(...) ((void)0)
1824 #error "MPACK_STDIO requires preprocessor definitions for MPACK_MALLOC and MPACK_FREE."
1826 #if MPACK_READ_TRACKING
1827 #error "MPACK_READ_TRACKING requires preprocessor definitions for MPACK_MALLOC and MPACK_FREE."
1829 #if MPACK_WRITE_TRACKING
1830 #error "MPACK_WRITE_TRACKING requires preprocessor definitions for MPACK_MALLOC and MPACK_FREE."
1838 #ifdef MPACK_REALLOC
1839 MPACK_INLINE
void* mpack_realloc(
void* old_ptr,
size_t used_size,
size_t new_size) {
1840 MPACK_UNUSED(used_size);
1844 void* mpack_realloc(
void* old_ptr,
size_t used_size,
size_t new_size);
1856MPACK_SILENCE_WARNINGS_END
1868#ifndef MPACK_COMMON_H
1869#define MPACK_COMMON_H 1
1873#ifndef MPACK_PRINT_BYTE_COUNT
1874#define MPACK_PRINT_BYTE_COUNT 12
1877MPACK_SILENCE_WARNINGS_BEGIN
1893#define MPACK_VERSION_MAJOR 1
1894#define MPACK_VERSION_MINOR 1
1895#define MPACK_VERSION_PATCH 0
1898#define MPACK_VERSION ((MPACK_VERSION_MAJOR * 10000) + \
1899 (MPACK_VERSION_MINOR * 100) + MPACK_VERSION_PATCH)
1902#define MPACK_VERSION_AT_LEAST(major, minor, patch) \
1903 (MPACK_VERSION >= (((major) * 10000) + ((minor) * 100) + (patch)))
1906#if (MPACK_VERSION_PATCH > 0)
1907#define MPACK_VERSION_STRING_BASE \
1908 MPACK_STRINGIFY(MPACK_VERSION_MAJOR) "." \
1909 MPACK_STRINGIFY(MPACK_VERSION_MINOR) "." \
1910 MPACK_STRINGIFY(MPACK_VERSION_PATCH)
1912#define MPACK_VERSION_STRING_BASE \
1913 MPACK_STRINGIFY(MPACK_VERSION_MAJOR) "." \
1914 MPACK_STRINGIFY(MPACK_VERSION_MINOR)
1924#if MPACK_RELEASE_VERSION
1925#define MPACK_VERSION_STRING MPACK_VERSION_STRING_BASE
1927#define MPACK_VERSION_STRING MPACK_VERSION_STRING_BASE "dev"
1937#define MPACK_LIBRARY_STRING "MPack " MPACK_VERSION_STRING "-debug"
1939#define MPACK_LIBRARY_STRING "MPack " MPACK_VERSION_STRING
1948#define MPACK_MAXIMUM_TAG_SIZE 9
1959#define MPACK_TIMESTAMP_NANOSECONDS_MAX 999999999
1964#if MPACK_COMPATIBILITY
1974typedef enum mpack_version_t {
1979 mpack_version_v4 = 4,
1984 mpack_version_v5 = 5,
1989 mpack_version_current = mpack_version_v5,
2040 #if MPACK_EXTENSIONS
2062typedef struct mpack_timestamp_t {
2087 #if MPACK_EXTENSIONS
2133#define MPACK_TAG_ZERO {(mpack_type_t)0, 0, {0}}
2135#define MPACK_TAG_ZERO {(mpack_type_t)0, {0}}
2253 ret.type = mpack_type_ext;
2254 ret.exttype = exttype;
2432 mpack_assert(tag->type == mpack_type_ext,
"tag is not an ext!");
2447 mpack_assert(tag->type == mpack_type_ext,
"tag is not an ext!");
2448 return tag->exttype;
2464 #if MPACK_EXTENSIONS
2466 || tag->type == mpack_type_ext,
"tag is not a str, bin or ext!");
2469 "tag is not a str or bin!");
2489#define MPACK_EXTTYPE_TIMESTAMP ((int8_t)(-1))
2528#if MPACK_DEBUG && MPACK_STDIO
2538void mpack_tag_debug_pseudo_json(
mpack_tag_t tag,
char*
buffer,
size_t buffer_size,
2539 const char* prefix,
size_t prefix_size);
2547void mpack_tag_debug_describe(
mpack_tag_t tag,
char*
buffer,
size_t buffer_size);
2556typedef void (*mpack_print_callback_t)(
void* context,
const char*
data,
size_t count);
2560typedef struct mpack_print_t {
2564 mpack_print_callback_t callback;
2568void mpack_print_append(mpack_print_t*
print,
const char*
data,
size_t count);
2570MPACK_INLINE
void mpack_print_append_cstr(mpack_print_t*
print,
const char* cstr) {
2571 mpack_print_append(
print, cstr, mpack_strlen(cstr));
2574void mpack_print_flush(mpack_print_t*
print);
2576void mpack_print_file_callback(
void* context,
const char*
data,
size_t count);
2668 return mpack_tag_make_ext(exttype, (
uint32_t)length);
2687MPACK_INLINE
uint8_t mpack_load_u8(
const char* p) {
2691MPACK_INLINE
uint16_t mpack_load_u16(
const char* p) {
2692 #ifdef MPACK_NHSWAP16
2694 mpack_memcpy(&val, p,
sizeof(val));
2695 return MPACK_NHSWAP16(val);
2702MPACK_INLINE
uint32_t mpack_load_u32(
const char* p) {
2703 #ifdef MPACK_NHSWAP32
2705 mpack_memcpy(&val, p,
sizeof(val));
2706 return MPACK_NHSWAP32(val);
2715MPACK_INLINE
uint64_t mpack_load_u64(
const char* p) {
2716 #ifdef MPACK_NHSWAP64
2718 mpack_memcpy(&val, p,
sizeof(val));
2719 return MPACK_NHSWAP64(val);
2732MPACK_INLINE
void mpack_store_u8(
char* p,
uint8_t val) {
2737MPACK_INLINE
void mpack_store_u16(
char* p,
uint16_t val) {
2738 #ifdef MPACK_NHSWAP16
2739 val = MPACK_NHSWAP16(val);
2740 mpack_memcpy(p, &val,
sizeof(val));
2743 u[0] = (
uint8_t)((val >> 8) & 0xFF);
2744 u[1] = (
uint8_t)( val & 0xFF);
2748MPACK_INLINE
void mpack_store_u32(
char* p,
uint32_t val) {
2749 #ifdef MPACK_NHSWAP32
2750 val = MPACK_NHSWAP32(val);
2751 mpack_memcpy(p, &val,
sizeof(val));
2754 u[0] = (
uint8_t)((val >> 24) & 0xFF);
2755 u[1] = (
uint8_t)((val >> 16) & 0xFF);
2756 u[2] = (
uint8_t)((val >> 8) & 0xFF);
2757 u[3] = (
uint8_t)( val & 0xFF);
2761MPACK_INLINE
void mpack_store_u64(
char* p,
uint64_t val) {
2762 #ifdef MPACK_NHSWAP64
2763 val = MPACK_NHSWAP64(val);
2764 mpack_memcpy(p, &val,
sizeof(val));
2767 u[0] = (
uint8_t)((val >> 56) & 0xFF);
2768 u[1] = (
uint8_t)((val >> 48) & 0xFF);
2769 u[2] = (
uint8_t)((val >> 40) & 0xFF);
2770 u[3] = (
uint8_t)((val >> 32) & 0xFF);
2771 u[4] = (
uint8_t)((val >> 24) & 0xFF);
2772 u[5] = (
uint8_t)((val >> 16) & 0xFF);
2773 u[6] = (
uint8_t)((val >> 8) & 0xFF);
2774 u[7] = (
uint8_t)( val & 0xFF);
2778MPACK_INLINE
int8_t mpack_load_i8 (
const char* p) {
return (
int8_t) mpack_load_u8 (p);}
2779MPACK_INLINE
int16_t mpack_load_i16(
const char* p) {
return (
int16_t)mpack_load_u16(p);}
2780MPACK_INLINE
int32_t mpack_load_i32(
const char* p) {
return (
int32_t)mpack_load_u32(p);}
2781MPACK_INLINE
int64_t mpack_load_i64(
const char* p) {
return (
int64_t)mpack_load_u64(p);}
2782MPACK_INLINE
void mpack_store_i8 (
char* p,
int8_t val) {mpack_store_u8 (p, (
uint8_t) val);}
2783MPACK_INLINE
void mpack_store_i16(
char* p,
int16_t val) {mpack_store_u16(p, (
uint16_t)val);}
2784MPACK_INLINE
void mpack_store_i32(
char* p,
int32_t val) {mpack_store_u32(p, (
uint32_t)val);}
2785MPACK_INLINE
void mpack_store_i64(
char* p,
int64_t val) {mpack_store_u64(p, (
uint64_t)val);}
2788MPACK_INLINE
float mpack_load_float(
const char* p) {
2789 MPACK_CHECK_FLOAT_ORDER();
2790 MPACK_STATIC_ASSERT(
sizeof(
float) ==
sizeof(
uint32_t),
"float is wrong size??");
2795 v.u = mpack_load_u32(p);
2801MPACK_INLINE
double mpack_load_double(
const char* p) {
2802 MPACK_CHECK_FLOAT_ORDER();
2803 MPACK_STATIC_ASSERT(
sizeof(
double) ==
sizeof(
uint64_t),
"double is wrong size??");
2808 v.u = mpack_load_u64(p);
2814MPACK_INLINE
void mpack_store_float(
char* p,
float value) {
2815 MPACK_CHECK_FLOAT_ORDER();
2821 mpack_store_u32(p, v.u);
2826MPACK_INLINE
void mpack_store_double(
char* p,
double value) {
2827 MPACK_CHECK_FLOAT_ORDER();
2833 mpack_store_u64(p, v.u);
2837#if MPACK_FLOAT && !MPACK_DOUBLE
2847MPACK_INLINE
float mpack_shorten_raw_double_to_float(
uint64_t d) {
2848 MPACK_CHECK_FLOAT_ORDER();
2865 if (MPACK_UNLIKELY(d_exponent == ((1 << 11) - 1))) {
2869 f_exponent = ((1 << 8) - 1);
2870 f_significand = (
uint32_t)(d_significand >> 29) | (d_significand ? 1 : 0);
2873 int fix_bias = (int)d_exponent - ((1 << 10) - 1) + ((1 << 7) - 1);
2874 if (MPACK_UNLIKELY(fix_bias <= 0)) {
2878 }
else if (MPACK_UNLIKELY(fix_bias > 0xff)) {
2885 f_significand = (
uint32_t)(d_significand >> 29);
2890 printf(
"\n===============\n");
2891 for (
size_t i = 0; i < 64; ++i)
2892 printf(
"%i%s",(
int)((d>>(63-i))&1),((i%8)==7)?
" ":
"");
2893 printf(
"\n%lu %lu %lu\n", d_sign, d_exponent, d_significand);
2894 printf(
"%u %u %u\n", f_sign, f_exponent, f_significand);
2897 v.u = (f_sign << 31) | (f_exponent << 23) | f_significand;
2909#define MPACK_TAG_SIZE_FIXUINT 1
2910#define MPACK_TAG_SIZE_U8 2
2911#define MPACK_TAG_SIZE_U16 3
2912#define MPACK_TAG_SIZE_U32 5
2913#define MPACK_TAG_SIZE_U64 9
2914#define MPACK_TAG_SIZE_FIXINT 1
2915#define MPACK_TAG_SIZE_I8 2
2916#define MPACK_TAG_SIZE_I16 3
2917#define MPACK_TAG_SIZE_I32 5
2918#define MPACK_TAG_SIZE_I64 9
2919#define MPACK_TAG_SIZE_FLOAT 5
2920#define MPACK_TAG_SIZE_DOUBLE 9
2921#define MPACK_TAG_SIZE_FIXARRAY 1
2922#define MPACK_TAG_SIZE_ARRAY16 3
2923#define MPACK_TAG_SIZE_ARRAY32 5
2924#define MPACK_TAG_SIZE_FIXMAP 1
2925#define MPACK_TAG_SIZE_MAP16 3
2926#define MPACK_TAG_SIZE_MAP32 5
2927#define MPACK_TAG_SIZE_FIXSTR 1
2928#define MPACK_TAG_SIZE_STR8 2
2929#define MPACK_TAG_SIZE_STR16 3
2930#define MPACK_TAG_SIZE_STR32 5
2931#define MPACK_TAG_SIZE_BIN8 2
2932#define MPACK_TAG_SIZE_BIN16 3
2933#define MPACK_TAG_SIZE_BIN32 5
2934#define MPACK_TAG_SIZE_FIXEXT1 2
2935#define MPACK_TAG_SIZE_FIXEXT2 2
2936#define MPACK_TAG_SIZE_FIXEXT4 2
2937#define MPACK_TAG_SIZE_FIXEXT8 2
2938#define MPACK_TAG_SIZE_FIXEXT16 2
2939#define MPACK_TAG_SIZE_EXT8 3
2940#define MPACK_TAG_SIZE_EXT16 4
2941#define MPACK_TAG_SIZE_EXT32 6
2944#define MPACK_EXT_SIZE_TIMESTAMP4 (MPACK_TAG_SIZE_FIXEXT4 + 4)
2945#define MPACK_EXT_SIZE_TIMESTAMP8 (MPACK_TAG_SIZE_FIXEXT8 + 8)
2946#define MPACK_EXT_SIZE_TIMESTAMP12 (MPACK_TAG_SIZE_EXT8 + 12)
2952#if MPACK_READ_TRACKING || MPACK_WRITE_TRACKING
2957typedef struct mpack_track_element_t {
2964 bool key_needs_value;
2969} mpack_track_element_t;
2971typedef struct mpack_track_t {
2974 mpack_track_element_t* elements;
2989mpack_error_t mpack_track_destroy(mpack_track_t* track,
bool cancel);
3007bool mpack_utf8_check(
const char* str,
size_t bytes);
3012bool mpack_utf8_check_no_null(
const char* str,
size_t bytes);
3017bool mpack_str_check_no_null(
const char* str,
size_t bytes);
3031MPACK_SILENCE_WARNINGS_END
3044#ifndef MPACK_WRITER_H
3045#define MPACK_WRITER_H 1
3051MPACK_SILENCE_WARNINGS_BEGIN
3054#if MPACK_WRITE_TRACKING
3055struct mpack_track_t;
3071#define MPACK_WRITER_MINIMUM_BUFFER_SIZE 32
3135typedef struct mpack_builder_page_t {
3136 struct mpack_builder_page_t* next;
3138} mpack_builder_page_t;
3144typedef struct mpack_build_t {
3146 struct mpack_build_t* parent;
3160 bool key_needs_value;
3166typedef struct mpack_builder_t {
3167 mpack_build_t* current_build;
3168 mpack_build_t* latest_build;
3169 mpack_builder_page_t* current_page;
3170 mpack_builder_page_t* pages;
3172 char* stash_position;
3174 #if MPACK_BUILDER_INTERNAL_STORAGE
3181 #if MPACK_COMPATIBILITY
3182 mpack_version_t version;
3194 #if MPACK_WRITE_TRACKING
3195 mpack_track_t track;
3205 mpack_builder_t builder;
3210#if MPACK_WRITE_TRACKING
3218 MPACK_UNUSED(writer);
3220 MPACK_UNUSED(
count);
3223 MPACK_UNUSED(writer);
3227 MPACK_UNUSED(writer);
3231 MPACK_UNUSED(writer);
3235 MPACK_UNUSED(writer);
3236 MPACK_UNUSED(
count);
3327#define mpack_writer_init_stack_line_ex(line, writer) \
3328 char mpack_buf_##line[MPACK_STACK_SIZE]; \
3329 mpack_writer_init(writer, mpack_buf_##line, sizeof(mpack_buf_##line))
3331#define mpack_writer_init_stack_line(line, writer) \
3332 mpack_writer_init_stack_line_ex(line, writer)
3341#define mpack_writer_init_stack(writer) \
3342 mpack_writer_init_stack_line(__LINE__, (writer))
3383#if MPACK_COMPATIBILITY
3392MPACK_INLINE
void mpack_writer_set_version(
mpack_writer_t* writer, mpack_version_t version) {
3393 writer->version = version;
3407 writer->context = context;
3417 return writer->context;
3450 writer->error_fn = error_fn;
3463 writer->teardown = teardown;
3501 return (
size_t)(writer->position - writer->buffer);
3509 return (
size_t)(writer->end - writer->position);
3517 return (
size_t)(writer->end - writer->buffer);
3545 return writer->error;
3670 mpack_write_timestamp(writer, seconds, 0);
3678MPACK_INLINE
void mpack_write_timestamp_struct(
mpack_writer_t* writer, mpack_timestamp_t timestamp) {
3679 mpack_write_timestamp(writer, timestamp.seconds, timestamp.nanoseconds);
3725 MPACK_UNUSED(writer);
3728 mpack_build_t* build = writer->builder.current_build;
3729 if (build != NULL) {
3730 ++build->nested_compound_elements;
3736 MPACK_UNUSED(writer);
3739 mpack_build_t* build = writer->builder.current_build;
3740 if (build != NULL) {
3741 mpack_assert(build->nested_compound_elements > 0);
3742 --build->nested_compound_elements;
4085 mpack_writer_track_pop(writer, mpack_type_ext);
4099 mpack_writer_track_pop(writer,
type);
4106#if MPACK_HAS_GENERIC && !defined(__cplusplus)
4129 #define MPACK_WRITE_GENERIC_FLOAT float: mpack_write_float,
4131 #define MPACK_WRITE_GENERIC_FLOAT
4134 #define MPACK_WRITE_GENERIC_DOUBLE double: mpack_write_double,
4136 #define MPACK_WRITE_GENERIC_DOUBLE
4138#define mpack_write(writer, value) \
4139 _Generic(((void)0, value), \
4140 int8_t: mpack_write_i8, \
4141 int16_t: mpack_write_i16, \
4142 int32_t: mpack_write_i32, \
4143 int64_t: mpack_write_i64, \
4144 uint8_t: mpack_write_u8, \
4145 uint16_t: mpack_write_u16, \
4146 uint32_t: mpack_write_u32, \
4147 uint64_t: mpack_write_u64, \
4148 bool: mpack_write_bool, \
4149 MPACK_WRITE_GENERIC_FLOAT \
4150 MPACK_WRITE_GENERIC_DOUBLE \
4151 char *: mpack_write_cstr_or_nil, \
4152 const char *: mpack_write_cstr_or_nil \
4171#define mpack_write_kv(writer, key, value) do { \
4172 mpack_write_cstr(writer, key); \
4173 mpack_write(writer, value); \
4185#if defined(__cplusplus) || defined(MPACK_DOXYGEN)
4199#undef mpack_write_kv
4316MPACK_INLINE
void mpack_write_kv(
mpack_writer_t* writer,
const char *key,
const char *
value) {
4331MPACK_SILENCE_WARNINGS_END
4345#ifndef MPACK_READER_H
4346#define MPACK_READER_H 1
4350MPACK_SILENCE_WARNINGS_BEGIN
4355#if MPACK_READ_TRACKING
4356struct mpack_track_t;
4361#define MPACK_READER_SMALL_FRACTION_DENOMINATOR 32
4386#define MPACK_READER_MINIMUM_BUFFER_SIZE 32
4481 #if MPACK_READ_TRACKING
4482 mpack_track_t track;
4566#define mpack_reader_init_stack_line_ex(line, reader) \
4567 char mpack_buf_##line[MPACK_STACK_SIZE]; \
4568 mpack_reader_init((reader), mpack_buf_##line, sizeof(mpack_buf_##line), 0)
4570#define mpack_reader_init_stack_line(line, reader) \
4571 mpack_reader_init_stack_line_ex(line, reader)
4574#define mpack_reader_init_stack(reader) \
4575 mpack_reader_init_stack_line(__LINE__, (reader))
4612 reader->context = context;
4623 return reader->context;
4677 reader->error_fn = error_fn;
4690 reader->teardown = teardown;
4709 return reader->error;
4926char* mpack_read_bytes_alloc_impl(
mpack_reader_t* reader,
size_t count,
bool null_terminated);
4939 return mpack_read_bytes_alloc_impl(reader,
count,
false);
5058#if MPACK_READ_TRACKING
5068 MPACK_UNUSED(reader);
5142#if MPACK_DEBUG && MPACK_STDIO
5157void mpack_print_data_to_buffer(
const char*
data,
size_t data_size,
char*
buffer,
size_t buffer_size);
5168void mpack_print_data_to_callback(
const char*
data,
size_t size, mpack_print_callback_t callback,
void* context);
5174void mpack_print_data_to_file(
const char*
data,
size_t len, FILE*
file);
5180MPACK_INLINE
void mpack_print_data_to_stdout(
const char*
data,
size_t len) {
5181 mpack_print_data_to_file(
data, len, stdout);
5189void mpack_print_stdfile_to_callback(FILE*
file, mpack_print_callback_t callback,
void* context);
5196MPACK_INLINE
void mpack_print(
const char*
data,
size_t len) {
5197 mpack_print_data_to_stdout(
data, len);
5223 mpack_assert(
count != 0,
"cannot ensure zero bytes!");
5224 mpack_assert(reader->error ==
mpack_ok,
"reader cannot be in an error state!");
5226 if (
count <= (
size_t)(reader->end - reader->data))
5228 return mpack_reader_ensure_straddle(reader,
count);
5236 mpack_assert(
count == 0 || p != NULL,
"data pointer for %i bytes is NULL", (
int)
count);
5238 if (
count > (
size_t)(reader->end - reader->data)) {
5239 mpack_read_native_straddle(reader, p,
count);
5241 mpack_memcpy(p, reader->data,
count);
5242 reader->data +=
count;
5246#if MPACK_READ_TRACKING
5247#define MPACK_READER_TRACK(reader, error_expr) \
5248 (((reader)->error == mpack_ok) ? mpack_reader_flag_if_error((reader), (error_expr)) : (reader)->error)
5250#define MPACK_READER_TRACK(reader, error_expr) (MPACK_UNUSED(reader), mpack_ok)
5254 return MPACK_READER_TRACK(reader, mpack_track_element(&reader->track,
true));
5258 return MPACK_READER_TRACK(reader, mpack_track_peek_element(&reader->track,
true));
5262 MPACK_UNUSED(
count);
5263 return MPACK_READER_TRACK(reader, mpack_track_bytes(&reader->track,
true,
count));
5267 MPACK_UNUSED(
count);
5268 return MPACK_READER_TRACK(reader, mpack_track_str_bytes_all(&reader->track,
true,
count));
5278MPACK_SILENCE_WARNINGS_END
5291#ifndef MPACK_EXPECT_H
5292#define MPACK_EXPECT_H 1
5296MPACK_SILENCE_WARNINGS_BEGIN
5302#error "MPACK_EXPECT requires MPACK_READER."
5538 if (
sizeof(
unsigned int) == 4)
5654 if (
sizeof(
int) == 4)
5775 if (
sizeof(
unsigned int) == 4)
5794 if (
sizeof(
int) == 4)
6139#define mpack_expect_array_alloc(reader, Type, max_count, out_count) \
6140 ((Type*)mpack_expect_array_alloc_impl(reader, sizeof(Type), max_count, out_count, false))
6167#define mpack_expect_array_or_nil_alloc(reader, Type, max_count, out_count) \
6168 ((Type*)mpack_expect_array_alloc_impl(reader, sizeof(Type), max_count, out_count, true))
6178 size_t element_size,
uint32_t max_count,
uint32_t* out_count,
bool allow_nil);
6242 if (length > maxsize) {
6343 mpack_assert(cstr != NULL,
"cstr pointer is NULL");
6380 if (length > maxsize) {
6493 if (length > maxsize) {
6527 if (mpack_expect_ext(reader,
type) !=
count) {
6558#if MPACK_EXTENSIONS && defined(MPACK_MALLOC)
6735 bool found[],
size_t count);
6748MPACK_SILENCE_WARNINGS_END
6763#define MPACK_NODE_H 1
6767MPACK_SILENCE_WARNINGS_BEGIN
6915typedef struct mpack_tree_page_t {
6916 struct mpack_tree_page_t* next;
6920typedef enum mpack_tree_parse_state_t {
6921 mpack_tree_parse_state_not_started,
6922 mpack_tree_parse_state_in_progress,
6923 mpack_tree_parse_state_parsed,
6924} mpack_tree_parse_state_t;
6926typedef struct mpack_level_t {
6931typedef struct mpack_tree_parser_t {
6932 mpack_tree_parse_state_t state;
6952 size_t possible_nodes_left;
6957 size_t current_node_reserved;
6963 mpack_level_t* stack;
6964 size_t stack_capacity;
6972} mpack_tree_parser_t;
6986 size_t buffer_capacity;
6998 mpack_tree_parser_t parser;
7005 mpack_tree_page_t* next;
7019 return node.data->value.children + child;
7023 return mpack_node(tree, &tree->nil_node);
7027 return mpack_node(tree, &tree->missing_node);
7091 size_t max_message_size,
size_t max_message_nodes);
7185 size_t max_message_nodes);
7274 tree->context = context;
7284 return tree->context;
7301 tree->error_fn = error_fn;
7314 tree->teardown = teardown;
7365#if MPACK_DEBUG && MPACK_STDIO
7387void mpack_node_print_to_callback(
mpack_node_t node, mpack_print_callback_t callback,
void* context);
7405MPACK_INLINE
void mpack_node_print_to_stdout(
mpack_node_t node) {
7406 mpack_node_print_to_file(node, stdout);
7415 mpack_node_print_to_stdout(node);
7626mpack_timestamp_t mpack_node_timestamp(
mpack_node_t node);
8201MPACK_SILENCE_WARNINGS_END
then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file
Definition: ThirdPartyNotices.txt:195
\rst A contiguous memory buffer with an optional growing ability.
Definition: core.h:862
Definition: format.h:3841
constexpr auto count() -> size_t
Definition: core.h:1204
type
Definition: core.h:575
struct mpack_tag_t mpack_tag_t
An MPack tag is a MessagePack object header.
Definition: mpack.h:2080
MPACK_INLINE mpack_tag_t mpack_tag_array(int32_t count)
Definition: mpack.h:2646
MPACK_INLINE mpack_tag_t mpack_tag_make_double(double value)
Generates a double tag.
Definition: mpack.h:2201
MPACK_INLINE uint32_t mpack_tag_bytes(mpack_tag_t *tag)
Gets the length in bytes of a str-, bin- or ext-type tag.
Definition: mpack.h:2463
#define MPACK_TAG_ZERO
An mpack_tag_t initializer that zeroes the given tag.
Definition: mpack.h:2135
MPACK_INLINE mpack_tag_t mpack_tag_false(void)
Definition: mpack.h:2617
MPACK_INLINE mpack_tag_t mpack_tag_int(int64_t value)
Definition: mpack.h:2622
mpack_type_t
Defines the type of a MessagePack tag.
Definition: mpack.h:2027
MPACK_INLINE mpack_tag_t mpack_tag_make_uint(uint64_t value)
Generates an unsigned int tag.
Definition: mpack.h:2178
MPACK_INLINE mpack_tag_t mpack_tag_make_false(void)
Generates a bool tag with value false.
Definition: mpack.h:2162
MPACK_INLINE mpack_tag_t mpack_tag_uint(uint64_t value)
Definition: mpack.h:2627
MPACK_INLINE mpack_tag_t mpack_tag_bool(bool value)
Definition: mpack.h:2607
MPACK_INLINE mpack_tag_t mpack_tag_nil(void)
Definition: mpack.h:2602
MPACK_INLINE bool mpack_tag_equal(mpack_tag_t left, mpack_tag_t right)
Compares two tags for equality.
Definition: mpack.h:2524
MPACK_INLINE mpack_tag_t mpack_tag_make_array(uint32_t count)
Generates an array tag.
Definition: mpack.h:2214
MPACK_INLINE mpack_tag_t mpack_tag_make_true(void)
Generates a bool tag with value true.
Definition: mpack.h:2154
MPACK_INLINE float mpack_tag_float_value(mpack_tag_t *tag)
Gets the float value of a float-type tag.
Definition: mpack.h:2337
MPACK_INLINE mpack_tag_t mpack_tag_make_nil(void)
Generates a nil tag.
Definition: mpack.h:2139
const char * mpack_type_to_string(mpack_type_t type)
Converts an MPack type to a string.
MPACK_INLINE mpack_tag_t mpack_tag_str(int32_t length)
Definition: mpack.h:2656
MPACK_INLINE double mpack_tag_double_value(mpack_tag_t *tag)
Gets the double value of a double-type tag.
Definition: mpack.h:2359
MPACK_INLINE mpack_tag_t mpack_tag_make_str(uint32_t length)
Generates a str tag.
Definition: mpack.h:2230
MPACK_INLINE mpack_tag_t mpack_tag_bin(int32_t length)
Definition: mpack.h:2661
MPACK_INLINE uint32_t mpack_tag_bin_length(mpack_tag_t *tag)
Gets the length in bytes of a bin-type tag.
Definition: mpack.h:2415
MPACK_INLINE mpack_tag_t mpack_tag_true(void)
Definition: mpack.h:2612
MPACK_INLINE mpack_tag_t mpack_tag_map(int32_t count)
Definition: mpack.h:2651
MPACK_INLINE mpack_tag_t mpack_tag_make_int(int64_t value)
Generates a signed int tag.
Definition: mpack.h:2170
int mpack_tag_cmp(mpack_tag_t left, mpack_tag_t right)
Compares two tags with an arbitrary fixed ordering.
MPACK_INLINE bool mpack_tag_bool_value(mpack_tag_t *tag)
Gets the boolean value of a bool-type tag.
Definition: mpack.h:2283
MPACK_INLINE uint64_t mpack_tag_uint_value(mpack_tag_t *tag)
Gets the unsigned integer value of a uint-type tag.
Definition: mpack.h:2319
MPACK_INLINE mpack_type_t mpack_tag_type(mpack_tag_t *tag)
Gets the type of a tag.
Definition: mpack.h:2272
MPACK_INLINE mpack_tag_t mpack_tag_make_float(float value)
Generates a float tag.
Definition: mpack.h:2187
mpack_error_t
Error states for MPack objects.
Definition: mpack.h:2001
MPACK_INLINE int64_t mpack_tag_int_value(mpack_tag_t *tag)
Gets the signed integer value of an int-type tag.
Definition: mpack.h:2301
MPACK_INLINE mpack_tag_t mpack_tag_make_map(uint32_t count)
Generates a map tag.
Definition: mpack.h:2222
MPACK_INLINE mpack_tag_t mpack_tag_double(double value)
Definition: mpack.h:2640
const char * mpack_error_to_string(mpack_error_t error)
Converts an MPack error to a string.
MPACK_INLINE mpack_tag_t mpack_tag_float(float value)
Definition: mpack.h:2633
MPACK_INLINE mpack_tag_t mpack_tag_make_bool(bool value)
Generates a bool tag.
Definition: mpack.h:2146
MPACK_INLINE uint32_t mpack_tag_array_count(mpack_tag_t *tag)
Gets the number of elements in an array tag.
Definition: mpack.h:2376
MPACK_INLINE uint32_t mpack_tag_str_length(mpack_tag_t *tag)
Gets the length in bytes of a str-type tag.
Definition: mpack.h:2402
MPACK_INLINE mpack_tag_t mpack_tag_make_bin(uint32_t length)
Generates a bin tag.
Definition: mpack.h:2238
MPACK_INLINE uint32_t mpack_tag_map_count(mpack_tag_t *tag)
Gets the number of key-value pairs in a map tag.
Definition: mpack.h:2389
@ mpack_type_bool
A boolean (true or false.)
Definition: mpack.h:2030
@ mpack_type_map
An ordered map of key/value pairs of MessagePack objects.
Definition: mpack.h:2038
@ mpack_type_missing
Special type indicating a missing optional value.
Definition: mpack.h:2028
@ mpack_type_str
A string.
Definition: mpack.h:2035
@ mpack_type_double
A 64-bit IEEE 754 floating point number.
Definition: mpack.h:2034
@ mpack_type_bin
A chunk of binary data.
Definition: mpack.h:2036
@ mpack_type_nil
A null value.
Definition: mpack.h:2029
@ mpack_type_float
A 32-bit IEEE 754 floating point number.
Definition: mpack.h:2033
@ mpack_type_int
A 64-bit signed integer.
Definition: mpack.h:2031
@ mpack_type_array
An array of MessagePack objects.
Definition: mpack.h:2037
@ mpack_type_uint
A 64-bit unsigned integer.
Definition: mpack.h:2032
@ mpack_error_eof
The reader failed to read because of file or socket EOF.
Definition: mpack.h:2011
@ mpack_error_memory
An allocation failure occurred.
Definition: mpack.h:2008
@ mpack_error_too_big
A read or write was bigger than the maximum size allowed for that operation.
Definition: mpack.h:2007
@ mpack_ok
No error.
Definition: mpack.h:2002
@ mpack_error_io
The reader or writer failed to fill or flush, or some other file or socket error occurred.
Definition: mpack.h:2003
@ mpack_error_invalid
The data read is not valid MessagePack.
Definition: mpack.h:2004
@ mpack_error_unsupported
The data read is not supported by this configuration of MPack.
Definition: mpack.h:2005
@ mpack_error_type
The type or value range did not match what was expected by the caller.
Definition: mpack.h:2006
@ mpack_error_bug
The MPack API was used incorrectly.
Definition: mpack.h:2009
@ mpack_error_data
The contained data is not valid.
Definition: mpack.h:2010
#define MPACK_REALLOC
Defines the realloc function used by MPack.
Definition: mpack.h:482
#define MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC
The maximum depth for the node parser if MPACK_MALLOC is not available.
Definition: mpack.h:884
#define MPACK_NODE_INITIAL_DEPTH
The initial depth for the node parser.
Definition: mpack.h:877
#define MPACK_BUILDER_INTERNAL_STORAGE_SIZE
Amount of space reserved inside mpack_writer_t for the Builders.
Definition: mpack.h:868
void mpack_expect_uint_match(mpack_reader_t *reader, uint64_t value)
Reads an unsigned integer, ensuring that it exactly matches the given value.
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.
Definition: mpack.h:5535
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,...
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.
uint32_t mpack_expect_array(mpack_reader_t *reader)
Reads the start of an array, returning its element count.
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.
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.
Definition: mpack.h:5551
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.
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.
Definition: mpack.h:5668
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,...
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...
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.
Definition: mpack.h:5954
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.
uint32_t mpack_expect_map(mpack_reader_t *reader)
Reads the start of a map, returning its element count.
float mpack_expect_float(mpack_reader_t *reader)
Reads a number, returning the value as a float.
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...
float mpack_expect_float_strict(mpack_reader_t *reader)
Reads a float.
double mpack_expect_double(mpack_reader_t *reader)
Reads a number, returning the value as a double.
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,...
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.
Definition: mpack.h:5719
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,...
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.
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 ...
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.
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.
Definition: mpack.h:5681
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 ...
Definition: mpack.h:6260
uint32_t mpack_expect_str(mpack_reader_t *reader)
Reads the start of a string, returning its size in bytes.
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.
Definition: mpack.h:5651
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.
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.
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.
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.
Definition: mpack.h:5694
int8_t mpack_expect_i8(mpack_reader_t *reader)
Reads an 8-bit signed integer.
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 arra...
void mpack_expect_array_match(mpack_reader_t *reader, uint32_t count)
Reads the start of an array of the exact size given.
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.
Definition: mpack.h:6064
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 ...
Definition: mpack.h:6240
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.
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 b...
Definition: mpack.h:6378
void mpack_expect_int_match(mpack_reader_t *reader, int64_t value)
Reads a signed integer, ensuring that it exactly matches the given value.
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 b...
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...
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.
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.
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.
MPACK_INLINE int mpack_expect_int(mpack_reader_t *reader)
Reads a signed int.
Definition: mpack.h:5791
uint8_t mpack_expect_u8(mpack_reader_t *reader)
Reads an 8-bit unsigned integer.
uint64_t mpack_expect_u64(mpack_reader_t *reader)
Reads a 64-bit unsigned integer.
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.
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),...
void mpack_expect_map_match(mpack_reader_t *reader, uint32_t count)
Reads the start of a map of the exact size given.
MPACK_INLINE unsigned int mpack_expect_uint(mpack_reader_t *reader)
Reads an unsigned int.
Definition: mpack.h:5772
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.
Definition: mpack.h:5575
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.
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.
uint32_t mpack_expect_u32(mpack_reader_t *reader)
Reads a 32-bit unsigned integer.
uint16_t mpack_expect_u16(mpack_reader_t *reader)
Reads a 16-bit unsigned integer.
double mpack_expect_double_strict(mpack_reader_t *reader)
Reads a double.
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.
int16_t mpack_expect_i16(mpack_reader_t *reader)
Reads a 16-bit signed integer.
int64_t mpack_expect_i64(mpack_reader_t *reader)
Reads a 64-bit signed integer.
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 th...
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 b...
Definition: mpack.h:6398
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.
Definition: mpack.h:5599
uint32_t mpack_expect_bin(mpack_reader_t *reader)
Reads the start of a binary blob, returning its size in bytes.
int32_t mpack_expect_i32(mpack_reader_t *reader)
Reads a 32-bit signed integer.
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.
Definition: mpack.h:5587
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.
Definition: mpack.h:5563
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),...
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.
Definition: mpack.h:6342
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 ke...
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.
Definition: mpack.h:5707
int32_t mpack_node_i32(mpack_node_t node)
Returns the 32-bit signed value of the node.
size_t mpack_node_map_count(mpack_node_t node)
Returns the number of key/value pairs in the given map node.
void mpack_tree_init_filename(mpack_tree_t *tree, const char *filename, size_t max_bytes)
Initializes a tree to parse the given file.
struct mpack_node_t mpack_node_t
A handle to node data in a parsed MPack tree.
Definition: mpack.h:6797
bool mpack_node_is_nil(mpack_node_t node)
Returns true if the given node is a nil node; false otherwise.
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 ...
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 n...
bool mpack_node_is_missing(mpack_node_t node)
Returns true if the given node handle indicates a missing node; false otherwise.
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.
Definition: mpack.h:6842
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 k...
void(* mpack_tree_teardown_t)(mpack_tree_t *tree)
A teardown function to be called when the tree is destroyed.
Definition: mpack.h:6870
double mpack_node_double(mpack_node_t node)
Returns the double value of the node.
unsigned int mpack_node_uint(mpack_node_t node)
Returns the unsigned int value of the node.
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.
float mpack_node_float_strict(mpack_node_t node)
Returns the float value of the node.
uint32_t mpack_node_data_len(mpack_node_t node)
Returns the length of the given str, bin or ext node.
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.
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.
Definition: mpack.h:7273
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 i...
struct mpack_node_data_t mpack_node_data_t
The storage for nodes in an MPack tree.
Definition: mpack.h:6808
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.
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,...
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.
uint64_t mpack_node_u64(mpack_node_t node)
Returns the 64-bit unsigned value of the node.
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.
void mpack_node_nil(mpack_node_t node)
Checks that the given node is of nil type, raising mpack_error_type otherwise.
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.
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.
int8_t mpack_node_i8(mpack_node_t node)
Returns the 8-bit signed value of the node.
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.
MPACK_INLINE mpack_error_t mpack_tree_error(mpack_tree_t *tree)
Returns the error state of the tree.
Definition: mpack.h:7242
MPACK_INLINE void mpack_tree_init_file(mpack_tree_t *tree, const char *filename, size_t max_bytes)
Deprecated.
Definition: mpack.h:7134
float mpack_node_float(mpack_node_t node)
Returns the float value of the node.
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 n...
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.
double mpack_node_double_strict(mpack_node_t node)
Returns the double value of the node.
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.
void mpack_tree_init_data(mpack_tree_t *tree, const char *data, size_t length)
Initializes a tree parser with the given data.
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.
const char * mpack_node_data(mpack_node_t node)
Returns a pointer to the data contained by this node.
int mpack_node_int(mpack_node_t node)
Returns the int value of the node.
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.
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.
size_t mpack_node_array_length(mpack_node_t node)
Returns the length of the given array node.
MPACK_INLINE void * mpack_tree_context(mpack_tree_t *tree)
Returns the custom context for tree callbacks.
Definition: mpack.h:7283
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.
void mpack_node_missing(mpack_node_t node)
Checks that the given node indicates a missing node, raising mpack_error_type otherwise.
MPACK_INLINE void mpack_tree_init(mpack_tree_t *tree, const char *data, size_t length)
Deprecated.
Definition: mpack.h:7059
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.
Definition: mpack.h:7313
void mpack_tree_parse(mpack_tree_t *tree)
Parses a MessagePack message into a tree of immutable nodes.
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.
uint32_t mpack_node_u32(mpack_node_t node)
Returns the 32-bit unsigned value of the node.
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.
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.
struct mpack_tree_t mpack_tree_t
An MPack tree parser to parse a blob or stream of MessagePack.
Definition: mpack.h:6816
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.
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.
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 ...
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.
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.
MPACK_INLINE size_t mpack_tree_size(mpack_tree_t *tree)
Returns the size in bytes of the current parsed message.
Definition: mpack.h:7256
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.
mpack_error_t mpack_tree_destroy(mpack_tree_t *tree)
Destroys the tree.
mpack_type_t mpack_node_type(mpack_node_t node)
Returns the type of the node.
void mpack_node_check_utf8(mpack_node_t node)
Checks that the given node contains a valid UTF-8 string.
bool mpack_node_bool(mpack_node_t node)
Returns the bool value of the node.
MPACK_INLINE mpack_error_t mpack_node_error(mpack_node_t node)
Returns the error state of the node's tree.
Definition: mpack.h:7353
uint8_t mpack_node_u8(mpack_node_t node)
Returns the 8-bit unsigned value of the node.
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.
Definition: mpack.h:7300
void mpack_tree_init_error(mpack_tree_t *tree, mpack_error_t error)
Initializes an MPack tree directly into an error state.
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.
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...
size_t mpack_node_bin_size(mpack_node_t node)
Returns the number of bytes in the given bin node.
uint16_t mpack_node_u16(mpack_node_t node)
Returns the 16-bit unsigned value of the node.
int64_t mpack_node_i64(mpack_node_t node)
Returns the 64-bit signed value of the node.
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.
size_t mpack_node_strlen(mpack_node_t node)
Returns the length in bytes of the given string node.
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 n...
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 buff...
const char * mpack_node_bin_data(mpack_node_t node)
Returns a pointer to the data contained by this bin node.
size_t(* mpack_tree_read_t)(mpack_tree_t *tree, char *buffer, size_t count)
The MPack tree's read function.
Definition: mpack.h:6865
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.
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 th...
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.
int16_t mpack_node_i16(mpack_node_t node)
Returns the 16-bit signed value of the node.
void mpack_writer_init_growable(mpack_writer_t *writer, char **data, size_t *size)
Initializes an MPack writer using a growable buffer.
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.
Definition: mpack.h:4611
void mpack_skip_bytes(mpack_reader_t *reader, size_t count)
Skips bytes from the underlying stream.
MPACK_INLINE void mpack_writer_init_file(mpack_writer_t *writer, const char *filename)
Deprecated.
Definition: mpack.h:3303
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 resultin...
Definition: mpack.h:4734
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.
mpack_error_t mpack_writer_destroy(mpack_writer_t *writer)
Cleans up the MPack writer, flushing and closing the underlying stream, if any.
void mpack_reader_init(mpack_reader_t *reader, char *buffer, size_t size, size_t count)
Initializes an MPack reader with the given buffer.
size_t mpack_reader_remaining(mpack_reader_t *reader, const char **data)
Returns bytes left in the reader's buffer.
MPACK_INLINE void mpack_done_array(mpack_reader_t *reader)
Finishes reading an array.
Definition: mpack.h:5078
mpack_tag_t mpack_peek_tag(mpack_reader_t *reader)
Parses the next MessagePack object header (an MPack tag) without advancing the reader.
void mpack_discard(mpack_reader_t *reader)
Reads and discards the next object.
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.
MPACK_INLINE void mpack_reader_init_file(mpack_reader_t *reader, const char *filename)
Deprecated.
Definition: mpack.h:4534
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.
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 g...
MPACK_INLINE void mpack_done_type(mpack_reader_t *reader, mpack_type_t type)
Definition: mpack.h:5067
void(* mpack_reader_skip_t)(mpack_reader_t *reader, size_t count)
The MPack reader's skip function.
Definition: mpack.h:4430
mpack_tag_t mpack_read_tag(mpack_reader_t *reader)
Reads a MessagePack object header (an MPack tag.)
void mpack_reader_init_error(mpack_reader_t *reader, mpack_error_t error)
Initializes an MPack reader directly into an error state.
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.
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.
Definition: mpack.h:4456
MPACK_INLINE void * mpack_reader_context(mpack_reader_t *reader)
Returns the custom context for reader callbacks.
Definition: mpack.h:4622
MPACK_INLINE mpack_error_t mpack_reader_error(mpack_reader_t *reader)
Queries the error state of the MPack reader.
Definition: mpack.h:4708
void mpack_writer_init_filename(mpack_writer_t *writer, const char *filename)
Initializes an MPack writer that writes to a file.
MPACK_INLINE void mpack_done_map(mpack_reader_t *reader)
Finishes reading a map.
Definition: mpack.h:5089
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...
Definition: mpack.h:4938
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.
size_t(* mpack_reader_fill_t)(mpack_reader_t *reader, char *buffer, size_t count)
The MPack reader's fill function.
Definition: mpack.h:4420
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.
Definition: mpack.h:4676
MPACK_INLINE void mpack_done_bin(mpack_reader_t *reader)
Finishes reading a binary data blob.
Definition: mpack.h:5111
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.
MPACK_INLINE void mpack_done_str(mpack_reader_t *reader)
Finishes reading a string.
Definition: mpack.h:5100
void mpack_writer_init_error(mpack_writer_t *writer, mpack_error_t error)
Initializes an MPack writer directly into an error state.
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.
void mpack_writer_init(mpack_writer_t *writer, char *buffer, size_t size)
Initializes an MPack writer with the given buffer.
mpack_error_t mpack_reader_destroy(mpack_reader_t *reader)
Cleans up the MPack reader, ensuring that all compound elements have been completely read.
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.
Definition: mpack.h:5025
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,...
void(* mpack_reader_teardown_t)(mpack_reader_t *reader)
A teardown function to be called when the reader is destroyed.
Definition: mpack.h:4461
void mpack_reader_init_filename(mpack_reader_t *reader, const char *filename)
Initializes an MPack reader that reads from a file.
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.
struct mpack_reader_t mpack_reader_t
A buffered MessagePack decoder.
Definition: mpack.h:4401
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 give...
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.
Definition: mpack.h:4689
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.
void mpack_writer_flush_message(mpack_writer_t *writer)
Flushes any buffered data to the underlying stream.
void mpack_start_str(mpack_writer_t *writer, uint32_t count)
Opens a string.
void mpack_complete_map(struct mpack_writer_t *writer)
Completes a map being built.
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.
void mpack_write_tag(mpack_writer_t *writer, mpack_tag_t tag)
Writes a MessagePack object header (an MPack Tag.)
MPACK_INLINE void mpack_finish_array(mpack_writer_t *writer)
Finishes writing an array.
Definition: mpack.h:3758
MPACK_INLINE void * mpack_writer_context(mpack_writer_t *writer)
Returns the custom context for writer callbacks.
Definition: mpack.h:3416
MPACK_INLINE mpack_error_t mpack_writer_error(mpack_writer_t *writer)
Queries the error state of the MPack writer.
Definition: mpack.h:3544
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.
Definition: mpack.h:3462
void mpack_write_float(mpack_writer_t *writer, float value)
Writes a float.
void mpack_write_double(mpack_writer_t *writer, double value)
Writes a double.
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 poin...
void mpack_write_bin(mpack_writer_t *writer, const char *data, uint32_t count)
Writes a binary blob.
void mpack_write_i32(mpack_writer_t *writer, int32_t value)
Writes a 32-bit integer in the most efficient packing available.
void mpack_write_cstr(mpack_writer_t *writer, const char *cstr)
Writes a null-terminated string.
MPACK_INLINE void mpack_write_int(mpack_writer_t *writer, int64_t value)
Writes an integer in the most efficient packing available.
Definition: mpack.h:3588
void mpack_start_array(mpack_writer_t *writer, uint32_t count)
Opens an array.
MPACK_INLINE void mpack_finish_map(mpack_writer_t *writer)
Finishes writing a map.
Definition: mpack.h:3774
void mpack_write_u64(mpack_writer_t *writer, uint64_t value)
Writes an 64-bit unsigned integer in the most efficient packing available.
void mpack_write_i8(mpack_writer_t *writer, int8_t value)
Writes an 8-bit integer in the most efficient packing available.
MPACK_INLINE void mpack_write_uint(mpack_writer_t *writer, uint64_t value)
Writes an unsigned integer in the most efficient packing available.
Definition: mpack.h:3605
void mpack_write_utf8(mpack_writer_t *writer, const char *str, uint32_t length)
Writes a string, ensuring that it is valid UTF-8.
MPACK_INLINE size_t mpack_writer_buffer_size(mpack_writer_t *writer)
Returns the (current) size of the buffer.
Definition: mpack.h:3516
void mpack_write_u8(mpack_writer_t *writer, uint8_t value)
Writes an 8-bit unsigned integer in the most efficient packing available.
void mpack_build_map(struct mpack_writer_t *writer)
Starts building a map.
void mpack_start_map(mpack_writer_t *writer, uint32_t count)
Opens a map.
void mpack_write_utf8_cstr(mpack_writer_t *writer, const char *cstr)
Writes a null-terminated string, ensuring that it is valid UTF-8.
void mpack_write_bool(mpack_writer_t *writer, bool value)
Writes a boolean.
void mpack_write_true(mpack_writer_t *writer)
Writes a boolean with value true.
void mpack_build_array(struct mpack_writer_t *writer)
Starts building an array.
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.
Definition: mpack.h:3117
void mpack_complete_array(struct mpack_writer_t *writer)
Completes an array being built.
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.
void mpack_write_u32(mpack_writer_t *writer, uint32_t value)
Writes an 32-bit unsigned integer in the most efficient packing available.
void mpack_write_object_bytes(mpack_writer_t *writer, const char *data, size_t bytes)
Write a pre-encoded messagepack object.
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...
MPACK_INLINE void mpack_builder_compound_push(mpack_writer_t *writer)
Definition: mpack.h:3724
MPACK_INLINE void mpack_finish_type(mpack_writer_t *writer, mpack_type_t type)
Finishes writing the given compound type.
Definition: mpack.h:4098
void(* mpack_writer_teardown_t)(mpack_writer_t *writer)
A teardown function to be called when the writer is destroyed.
Definition: mpack.h:3122
void mpack_start_bin(mpack_writer_t *writer, uint32_t count)
Opens a binary blob.
MPACK_INLINE void mpack_builder_compound_pop(mpack_writer_t *writer)
Definition: mpack.h:3735
void mpack_expect_false(mpack_reader_t *reader)
Reads a boolean, raising mpack_error_type if its value is not false.
MPACK_INLINE size_t mpack_writer_buffer_left(mpack_writer_t *writer)
Returns the amount of space left in the buffer.
Definition: mpack.h:3508
void mpack_expect_true(mpack_reader_t *reader)
Reads a boolean, raising mpack_error_type if its value is not true.
void mpack_write_false(mpack_writer_t *writer)
Writes a boolean with value false.
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.
Definition: mpack.h:3449
void mpack_write_i64(mpack_writer_t *writer, int64_t value)
Writes a 64-bit integer in the most efficient packing available.
struct mpack_writer_t mpack_writer_t
A buffered MessagePack encoder.
Definition: mpack.h:3082
void mpack_write_str(mpack_writer_t *writer, const char *str, uint32_t length)
Writes a string.
void mpack_write_i16(mpack_writer_t *writer, int16_t value)
Writes a 16-bit integer in the most efficient packing available.
void mpack_write_u16(mpack_writer_t *writer, uint16_t value)
Writes an 16-bit unsigned integer in the most efficient packing available.
MPACK_INLINE size_t mpack_writer_buffer_used(mpack_writer_t *writer)
Returns the number of bytes currently stored in the buffer.
Definition: mpack.h:3500
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.
Definition: mpack.h:3091
void mpack_expect_nil(mpack_reader_t *reader)
Reads a nil, raising mpack_error_type if the value is not nil.
void mpack_write_nil(mpack_writer_t *writer)
Writes a nil.
bool mpack_expect_bool(mpack_reader_t *reader)
Reads a boolean.
MPACK_INLINE void mpack_finish_str(mpack_writer_t *writer)
Finishes writing a string.
Definition: mpack.h:4051
MPACK_INLINE void mpack_finish_bin(mpack_writer_t *writer)
Finishes writing a binary blob.
Definition: mpack.h:4066
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.
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.
Definition: mpack.h:3406
#define MPACK_READER_SMALL_FRACTION_DENOMINATOR
Definition: mpack.h:4361
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: PacketMath.h:646
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
::uint64_t uint64_t
Definition: Meta.h:58
::int16_t int16_t
Definition: Meta.h:55
::uint16_t uint16_t
Definition: Meta.h:54
::uint32_t uint32_t
Definition: Meta.h:56
::int32_t int32_t
Definition: Meta.h:57
::int8_t int8_t
Definition: Meta.h:53
::int64_t int64_t
Definition: Meta.h:59
::uint8_t uint8_t
Definition: Meta.h:52
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
constexpr auto max_value() -> T
Definition: format.h:437
@ error
Definition: format.h:2559
Definition: Eigen_Colamd.h:50
Definition: MessagePack.h:15
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition: Endian.h:65
auto printf(const S &fmt, const T &... args) -> int
\rst Prints formatted data to stdout.
Definition: printf.h:631
Definition: format.h:1544
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:87