35#define MPACK_AMALGAMATED 1
37#if defined(MPACK_HAS_CONFIG) && MPACK_HAS_CONFIG
38#include "mpack-config.h"
64#ifndef MPACK_PLATFORM_H
65#define MPACK_PLATFORM_H 1
112#if defined(_MSC_VER) && _MSC_VER < 1800 && !defined(__cplusplus)
113 #error "In Visual Studio 2012 and earlier, MPack must be compiled as C++. Enable the /Tp compiler flag."
116#if defined(_WIN32) && MPACK_INTERNAL
117 #define _CRT_SECURE_NO_WARNINGS 1
120#ifndef __STDC_LIMIT_MACROS
121 #define __STDC_LIMIT_MACROS 1
123#ifndef __STDC_FORMAT_MACROS
124 #define __STDC_FORMAT_MACROS 1
126#ifndef __STDC_CONSTANT_MACROS
127 #define __STDC_CONSTANT_MACROS 1
148#if defined(MPACK_HAS_CONFIG)
150 #include "mpack-config.h"
153 #define MPACK_HAS_CONFIG 0
162#ifndef MPACK_NO_BUILTINS
163 #define MPACK_NO_BUILTINS 0
180#define MPACK_READER 1
189#define MPACK_EXPECT 1
207#define MPACK_WRITER 1
242#ifndef MPACK_COMPATIBILITY
243#define MPACK_COMPATIBILITY 0
258#ifndef MPACK_EXTENSIONS
259#define MPACK_EXTENSIONS 0
269#if defined(MPACK_DOXYGEN)
276#define MPACK_COMPATIBILITY 0
277#define MPACK_EXTENSIONS 0
310#ifndef MPACK_CONFORMING
311 #define MPACK_CONFORMING 1
338 #if !MPACK_CONFORMING
341 #define MPACK_STDLIB 0
343 #define MPACK_STDLIB 1
354 #if !MPACK_STDLIB || defined(__AVR__)
355 #define MPACK_STDIO 0
357 #define MPACK_STDIO 1
369 #define MPACK_FLOAT 1
384 #if !MPACK_FLOAT || defined(__AVR__)
386 #define MPACK_DOUBLE 0
388 #define MPACK_DOUBLE 1
458#if defined(MPACK_MALLOC) && !defined(MPACK_FREE)
459 #error "MPACK_MALLOC requires MPACK_FREE."
461#if !defined(MPACK_MALLOC) && defined(MPACK_FREE)
462 #error "MPACK_FREE requires MPACK_MALLOC."
467 #error "Define MPACK_MALLOC, not mpack_malloc."
470 #error "Define MPACK_REALLOC, not mpack_realloc."
473 #error "Define MPACK_FREE, not mpack_free."
478 #error "Don't define MPACK_CALLOC. MPack does not use calloc()."
481 #error "Don't define mpack_calloc. MPack does not use calloc()."
485#if defined(MPACK_STDLIB)
486 #if MPACK_STDLIB && !defined(MPACK_MALLOC)
487 #define MPACK_MALLOC malloc
488 #define MPACK_REALLOC realloc
489 #define MPACK_FREE free
501 #if defined(MPACK_MALLOC) && MPACK_WRITER
502 #define MPACK_BUILDER 1
504 #define MPACK_BUILDER 0
579 #error "Define MPACK_MEMCMP, not mpack_memcmp."
582 #error "Define MPACK_MEMCPY, not mpack_memcpy."
585 #error "Define MPACK_MEMMOVE, not mpack_memmove."
588 #error "Define MPACK_MEMSET, not mpack_memset."
591 #error "Define MPACK_STRLEN, not mpack_strlen."
597 #define MPACK_MEMCMP memcmp
600 #define MPACK_MEMCPY memcpy
602 #ifndef MPACK_MEMMOVE
603 #define MPACK_MEMMOVE memmove
606 #define MPACK_MEMSET memset
609 #define MPACK_STRLEN strlen
613#if !MPACK_NO_BUILTINS
615 #if !defined(MPACK_MEMCMP) && __has_builtin(__builtin_memcmp)
616 #define MPACK_MEMCMP __builtin_memcmp
618 #if !defined(MPACK_MEMCPY) && __has_builtin(__builtin_memcpy)
619 #define MPACK_MEMCPY __builtin_memcpy
621 #if !defined(MPACK_MEMMOVE) && __has_builtin(__builtin_memmove)
622 #define MPACK_MEMMOVE __builtin_memmove
624 #if !defined(MPACK_MEMSET) && __has_builtin(__builtin_memset)
625 #define MPACK_MEMSET __builtin_memset
627 #if !defined(MPACK_STRLEN) && __has_builtin(__builtin_strlen)
628 #define MPACK_STRLEN __builtin_strlen
630 #elif defined(__GNUC__)
632 #define MPACK_MEMCMP __builtin_memcmp
635 #define MPACK_MEMCPY __builtin_memcpy
642 #define MPACK_MEMSET __builtin_memset
645 #define MPACK_STRLEN __builtin_strlen
669#if !defined(MPACK_DEBUG)
670 #if defined(DEBUG) || defined(_DEBUG)
671 #define MPACK_DEBUG 1
673 #define MPACK_DEBUG 0
688 #define MPACK_STRINGS 0
690 #define MPACK_STRINGS 1
701#ifndef MPACK_CUSTOM_ASSERT
702#define MPACK_CUSTOM_ASSERT 0
714#if !defined(MPACK_READ_TRACKING)
715 #if MPACK_DEBUG && MPACK_READER && defined(MPACK_MALLOC)
716 #define MPACK_READ_TRACKING 1
718 #define MPACK_READ_TRACKING 0
721#if MPACK_READ_TRACKING && !MPACK_READER
722 #error "MPACK_READ_TRACKING requires MPACK_READER."
739#if !defined(MPACK_WRITE_TRACKING)
740 #if MPACK_DEBUG && MPACK_WRITER && defined(MPACK_MALLOC)
741 #define MPACK_WRITE_TRACKING 1
743 #define MPACK_WRITE_TRACKING 0
746#if MPACK_WRITE_TRACKING && !MPACK_WRITER
747 #error "MPACK_WRITE_TRACKING requires MPACK_WRITER."
772#ifndef MPACK_OPTIMIZE_FOR_SIZE
773 #ifdef __OPTIMIZE_SIZE__
774 #define MPACK_OPTIMIZE_FOR_SIZE 1
776 #define MPACK_OPTIMIZE_FOR_SIZE 0
787#ifndef MPACK_STACK_SIZE
788#define MPACK_STACK_SIZE 4096
799#ifndef MPACK_BUFFER_SIZE
800#define MPACK_BUFFER_SIZE 4096
809#ifndef MPACK_PAGE_SIZE
810#define MPACK_PAGE_SIZE 4096
826#ifndef MPACK_NODE_PAGE_SIZE
827#define MPACK_NODE_PAGE_SIZE MPACK_PAGE_SIZE
836#ifndef MPACK_BUILDER_PAGE_SIZE
837#define MPACK_BUILDER_PAGE_SIZE MPACK_PAGE_SIZE
851#ifndef MPACK_BUILDER_INTERNAL_STORAGE
852#define MPACK_BUILDER_INTERNAL_STORAGE 0
873#ifndef MPACK_BUILDER_INTERNAL_STORAGE_SIZE
874#define MPACK_BUILDER_INTERNAL_STORAGE_SIZE 256
882#ifndef MPACK_NODE_INITIAL_DEPTH
883#define MPACK_NODE_INITIAL_DEPTH 8
889#ifndef MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC
890#define MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC 32
902#if defined(MPACK_DOXYGEN)
904 #define MPACK_NO_BUILTINS 0
931void mpack_assert_fail(
const char* message);
951#ifndef MPACK_CUSTOM_BREAK
952#define MPACK_CUSTOM_BREAK 0
954#ifndef MPACK_EMIT_INLINE_DEFS
955#define MPACK_EMIT_INLINE_DEFS 0
957#ifndef MPACK_AMALGAMATED
958#define MPACK_AMALGAMATED 0
960#ifndef MPACK_RELEASE_VERSION
961#define MPACK_RELEASE_VERSION 0
963#ifndef MPACK_INTERNAL
964#define MPACK_INTERNAL 0
975 #include <inttypes.h>
999 #define MPACK_INT64_C INT64_C
1000 #define MPACK_UINT64_C UINT64_C
1002 #define MPACK_INT8_MIN INT8_MIN
1003 #define MPACK_INT16_MIN INT16_MIN
1004 #define MPACK_INT32_MIN INT32_MIN
1005 #define MPACK_INT64_MIN INT64_MIN
1006 #define MPACK_INT_MIN INT_MIN
1008 #define MPACK_INT8_MAX INT8_MAX
1009 #define MPACK_INT16_MAX INT16_MAX
1010 #define MPACK_INT32_MAX INT32_MAX
1011 #define MPACK_INT64_MAX INT64_MAX
1012 #define MPACK_INT_MAX INT_MAX
1014 #define MPACK_UINT8_MAX UINT8_MAX
1015 #define MPACK_UINT16_MAX UINT16_MAX
1016 #define MPACK_UINT32_MAX UINT32_MAX
1017 #define MPACK_UINT64_MAX UINT64_MAX
1018 #define MPACK_UINT_MAX UINT_MAX
1022 #define MPACK_INT64_C(x) ((int64_t)(x##LL))
1023 #define MPACK_UINT64_C(x) ((uint64_t)(x##LLU))
1025 #define MPACK_INT8_MIN ((int8_t)(0x80))
1026 #define MPACK_INT16_MIN ((int16_t)(0x8000))
1027 #define MPACK_INT32_MIN ((int32_t)(0x80000000))
1028 #define MPACK_INT64_MIN MPACK_INT64_C(0x8000000000000000)
1029 #define MPACK_INT_MIN MPACK_INT32_MIN
1031 #define MPACK_INT8_MAX ((int8_t)(0x7f))
1032 #define MPACK_INT16_MAX ((int16_t)(0x7fff))
1033 #define MPACK_INT32_MAX ((int32_t)(0x7fffffff))
1034 #define MPACK_INT64_MAX MPACK_INT64_C(0x7fffffffffffffff)
1035 #define MPACK_INT_MAX MPACK_INT32_MAX
1037 #define MPACK_UINT8_MAX ((uint8_t)(0xffu))
1038 #define MPACK_UINT16_MAX ((uint16_t)(0xffffu))
1039 #define MPACK_UINT32_MAX ((uint32_t)(0xffffffffu))
1040 #define MPACK_UINT64_MAX MPACK_UINT64_C(0xffffffffffffffff)
1041 #define MPACK_UINT_MAX MPACK_UINT32_MAX
1050#if MPACK_DOUBLE && !MPACK_FLOAT
1051 #error "MPACK_DOUBLE requires MPACK_FLOAT."
1059 #pragma GCC poison float
1062 #pragma GCC poison double
1074 #define MPACK_EXTERN_C_BEGIN namespace mpack {
1075 #define MPACK_EXTERN_C_END }
1077 #define MPACK_EXTERN_C_BEGIN
1078 #define MPACK_EXTERN_C_END
1087#if defined(__GNUC__)
1089 #if defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1090 #define MPACK_SILENCE_WARNINGS_PUSH _Pragma ("GCC diagnostic push")
1091 #define MPACK_SILENCE_WARNINGS_POP _Pragma ("GCC diagnostic pop")
1093#elif defined(_MSC_VER)
1095 #define MPACK_SILENCE_WARNINGS_PUSH __pragma(warning(push))
1096 #define MPACK_SILENCE_WARNINGS_POP __pragma(warning(pop))
1099#if defined(_MSC_VER)
1102 #define MPACK_SILENCE_WARNINGS_MSVC_W4 \
1103 __pragma(warning(disable:4996)) \
1104 __pragma(warning(disable:4127)) \
1105 __pragma(warning(disable:4702)) \
1106 __pragma(warning(disable:4310))
1108 #define MPACK_SILENCE_WARNINGS_MSVC_W4
1113#if defined(__GNUC__) && !defined(__clang__)
1114 #if __GNUC__ < 5 || (__GNUC__ == 5 && __GNUC_MINOR__ < 1)
1116 #define MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES \
1117 _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"")
1119 #define MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES \
1120 _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"")
1124#ifndef MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES
1125 #define MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES
1130#if defined(__GNUC__) && !defined(__clang__)
1131 #if __GNUC__ == 4 && __GNUC_MINOR__ < 8
1132 #define MPACK_SILENCE_WARNINGS_SHADOW \
1133 _Pragma ("GCC diagnostic ignored \"-Wshadow\"")
1136#ifndef MPACK_SILENCE_WARNINGS_SHADOW
1137 #define MPACK_SILENCE_WARNINGS_SHADOW
1143 #define MPACK_SILENCE_WARNINGS_TYPE_LIMITS \
1144 _Pragma ("GCC diagnostic ignored \"-Wtype-limits\"")
1146 #define MPACK_SILENCE_WARNINGS_TYPE_LIMITS
1151#if defined(__GNUC__) && !defined(__cplusplus)
1152 #define MPACK_SILENCE_WARNINGS_DECLARATION_AFTER_STATEMENT \
1153 _Pragma ("GCC diagnostic ignored \"-Wdeclaration-after-statement\"")
1155 #define MPACK_SILENCE_WARNINGS_DECLARATION_AFTER_STATEMENT
1158#ifdef MPACK_SILENCE_WARNINGS_PUSH
1164 #define MPACK_SILENCE_WARNINGS_BEGIN \
1165 MPACK_SILENCE_WARNINGS_PUSH \
1166 MPACK_SILENCE_WARNINGS_MSVC_W4 \
1167 MPACK_SILENCE_WARNINGS_MISSING_PROTOTYPES \
1168 MPACK_SILENCE_WARNINGS_SHADOW \
1169 MPACK_SILENCE_WARNINGS_TYPE_LIMITS \
1170 MPACK_SILENCE_WARNINGS_DECLARATION_AFTER_STATEMENT
1172 #define MPACK_SILENCE_WARNINGS_END \
1173 MPACK_SILENCE_WARNINGS_POP
1175 #define MPACK_SILENCE_WARNINGS_BEGIN
1176 #define MPACK_SILENCE_WARNINGS_END
1179MPACK_SILENCE_WARNINGS_BEGIN
1186#define MPACK_UNUSED(var) ((void)(var))
1188#define MPACK_STRINGIFY_IMPL(arg) #arg
1189#define MPACK_STRINGIFY(arg) MPACK_STRINGIFY_IMPL(arg)
1198#define MPACK_EXPAND(x) x
1202#define MPACK_EXTRACT_ARG0_IMPL(first, ...) first
1203#define MPACK_EXTRACT_ARG0(...) MPACK_EXPAND(MPACK_EXTRACT_ARG0_IMPL( __VA_ARGS__ , ignored))
1207#define MPACK_STRINGIFY_ARG0_impl(first, ...) #first
1208#define MPACK_STRINGIFY_ARG0(...) MPACK_EXPAND(MPACK_STRINGIFY_ARG0_impl( __VA_ARGS__ , ignored))
1245#if defined(__cplusplus)
1253 #define MPACK_INLINE inline
1255#elif defined(_MSC_VER)
1259 #define MPACK_INLINE __inline
1260 #define MPACK_STATIC_INLINE static __inline
1262#elif defined(__GNUC__) && (defined(__GNUC_GNU_INLINE__) || \
1263 (!defined(__GNUC_STDC_INLINE__) && !defined(__GNUC_GNU_INLINE__)))
1265 #if MPACK_EMIT_INLINE_DEFS
1266 #define MPACK_INLINE inline
1268 #define MPACK_INLINE extern inline
1271#elif defined(__TINYC__)
1276 #ifndef MPACK_DISABLE_TINYC_INLINE_WARNING
1277 #warning "Single-definition inline is not supported by tcc. All inlines will be static. Define MPACK_DISABLE_TINYC_INLINE_WARNING to disable this warning."
1279 #define MPACK_INLINE static inline
1283 #if MPACK_EMIT_INLINE_DEFS
1284 #define MPACK_INLINE extern inline
1286 #define MPACK_INLINE inline
1290#ifndef MPACK_STATIC_INLINE
1291#define MPACK_STATIC_INLINE static inline
1294#ifdef MPACK_OPTIMIZE_FOR_SPEED
1295 #error "You should define MPACK_OPTIMIZE_FOR_SIZE, not MPACK_OPTIMIZE_FOR_SPEED."
1309#if !MPACK_NO_BUILTINS
1310 #if defined(_MSC_VER)
1311 #define MPACK_NOINLINE __declspec(noinline)
1312 #elif defined(__GNUC__) || defined(__clang__)
1313 #define MPACK_NOINLINE __attribute__((__noinline__))
1316#ifndef MPACK_NOINLINE
1317 #define MPACK_NOINLINE
1328#if !MPACK_NO_BUILTINS
1329 #if defined(__GNUC__)
1330 #define MPACK_RESTRICT __restrict__
1331 #elif defined(_MSC_VER)
1332 #define MPACK_RESTRICT __restrict
1336#ifndef MPACK_RESTRICT
1338 #define MPACK_RESTRICT
1342#ifndef MPACK_RESTRICT
1348 #define MPACK_RESTRICT
1353#ifndef MPACK_RESTRICT
1354 #define MPACK_RESTRICT restrict
1361#if !MPACK_NO_BUILTINS
1362 #if defined(__GNUC__) || defined(__clang__)
1363 #define MPACK_UNREACHABLE __builtin_unreachable()
1364 #define MPACK_NORETURN(fn) fn __attribute__((__noreturn__))
1365 #elif defined(_MSC_VER)
1366 #define MPACK_UNREACHABLE __assume(0)
1367 #define MPACK_NORETURN(fn) __declspec(noreturn) fn
1371#ifndef MPACK_UNREACHABLE
1372#define MPACK_UNREACHABLE ((void)0)
1374#ifndef MPACK_NORETURN
1375#define MPACK_NORETURN(fn) fn
1388#if !MPACK_NO_BUILTINS
1389 #if defined(__GNUC__) || defined(__clang__)
1390 #ifndef MPACK_LIKELY
1391 #define MPACK_LIKELY(x) __builtin_expect((x),1)
1393 #ifndef MPACK_UNLIKELY
1394 #define MPACK_UNLIKELY(x) __builtin_expect((x),0)
1400 #define MPACK_LIKELY(x) (x)
1402#ifndef MPACK_UNLIKELY
1403 #define MPACK_UNLIKELY(x) (x)
1410#ifndef MPACK_ALIGNOF
1411 #if defined(__STDC_VERSION__)
1412 #if __STDC_VERSION__ >= 201112L
1413 #define MPACK_ALIGNOF(T) (_Alignof(T))
1418#ifndef MPACK_ALIGNOF
1419 #if defined(__cplusplus)
1420 #if __cplusplus >= 201103L
1421 #define MPACK_ALIGNOF(T) (alignof(T))
1426#ifndef MPACK_ALIGNOF
1427 #if defined(__GNUC__) && !defined(MPACK_NO_BUILTINS)
1428 #if defined(__clang__) || __GNUC__ >= 4
1429 #define MPACK_ALIGNOF(T) (__alignof__(T))
1434#ifndef MPACK_ALIGNOF
1436 #define MPACK_ALIGNOF(T) __alignof(T)
1446#ifndef MPACK_STATIC_ASSERT
1447 #if defined(__cplusplus)
1448 #if __cplusplus >= 201103L
1449 #define MPACK_STATIC_ASSERT static_assert
1451 #elif defined(__STDC_VERSION__)
1452 #if __STDC_VERSION__ >= 201112L
1453 #define MPACK_STATIC_ASSERT _Static_assert
1458#if !MPACK_NO_BUILTINS
1459 #ifndef MPACK_STATIC_ASSERT
1460 #if defined(__has_feature)
1461 #if __has_feature(cxx_static_assert)
1462 #define MPACK_STATIC_ASSERT static_assert
1463 #elif __has_feature(c_static_assert)
1464 #define MPACK_STATIC_ASSERT _Static_assert
1469 #ifndef MPACK_STATIC_ASSERT
1470 #if defined(__GNUC__)
1472 #if defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1474 #if defined(__clang__) || __GNUC__ >= 5
1475 #define MPACK_IGNORE_PEDANTIC "GCC diagnostic ignored \"-Wpedantic\""
1477 #define MPACK_IGNORE_PEDANTIC "GCC diagnostic ignored \"-pedantic\""
1479 #define MPACK_STATIC_ASSERT(expr, str) do { \
1480 _Pragma ("GCC diagnostic push") \
1481 _Pragma (MPACK_IGNORE_PEDANTIC) \
1482 _Pragma ("GCC diagnostic ignored \"-Wc++-compat\"") \
1483 _Static_assert(expr, str); \
1484 _Pragma ("GCC diagnostic pop") \
1491 #ifndef MPACK_STATIC_ASSERT
1493 #if _MSC_VER >= 1600
1494 #define MPACK_STATIC_ASSERT static_assert
1500#ifndef MPACK_STATIC_ASSERT
1501 #define MPACK_STATIC_ASSERT(expr, str) (MPACK_UNUSED(sizeof(char[1 - 2*!(expr)])))
1508#ifndef MPACK_HAS_GENERIC
1509 #if defined(__clang__) && defined(__has_feature)
1512 #if __has_feature(c_generic_selections)
1513 #define MPACK_HAS_GENERIC 1
1515 #define MPACK_HAS_GENERIC 0
1520#ifndef MPACK_HAS_GENERIC
1521 #if defined(__STDC_VERSION__)
1522 #if __STDC_VERSION__ >= 201112L
1523 #if defined(__GNUC__) && !defined(__clang__)
1525 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
1526 #define MPACK_HAS_GENERIC 1
1530 #define MPACK_HAS_GENERIC 1
1536#ifndef MPACK_HAS_GENERIC
1537 #define MPACK_HAS_GENERIC 0
1552#ifndef MPACK_FINITE_MATH
1553#if defined(__FINITE_MATH_ONLY__) && __FINITE_MATH_ONLY__
1554#define MPACK_FINITE_MATH 1
1558#ifndef MPACK_FINITE_MATH
1559#define MPACK_FINITE_MATH 0
1576#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
1577 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1578 #define MPACK_NHSWAP16(x) (x)
1579 #define MPACK_NHSWAP32(x) (x)
1580 #define MPACK_NHSWAP64(x) (x)
1581 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1583 #if !MPACK_NO_BUILTINS
1584 #if defined(__clang__)
1585 #ifdef __has_builtin
1588 #if __has_builtin(__builtin_bswap16)
1589 #define MPACK_NHSWAP16(x) __builtin_bswap16(x)
1591 #if __has_builtin(__builtin_bswap32)
1592 #define MPACK_NHSWAP32(x) __builtin_bswap32(x)
1594 #if __has_builtin(__builtin_bswap64)
1595 #define MPACK_NHSWAP64(x) __builtin_bswap64(x)
1599 #elif defined(__GNUC__)
1605 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
1606 #define MPACK_NHSWAP64(x) __builtin_bswap64(x)
1620#elif defined(_MSC_VER) && defined(_WIN32) && MPACK_STDLIB && !MPACK_NO_BUILTINS
1631 #if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64)
1632 #define MPACK_NHSWAP16(x) _byteswap_ushort(x)
1633 #define MPACK_NHSWAP32(x) _byteswap_ulong(x)
1634 #define MPACK_NHSWAP64(x) _byteswap_uint64(x)
1639#if defined(__FLOAT_WORD_ORDER__) && defined(__BYTE_ORDER__)
1649 #define MPACK_CHECK_FLOAT_ORDER() \
1650 MPACK_STATIC_ASSERT(__FLOAT_WORD_ORDER__ == __BYTE_ORDER__, \
1651 "float byte order does not match int byte order! float/double " \
1652 "encoding is not properly implemented on this platform.")
1656#ifndef MPACK_CHECK_FLOAT_ORDER
1657 #define MPACK_CHECK_FLOAT_ORDER()
1696 MPACK_NORETURN(
void mpack_assert_fail_wrapper(
const char* message));
1698 MPACK_NORETURN(
void mpack_assert_fail_format(
const char*
format, ...));
1699 #define mpack_assert_fail_at(line, file, exprstr, format, ...) \
1700 MPACK_EXPAND(mpack_assert_fail_format("mpack assertion failed at " file ":" #line "\n%s\n" format, exprstr, __VA_ARGS__))
1702 #define mpack_assert_fail_at(line, file, exprstr, format, ...) \
1703 mpack_assert_fail_wrapper("mpack assertion failed at " file ":" #line "\n" exprstr "\n")
1706 #define mpack_assert_fail_pos(line, file, exprstr, expr, ...) \
1707 MPACK_EXPAND(mpack_assert_fail_at(line, file, exprstr, __VA_ARGS__))
1722 #define mpack_assert(...) \
1723 MPACK_EXPAND(((!(MPACK_EXTRACT_ARG0(__VA_ARGS__))) ? \
1724 mpack_assert_fail_pos(__LINE__, __FILE__, MPACK_STRINGIFY_ARG0(__VA_ARGS__) , __VA_ARGS__ , "", NULL) : \
1727 void mpack_break_hit(
const char* message);
1729 void mpack_break_hit_format(
const char*
format, ...);
1730 #define mpack_break_hit_at(line, file, ...) \
1731 MPACK_EXPAND(mpack_break_hit_format("mpack breakpoint hit at " file ":" #line "\n" __VA_ARGS__))
1733 #define mpack_break_hit_at(line, file, ...) \
1734 mpack_break_hit("mpack breakpoint hit at " file ":" #line )
1736 #define mpack_break_hit_pos(line, file, ...) MPACK_EXPAND(mpack_break_hit_at(line, file, __VA_ARGS__))
1737 #define mpack_break(...) MPACK_EXPAND(mpack_break_hit_pos(__LINE__, __FILE__, __VA_ARGS__))
1739 #define mpack_assert(...) \
1740 (MPACK_EXPAND((!(MPACK_EXTRACT_ARG0(__VA_ARGS__))) ? \
1741 (MPACK_UNREACHABLE, (void)0) : \
1743 #define mpack_break(...) ((void)0)
1749#if MPACK_STDLIB && defined(MPACK_UNIT_TESTS) && MPACK_INTERNAL && defined(__GNUC__)
1759 #pragma GCC poison memcmp
1760 #pragma GCC poison memcpy
1761 #pragma GCC poison memmove
1762 #pragma GCC poison memset
1763 #pragma GCC poison strlen
1764 #pragma GCC poison malloc
1765 #pragma GCC poison calloc
1766 #pragma GCC poison realloc
1767 #pragma GCC poison free
1776 #define mpack_memcmp MPACK_MEMCMP
1778 int mpack_memcmp(
const void* s1,
const void* s2,
size_t n);
1782 #define mpack_memcpy MPACK_MEMCPY
1784 void* mpack_memcpy(
void* MPACK_RESTRICT s1,
const void* MPACK_RESTRICT s2,
size_t n);
1788 #define mpack_memmove MPACK_MEMMOVE
1790 void* mpack_memmove(
void* s1,
const void* s2,
size_t n);
1794 #define mpack_memset MPACK_MEMSET
1796 void* mpack_memset(
void* s,
int c,
size_t n);
1800 #define mpack_strlen MPACK_STRLEN
1802 size_t mpack_strlen(
const char* s);
1809 #define mpack_snprintf _snprintf
1811 #define mpack_snprintf snprintf
1820 #define mpack_log(...) (MPACK_EXPAND(printf(__VA_ARGS__)), fflush(stdout))
1822 #define mpack_log(...) ((void)0)
1830 #error "MPACK_STDIO requires preprocessor definitions for MPACK_MALLOC and MPACK_FREE."
1832 #if MPACK_READ_TRACKING
1833 #error "MPACK_READ_TRACKING requires preprocessor definitions for MPACK_MALLOC and MPACK_FREE."
1835 #if MPACK_WRITE_TRACKING
1836 #error "MPACK_WRITE_TRACKING requires preprocessor definitions for MPACK_MALLOC and MPACK_FREE."
1844 #ifdef MPACK_REALLOC
1845 MPACK_INLINE
void* mpack_realloc(
void* old_ptr,
size_t used_size,
size_t new_size) {
1846 MPACK_UNUSED(used_size);
1850 void* mpack_realloc(
void* old_ptr,
size_t used_size,
size_t new_size);
1862MPACK_SILENCE_WARNINGS_END
1874#ifndef MPACK_COMMON_H
1875#define MPACK_COMMON_H 1
1879#ifndef MPACK_PRINT_BYTE_COUNT
1880#define MPACK_PRINT_BYTE_COUNT 12
1883MPACK_SILENCE_WARNINGS_BEGIN
1900#define MPACK_VERSION_MAJOR 1
1901#define MPACK_VERSION_MINOR 1
1902#define MPACK_VERSION_PATCH 1
1905#define MPACK_VERSION ((MPACK_VERSION_MAJOR * 10000) + \
1906 (MPACK_VERSION_MINOR * 100) + MPACK_VERSION_PATCH)
1909#define MPACK_VERSION_AT_LEAST(major, minor, patch) \
1910 (MPACK_VERSION >= (((major) * 10000) + ((minor) * 100) + (patch)))
1913#if (MPACK_VERSION_PATCH > 0)
1914#define MPACK_VERSION_STRING_BASE \
1915 MPACK_STRINGIFY(MPACK_VERSION_MAJOR) "." \
1916 MPACK_STRINGIFY(MPACK_VERSION_MINOR) "." \
1917 MPACK_STRINGIFY(MPACK_VERSION_PATCH)
1919#define MPACK_VERSION_STRING_BASE \
1920 MPACK_STRINGIFY(MPACK_VERSION_MAJOR) "." \
1921 MPACK_STRINGIFY(MPACK_VERSION_MINOR)
1931#if MPACK_RELEASE_VERSION
1932#define MPACK_VERSION_STRING MPACK_VERSION_STRING_BASE
1934#define MPACK_VERSION_STRING MPACK_VERSION_STRING_BASE "dev"
1944#define MPACK_LIBRARY_STRING "MPack " MPACK_VERSION_STRING "-debug"
1946#define MPACK_LIBRARY_STRING "MPack " MPACK_VERSION_STRING
1955#define MPACK_MAXIMUM_TAG_SIZE 9
1966#define MPACK_TIMESTAMP_NANOSECONDS_MAX 999999999
1971#if MPACK_COMPATIBILITY
1981typedef enum mpack_version_t {
1986 mpack_version_v4 = 4,
1991 mpack_version_v5 = 5,
1996 mpack_version_current = mpack_version_v5,
2047 #if MPACK_EXTENSIONS
2069typedef struct mpack_timestamp_t {
2071 uint32_t nanoseconds;
2094 #if MPACK_EXTENSIONS
2140#define MPACK_TAG_ZERO {(mpack_type_t)0, 0, {0}}
2142#define MPACK_TAG_ZERO {(mpack_type_t)0, {0}}
2197MPACK_INLINE
mpack_tag_t mpack_tag_make_raw_float(uint32_t value)
2211MPACK_INLINE
mpack_tag_t mpack_tag_make_raw_double(uint64_t value)
2258MPACK_INLINE
mpack_tag_t mpack_tag_make_ext(int8_t exttype, uint32_t length) {
2260 ret.type = mpack_type_ext;
2261 ret.exttype = exttype;
2346uint32_t mpack_tag_raw_float_value(
mpack_tag_t* tag)
2368uint64_t mpack_tag_raw_double_value(
mpack_tag_t* tag)
2438MPACK_INLINE uint32_t mpack_tag_ext_length(
mpack_tag_t* tag) {
2439 mpack_assert(tag->type == mpack_type_ext,
"tag is not an ext!");
2453MPACK_INLINE int8_t mpack_tag_ext_exttype(
mpack_tag_t* tag) {
2454 mpack_assert(tag->type == mpack_type_ext,
"tag is not an ext!");
2455 return tag->exttype;
2471 #if MPACK_EXTENSIONS
2473 || tag->type == mpack_type_ext,
"tag is not a str, bin or ext!");
2476 "tag is not a str or bin!");
2496#define MPACK_EXTTYPE_TIMESTAMP ((int8_t)(-1))
2535#if MPACK_DEBUG && MPACK_STDIO
2545void mpack_tag_debug_pseudo_json(
mpack_tag_t tag,
char* buffer,
size_t buffer_size,
2546 const char* prefix,
size_t prefix_size);
2554void mpack_tag_debug_describe(
mpack_tag_t tag,
char* buffer,
size_t buffer_size);
2563typedef void (*mpack_print_callback_t)(
void* context,
const char* data,
size_t count);
2567typedef struct mpack_print_t {
2571 mpack_print_callback_t callback;
2575void mpack_print_append(mpack_print_t*
print,
const char* data,
size_t count);
2577MPACK_INLINE
void mpack_print_append_cstr(mpack_print_t*
print,
const char* cstr) {
2578 mpack_print_append(
print, cstr, mpack_strlen(cstr));
2581void mpack_print_flush(mpack_print_t*
print);
2583void mpack_print_file_callback(
void* context,
const char* data,
size_t count);
2674MPACK_INLINE
mpack_tag_t mpack_tag_ext(int8_t exttype, int32_t length) {
2675 return mpack_tag_make_ext(exttype, (uint32_t)length);
2694MPACK_INLINE uint8_t mpack_load_u8(
const char* p) {
2695 return (uint8_t)p[0];
2698MPACK_INLINE uint16_t mpack_load_u16(
const char* p) {
2699 #ifdef MPACK_NHSWAP16
2701 mpack_memcpy(&val, p,
sizeof(val));
2702 return MPACK_NHSWAP16(val);
2704 return (uint16_t)((((uint16_t)(uint8_t)p[0]) << 8) |
2705 ((uint16_t)(uint8_t)p[1]));
2709MPACK_INLINE uint32_t mpack_load_u32(
const char* p) {
2710 #ifdef MPACK_NHSWAP32
2712 mpack_memcpy(&val, p,
sizeof(val));
2713 return MPACK_NHSWAP32(val);
2715 return (((uint32_t)(uint8_t)p[0]) << 24) |
2716 (((uint32_t)(uint8_t)p[1]) << 16) |
2717 (((uint32_t)(uint8_t)p[2]) << 8) |
2718 ((uint32_t)(uint8_t)p[3]);
2722MPACK_INLINE uint64_t mpack_load_u64(
const char* p) {
2723 #ifdef MPACK_NHSWAP64
2725 mpack_memcpy(&val, p,
sizeof(val));
2726 return MPACK_NHSWAP64(val);
2728 return (((uint64_t)(uint8_t)p[0]) << 56) |
2729 (((uint64_t)(uint8_t)p[1]) << 48) |
2730 (((uint64_t)(uint8_t)p[2]) << 40) |
2731 (((uint64_t)(uint8_t)p[3]) << 32) |
2732 (((uint64_t)(uint8_t)p[4]) << 24) |
2733 (((uint64_t)(uint8_t)p[5]) << 16) |
2734 (((uint64_t)(uint8_t)p[6]) << 8) |
2735 ((uint64_t)(uint8_t)p[7]);
2739MPACK_INLINE
void mpack_store_u8(
char* p, uint8_t val) {
2740 uint8_t* u = (uint8_t*)p;
2744MPACK_INLINE
void mpack_store_u16(
char* p, uint16_t val) {
2745 #ifdef MPACK_NHSWAP16
2746 val = MPACK_NHSWAP16(val);
2747 mpack_memcpy(p, &val,
sizeof(val));
2749 uint8_t* u = (uint8_t*)p;
2750 u[0] = (uint8_t)((val >> 8) & 0xFF);
2751 u[1] = (uint8_t)( val & 0xFF);
2755MPACK_INLINE
void mpack_store_u32(
char* p, uint32_t val) {
2756 #ifdef MPACK_NHSWAP32
2757 val = MPACK_NHSWAP32(val);
2758 mpack_memcpy(p, &val,
sizeof(val));
2760 uint8_t* u = (uint8_t*)p;
2761 u[0] = (uint8_t)((val >> 24) & 0xFF);
2762 u[1] = (uint8_t)((val >> 16) & 0xFF);
2763 u[2] = (uint8_t)((val >> 8) & 0xFF);
2764 u[3] = (uint8_t)( val & 0xFF);
2768MPACK_INLINE
void mpack_store_u64(
char* p, uint64_t val) {
2769 #ifdef MPACK_NHSWAP64
2770 val = MPACK_NHSWAP64(val);
2771 mpack_memcpy(p, &val,
sizeof(val));
2773 uint8_t* u = (uint8_t*)p;
2774 u[0] = (uint8_t)((val >> 56) & 0xFF);
2775 u[1] = (uint8_t)((val >> 48) & 0xFF);
2776 u[2] = (uint8_t)((val >> 40) & 0xFF);
2777 u[3] = (uint8_t)((val >> 32) & 0xFF);
2778 u[4] = (uint8_t)((val >> 24) & 0xFF);
2779 u[5] = (uint8_t)((val >> 16) & 0xFF);
2780 u[6] = (uint8_t)((val >> 8) & 0xFF);
2781 u[7] = (uint8_t)( val & 0xFF);
2785MPACK_INLINE int8_t mpack_load_i8 (
const char* p) {
return (int8_t) mpack_load_u8 (p);}
2786MPACK_INLINE int16_t mpack_load_i16(
const char* p) {
return (int16_t)mpack_load_u16(p);}
2787MPACK_INLINE int32_t mpack_load_i32(
const char* p) {
return (int32_t)mpack_load_u32(p);}
2788MPACK_INLINE int64_t mpack_load_i64(
const char* p) {
return (int64_t)mpack_load_u64(p);}
2789MPACK_INLINE
void mpack_store_i8 (
char* p, int8_t val) {mpack_store_u8 (p, (uint8_t) val);}
2790MPACK_INLINE
void mpack_store_i16(
char* p, int16_t val) {mpack_store_u16(p, (uint16_t)val);}
2791MPACK_INLINE
void mpack_store_i32(
char* p, int32_t val) {mpack_store_u32(p, (uint32_t)val);}
2792MPACK_INLINE
void mpack_store_i64(
char* p, int64_t val) {mpack_store_u64(p, (uint64_t)val);}
2795MPACK_INLINE
float mpack_load_float(
const char* p) {
2796 MPACK_CHECK_FLOAT_ORDER();
2797 MPACK_STATIC_ASSERT(
sizeof(
float) ==
sizeof(uint32_t),
"float is wrong size??");
2802 v.u = mpack_load_u32(p);
2808MPACK_INLINE
double mpack_load_double(
const char* p) {
2809 MPACK_CHECK_FLOAT_ORDER();
2810 MPACK_STATIC_ASSERT(
sizeof(
double) ==
sizeof(uint64_t),
"double is wrong size??");
2815 v.u = mpack_load_u64(p);
2821MPACK_INLINE
void mpack_store_float(
char* p,
float value) {
2822 MPACK_CHECK_FLOAT_ORDER();
2828 mpack_store_u32(p, v.u);
2833MPACK_INLINE
void mpack_store_double(
char* p,
double value) {
2834 MPACK_CHECK_FLOAT_ORDER();
2840 mpack_store_u64(p, v.u);
2844#if MPACK_FLOAT && !MPACK_DOUBLE
2854MPACK_INLINE
float mpack_shorten_raw_double_to_float(uint64_t d) {
2855 MPACK_CHECK_FLOAT_ORDER();
2864 uint64_t d_sign = (uint64_t)(d >> 63);
2865 uint64_t d_exponent = (uint32_t)(d >> 52) & ((1 << 11) - 1);
2866 uint64_t d_significand = d & (((uint64_t)1 << 52) - 1);
2868 uint32_t f_sign = (uint32_t)d_sign;
2869 uint32_t f_exponent;
2870 uint32_t f_significand;
2872 if (MPACK_UNLIKELY(d_exponent == ((1 << 11) - 1))) {
2876 f_exponent = ((1 << 8) - 1);
2877 f_significand = (uint32_t)(d_significand >> 29) | (d_significand ? 1 : 0);
2880 int fix_bias = (int)d_exponent - ((1 << 10) - 1) + ((1 << 7) - 1);
2881 if (MPACK_UNLIKELY(fix_bias <= 0)) {
2885 }
else if (MPACK_UNLIKELY(fix_bias > 0xff)) {
2891 f_exponent = (uint32_t)fix_bias;
2892 f_significand = (uint32_t)(d_significand >> 29);
2897 printf(
"\n===============\n");
2898 for (
size_t i = 0; i < 64; ++i)
2899 printf(
"%i%s",(
int)((d>>(63-i))&1),((i%8)==7)?
" ":
"");
2900 printf(
"\n%lu %lu %lu\n", d_sign, d_exponent, d_significand);
2901 printf(
"%u %u %u\n", f_sign, f_exponent, f_significand);
2904 v.u = (f_sign << 31) | (f_exponent << 23) | f_significand;
2916#define MPACK_TAG_SIZE_FIXUINT 1
2917#define MPACK_TAG_SIZE_U8 2
2918#define MPACK_TAG_SIZE_U16 3
2919#define MPACK_TAG_SIZE_U32 5
2920#define MPACK_TAG_SIZE_U64 9
2921#define MPACK_TAG_SIZE_FIXINT 1
2922#define MPACK_TAG_SIZE_I8 2
2923#define MPACK_TAG_SIZE_I16 3
2924#define MPACK_TAG_SIZE_I32 5
2925#define MPACK_TAG_SIZE_I64 9
2926#define MPACK_TAG_SIZE_FLOAT 5
2927#define MPACK_TAG_SIZE_DOUBLE 9
2928#define MPACK_TAG_SIZE_FIXARRAY 1
2929#define MPACK_TAG_SIZE_ARRAY16 3
2930#define MPACK_TAG_SIZE_ARRAY32 5
2931#define MPACK_TAG_SIZE_FIXMAP 1
2932#define MPACK_TAG_SIZE_MAP16 3
2933#define MPACK_TAG_SIZE_MAP32 5
2934#define MPACK_TAG_SIZE_FIXSTR 1
2935#define MPACK_TAG_SIZE_STR8 2
2936#define MPACK_TAG_SIZE_STR16 3
2937#define MPACK_TAG_SIZE_STR32 5
2938#define MPACK_TAG_SIZE_BIN8 2
2939#define MPACK_TAG_SIZE_BIN16 3
2940#define MPACK_TAG_SIZE_BIN32 5
2941#define MPACK_TAG_SIZE_FIXEXT1 2
2942#define MPACK_TAG_SIZE_FIXEXT2 2
2943#define MPACK_TAG_SIZE_FIXEXT4 2
2944#define MPACK_TAG_SIZE_FIXEXT8 2
2945#define MPACK_TAG_SIZE_FIXEXT16 2
2946#define MPACK_TAG_SIZE_EXT8 3
2947#define MPACK_TAG_SIZE_EXT16 4
2948#define MPACK_TAG_SIZE_EXT32 6
2951#define MPACK_EXT_SIZE_TIMESTAMP4 (MPACK_TAG_SIZE_FIXEXT4 + 4)
2952#define MPACK_EXT_SIZE_TIMESTAMP8 (MPACK_TAG_SIZE_FIXEXT8 + 8)
2953#define MPACK_EXT_SIZE_TIMESTAMP12 (MPACK_TAG_SIZE_EXT8 + 12)
2959#if MPACK_READ_TRACKING || MPACK_WRITE_TRACKING
2964typedef struct mpack_track_element_t {
2971 bool key_needs_value;
2976} mpack_track_element_t;
2978typedef struct mpack_track_t {
2981 mpack_track_element_t* elements;
2996mpack_error_t mpack_track_destroy(mpack_track_t* track,
bool cancel);
3014bool mpack_utf8_check(
const char* str,
size_t bytes);
3019bool mpack_utf8_check_no_null(
const char* str,
size_t bytes);
3024bool mpack_str_check_no_null(
const char* str,
size_t bytes);
3038MPACK_SILENCE_WARNINGS_END
3051#ifndef MPACK_WRITER_H
3052#define MPACK_WRITER_H 1
3058MPACK_SILENCE_WARNINGS_BEGIN
3061#if MPACK_WRITE_TRACKING
3062struct mpack_track_t;
3079#define MPACK_WRITER_MINIMUM_BUFFER_SIZE 32
3143typedef struct mpack_builder_page_t {
3144 struct mpack_builder_page_t* next;
3146} mpack_builder_page_t;
3152typedef struct mpack_build_t {
3154 struct mpack_build_t* parent;
3163 uint32_t nested_compound_elements;
3168 bool key_needs_value;
3174typedef struct mpack_builder_t {
3175 mpack_build_t* current_build;
3176 mpack_build_t* latest_build;
3177 mpack_builder_page_t* current_page;
3178 mpack_builder_page_t* pages;
3180 char* stash_position;
3182 #if MPACK_BUILDER_INTERNAL_STORAGE
3189 #if MPACK_COMPATIBILITY
3190 mpack_version_t version;
3202 #if MPACK_WRITE_TRACKING
3203 mpack_track_t track;
3213 mpack_builder_t builder;
3218#if MPACK_WRITE_TRACKING
3226 MPACK_UNUSED(writer);
3228 MPACK_UNUSED(
count);
3231 MPACK_UNUSED(writer);
3235 MPACK_UNUSED(writer);
3239 MPACK_UNUSED(writer);
3243 MPACK_UNUSED(writer);
3244 MPACK_UNUSED(
count);
3335#define mpack_writer_init_stack_line_ex(line, writer) \
3336 char mpack_buf_##line[MPACK_STACK_SIZE]; \
3337 mpack_writer_init(writer, mpack_buf_##line, sizeof(mpack_buf_##line))
3339#define mpack_writer_init_stack_line(line, writer) \
3340 mpack_writer_init_stack_line_ex(line, writer)
3349#define mpack_writer_init_stack(writer) \
3350 mpack_writer_init_stack_line(__LINE__, (writer))
3391#if MPACK_COMPATIBILITY
3400MPACK_INLINE
void mpack_writer_set_version(
mpack_writer_t* writer, mpack_version_t version) {
3401 writer->version = version;
3415 writer->context = context;
3425 return writer->context;
3458 writer->error_fn = error_fn;
3471 writer->teardown = teardown;
3509 return (
size_t)(writer->position - writer->buffer);
3517 return (
size_t)(writer->end - writer->position);
3525 return (
size_t)(writer->end - writer->buffer);
3553 return writer->error;
3631void mpack_write_raw_float(
mpack_writer_t* writer, uint32_t raw_value);
3639void mpack_write_raw_double(
mpack_writer_t* writer, uint64_t raw_value);
3667void mpack_write_timestamp(
mpack_writer_t* writer, int64_t seconds, uint32_t nanoseconds);
3677MPACK_INLINE
void mpack_write_timestamp_seconds(
mpack_writer_t* writer, int64_t seconds) {
3678 mpack_write_timestamp(writer, seconds, 0);
3686MPACK_INLINE
void mpack_write_timestamp_struct(
mpack_writer_t* writer, mpack_timestamp_t timestamp) {
3687 mpack_write_timestamp(writer, timestamp.seconds, timestamp.nanoseconds);
3733 MPACK_UNUSED(writer);
3736 mpack_build_t* build = writer->builder.current_build;
3737 if (build != NULL) {
3738 ++build->nested_compound_elements;
3744 MPACK_UNUSED(writer);
3747 mpack_build_t* build = writer->builder.current_build;
3748 if (build != NULL) {
3749 mpack_assert(build->nested_compound_elements > 0);
3750 --build->nested_compound_elements;
3978void mpack_write_ext(
mpack_writer_t* writer, int8_t exttype,
const char* data, uint32_t
count);
4093 mpack_writer_track_pop(writer, mpack_type_ext);
4107 mpack_writer_track_pop(writer,
type);
4114#if MPACK_HAS_GENERIC && !defined(__cplusplus)
4137 #define MPACK_WRITE_GENERIC_FLOAT float: mpack_write_float,
4139 #define MPACK_WRITE_GENERIC_FLOAT
4142 #define MPACK_WRITE_GENERIC_DOUBLE double: mpack_write_double,
4144 #define MPACK_WRITE_GENERIC_DOUBLE
4146#define mpack_write(writer, value) \
4147 _Generic(((void)0, value), \
4148 int8_t: mpack_write_i8, \
4149 int16_t: mpack_write_i16, \
4150 int32_t: mpack_write_i32, \
4151 int64_t: mpack_write_i64, \
4152 uint8_t: mpack_write_u8, \
4153 uint16_t: mpack_write_u16, \
4154 uint32_t: mpack_write_u32, \
4155 uint64_t: mpack_write_u64, \
4156 bool: mpack_write_bool, \
4157 MPACK_WRITE_GENERIC_FLOAT \
4158 MPACK_WRITE_GENERIC_DOUBLE \
4159 char *: mpack_write_cstr_or_nil, \
4160 const char *: mpack_write_cstr_or_nil \
4179#define mpack_write_kv(writer, key, value) do { \
4180 mpack_write_cstr(writer, key); \
4181 mpack_write(writer, value); \
4193#if defined(__cplusplus) || defined(MPACK_DOXYGEN)
4207#undef mpack_write_kv
4339MPACK_SILENCE_WARNINGS_END
4353#ifndef MPACK_READER_H
4354#define MPACK_READER_H 1
4358MPACK_SILENCE_WARNINGS_BEGIN
4363#if MPACK_READ_TRACKING
4364struct mpack_track_t;
4369#define MPACK_READER_SMALL_FRACTION_DENOMINATOR 32
4395#define MPACK_READER_MINIMUM_BUFFER_SIZE 32
4490 #if MPACK_READ_TRACKING
4491 mpack_track_t track;
4575#define mpack_reader_init_stack_line_ex(line, reader) \
4576 char mpack_buf_##line[MPACK_STACK_SIZE]; \
4577 mpack_reader_init((reader), mpack_buf_##line, sizeof(mpack_buf_##line), 0)
4579#define mpack_reader_init_stack_line(line, reader) \
4580 mpack_reader_init_stack_line_ex(line, reader)
4583#define mpack_reader_init_stack(reader) \
4584 mpack_reader_init_stack_line(__LINE__, (reader))
4621 reader->context = context;
4632 return reader->context;
4686 reader->error_fn = error_fn;
4699 reader->teardown = teardown;
4718 return reader->error;
4935char* mpack_read_bytes_alloc_impl(
mpack_reader_t* reader,
size_t count,
bool null_terminated);
4948 return mpack_read_bytes_alloc_impl(reader,
count,
false);
5055mpack_timestamp_t mpack_read_timestamp(
mpack_reader_t* reader,
size_t size);
5067#if MPACK_READ_TRACKING
5077 MPACK_UNUSED(reader);
5151#if MPACK_DEBUG && MPACK_STDIO
5166void mpack_print_data_to_buffer(
const char* data,
size_t data_size,
char* buffer,
size_t buffer_size);
5177void mpack_print_data_to_callback(
const char* data,
size_t size, mpack_print_callback_t callback,
void* context);
5183void mpack_print_data_to_file(
const char* data,
size_t len, FILE*
file);
5189MPACK_INLINE
void mpack_print_data_to_stdout(
const char* data,
size_t len) {
5190 mpack_print_data_to_file(data, len, stdout);
5198void mpack_print_stdfile_to_callback(FILE*
file, mpack_print_callback_t callback,
void* context);
5205MPACK_INLINE
void mpack_print(
const char* data,
size_t len) {
5206 mpack_print_data_to_stdout(data, len);
5232 mpack_assert(
count != 0,
"cannot ensure zero bytes!");
5233 mpack_assert(reader->error ==
mpack_ok,
"reader cannot be in an error state!");
5235 if (
count <= (
size_t)(reader->end - reader->data))
5237 return mpack_reader_ensure_straddle(reader,
count);
5245 mpack_assert(
count == 0 || p != NULL,
"data pointer for %i bytes is NULL", (
int)
count);
5247 if (
count > (
size_t)(reader->end - reader->data)) {
5248 mpack_read_native_straddle(reader, p,
count);
5250 mpack_memcpy(p, reader->data,
count);
5251 reader->data +=
count;
5255#if MPACK_READ_TRACKING
5256#define MPACK_READER_TRACK(reader, error_expr) \
5257 (((reader)->error == mpack_ok) ? mpack_reader_flag_if_error((reader), (error_expr)) : (reader)->error)
5259#define MPACK_READER_TRACK(reader, error_expr) (MPACK_UNUSED(reader), mpack_ok)
5263 return MPACK_READER_TRACK(reader, mpack_track_element(&reader->track,
true));
5267 return MPACK_READER_TRACK(reader, mpack_track_peek_element(&reader->track,
true));
5271 MPACK_UNUSED(
count);
5272 return MPACK_READER_TRACK(reader, mpack_track_bytes(&reader->track,
true,
count));
5276 MPACK_UNUSED(
count);
5277 return MPACK_READER_TRACK(reader, mpack_track_str_bytes_all(&reader->track,
true,
count));
5287MPACK_SILENCE_WARNINGS_END
5300#ifndef MPACK_EXPECT_H
5301#define MPACK_EXPECT_H 1
5305MPACK_SILENCE_WARNINGS_BEGIN
5311#error "MPACK_EXPECT requires MPACK_READER."
5548 if (
sizeof(
unsigned int) == 4)
5664 if (
sizeof(
int) == 4)
5785 if (
sizeof(
unsigned int) == 4)
5804 if (
sizeof(
int) == 4)
6149#define mpack_expect_array_alloc(reader, Type, max_count, out_count) \
6150 ((Type*)mpack_expect_array_alloc_impl(reader, sizeof(Type), max_count, out_count, false))
6177#define mpack_expect_array_or_nil_alloc(reader, Type, max_count, out_count) \
6178 ((Type*)mpack_expect_array_alloc_impl(reader, sizeof(Type), max_count, out_count, true))
6188 size_t element_size, uint32_t max_count, uint32_t* out_count,
bool allow_nil);
6252 if (length > maxsize) {
6353 mpack_assert(cstr != NULL,
"cstr pointer is NULL");
6390 if (length > maxsize) {
6501MPACK_INLINE uint32_t mpack_expect_ext_max(
mpack_reader_t* reader, int8_t*
type, uint32_t maxsize) {
6502 uint32_t length = mpack_expect_ext(reader,
type);
6503 if (length > maxsize) {
6537 if (mpack_expect_ext(reader,
type) !=
count) {
6565size_t mpack_expect_ext_buf(
mpack_reader_t* reader, int8_t*
type,
char* buf,
size_t size);
6568#if MPACK_EXTENSIONS && defined(MPACK_MALLOC)
6591char* mpack_expect_ext_alloc(
mpack_reader_t* reader, int8_t*
type,
size_t maxsize,
size_t* size);
6745 bool found[],
size_t count);
6758MPACK_SILENCE_WARNINGS_END
6773#define MPACK_NODE_H 1
6777MPACK_SILENCE_WARNINGS_BEGIN
6926typedef struct mpack_tree_page_t {
6927 struct mpack_tree_page_t* next;
6931typedef enum mpack_tree_parse_state_t {
6932 mpack_tree_parse_state_not_started,
6933 mpack_tree_parse_state_in_progress,
6934 mpack_tree_parse_state_parsed,
6935} mpack_tree_parse_state_t;
6937typedef struct mpack_level_t {
6942typedef struct mpack_tree_parser_t {
6943 mpack_tree_parse_state_t
state;
6963 size_t possible_nodes_left;
6968 size_t current_node_reserved;
6974 mpack_level_t* stack;
6975 size_t stack_capacity;
6983} mpack_tree_parser_t;
6997 size_t buffer_capacity;
7009 mpack_tree_parser_t parser;
7016 mpack_tree_page_t* next;
7030 return node.data->value.children + child;
7034 return mpack_node(tree, &tree->nil_node);
7038 return mpack_node(tree, &tree->missing_node);
7102 size_t max_message_size,
size_t max_message_nodes);
7196 size_t max_message_nodes);
7285 tree->context = context;
7295 return tree->context;
7312 tree->error_fn = error_fn;
7325 tree->teardown = teardown;
7376#if MPACK_DEBUG && MPACK_STDIO
7387void mpack_node_print_to_buffer(
mpack_node_t node,
char* buffer,
size_t buffer_size);
7398void mpack_node_print_to_callback(
mpack_node_t node, mpack_print_callback_t callback,
void* context);
7416MPACK_INLINE
void mpack_node_print_to_stdout(
mpack_node_t node) {
7417 mpack_node_print_to_file(node, stdout);
7426 mpack_node_print_to_stdout(node);
7637mpack_timestamp_t mpack_node_timestamp(
mpack_node_t node);
7646int64_t mpack_node_timestamp_seconds(
mpack_node_t node);
7656uint32_t mpack_node_timestamp_nanoseconds(
mpack_node_t node);
8212MPACK_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:192
Definition: format.h:4134
struct mpack_tag_t mpack_tag_t
An MPack tag is a MessagePack object header.
Definition: mpack.h:2087
MPACK_INLINE mpack_tag_t mpack_tag_array(int32_t count)
Definition: mpack.h:2653
MPACK_INLINE mpack_tag_t mpack_tag_make_double(double value)
Generates a double tag.
Definition: mpack.h:2208
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:2470
#define MPACK_TAG_ZERO
An mpack_tag_t initializer that zeroes the given tag.
Definition: mpack.h:2142
MPACK_INLINE mpack_tag_t mpack_tag_false(void)
Definition: mpack.h:2624
MPACK_INLINE mpack_tag_t mpack_tag_int(int64_t value)
Definition: mpack.h:2629
mpack_type_t
Defines the type of a MessagePack tag.
Definition: mpack.h:2034
MPACK_INLINE mpack_tag_t mpack_tag_make_uint(uint64_t value)
Generates an unsigned int tag.
Definition: mpack.h:2185
MPACK_INLINE mpack_tag_t mpack_tag_make_false(void)
Generates a bool tag with value false.
Definition: mpack.h:2169
MPACK_INLINE mpack_tag_t mpack_tag_uint(uint64_t value)
Definition: mpack.h:2634
MPACK_INLINE mpack_tag_t mpack_tag_bool(bool value)
Definition: mpack.h:2614
MPACK_INLINE mpack_tag_t mpack_tag_nil(void)
Definition: mpack.h:2609
MPACK_INLINE bool mpack_tag_equal(mpack_tag_t left, mpack_tag_t right)
Compares two tags for equality.
Definition: mpack.h:2531
MPACK_INLINE mpack_tag_t mpack_tag_make_array(uint32_t count)
Generates an array tag.
Definition: mpack.h:2221
MPACK_INLINE mpack_tag_t mpack_tag_make_true(void)
Generates a bool tag with value true.
Definition: mpack.h:2161
MPACK_INLINE float mpack_tag_float_value(mpack_tag_t *tag)
Gets the float value of a float-type tag.
Definition: mpack.h:2344
MPACK_INLINE mpack_tag_t mpack_tag_make_nil(void)
Generates a nil tag.
Definition: mpack.h:2146
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:2663
MPACK_INLINE double mpack_tag_double_value(mpack_tag_t *tag)
Gets the double value of a double-type tag.
Definition: mpack.h:2366
MPACK_INLINE mpack_tag_t mpack_tag_make_str(uint32_t length)
Generates a str tag.
Definition: mpack.h:2237
MPACK_INLINE mpack_tag_t mpack_tag_bin(int32_t length)
Definition: mpack.h:2668
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:2422
MPACK_INLINE mpack_tag_t mpack_tag_true(void)
Definition: mpack.h:2619
MPACK_INLINE mpack_tag_t mpack_tag_map(int32_t count)
Definition: mpack.h:2658
MPACK_INLINE mpack_tag_t mpack_tag_make_int(int64_t value)
Generates a signed int tag.
Definition: mpack.h:2177
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:2290
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:2326
MPACK_INLINE mpack_type_t mpack_tag_type(mpack_tag_t *tag)
Gets the type of a tag.
Definition: mpack.h:2279
MPACK_INLINE mpack_tag_t mpack_tag_make_float(float value)
Generates a float tag.
Definition: mpack.h:2194
mpack_error_t
Error states for MPack objects.
Definition: mpack.h:2008
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:2308
MPACK_INLINE mpack_tag_t mpack_tag_make_map(uint32_t count)
Generates a map tag.
Definition: mpack.h:2229
MPACK_INLINE mpack_tag_t mpack_tag_double(double value)
Definition: mpack.h:2647
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:2640
MPACK_INLINE mpack_tag_t mpack_tag_make_bool(bool value)
Generates a bool tag.
Definition: mpack.h:2153
MPACK_INLINE uint32_t mpack_tag_array_count(mpack_tag_t *tag)
Gets the number of elements in an array tag.
Definition: mpack.h:2383
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:2409
MPACK_INLINE mpack_tag_t mpack_tag_make_bin(uint32_t length)
Generates a bin tag.
Definition: mpack.h:2245
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:2396
@ mpack_type_bool
A boolean (true or false.)
Definition: mpack.h:2037
@ mpack_type_map
An ordered map of key/value pairs of MessagePack objects.
Definition: mpack.h:2045
@ mpack_type_missing
Special type indicating a missing optional value.
Definition: mpack.h:2035
@ mpack_type_str
A string.
Definition: mpack.h:2042
@ mpack_type_double
A 64-bit IEEE 754 floating point number.
Definition: mpack.h:2041
@ mpack_type_bin
A chunk of binary data.
Definition: mpack.h:2043
@ mpack_type_nil
A null value.
Definition: mpack.h:2036
@ mpack_type_float
A 32-bit IEEE 754 floating point number.
Definition: mpack.h:2040
@ mpack_type_int
A 64-bit signed integer.
Definition: mpack.h:2038
@ mpack_type_array
An array of MessagePack objects.
Definition: mpack.h:2044
@ mpack_type_uint
A 64-bit unsigned integer.
Definition: mpack.h:2039
@ mpack_error_eof
The reader failed to read because of file or socket EOF.
Definition: mpack.h:2018
@ mpack_error_memory
An allocation failure occurred.
Definition: mpack.h:2015
@ mpack_error_too_big
A read or write was bigger than the maximum size allowed for that operation.
Definition: mpack.h:2014
@ mpack_ok
No error.
Definition: mpack.h:2009
@ mpack_error_io
The reader or writer failed to fill or flush, or some other file or socket error occurred.
Definition: mpack.h:2010
@ mpack_error_invalid
The data read is not valid MessagePack.
Definition: mpack.h:2011
@ mpack_error_unsupported
The data read is not supported by this configuration of MPack.
Definition: mpack.h:2012
@ mpack_error_type
The type or value range did not match what was expected by the caller.
Definition: mpack.h:2013
@ mpack_error_bug
The MPack API was used incorrectly.
Definition: mpack.h:2016
@ mpack_error_data
The contained data is not valid.
Definition: mpack.h:2017
#define MPACK_REALLOC
Defines the realloc function used by MPack.
Definition: mpack.h:488
#define MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC
The maximum depth for the node parser if MPACK_MALLOC is not available.
Definition: mpack.h:890
#define MPACK_NODE_INITIAL_DEPTH
The initial depth for the node parser.
Definition: mpack.h:883
#define MPACK_BUILDER_INTERNAL_STORAGE_SIZE
Amount of space reserved inside mpack_writer_t for the Builders.
Definition: mpack.h:874
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:5545
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:5561
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:5678
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:5964
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:5729
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:5691
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:6270
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:5661
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:5704
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:6074
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:6250
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:6388
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:5801
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:5782
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:5585
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:6408
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:5609
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:5597
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:5573
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:6352
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:5717
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:6808
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:6853
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:6881
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:7284
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:6819
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:7253
MPACK_INLINE void mpack_tree_init_file(mpack_tree_t *tree, const char *filename, size_t max_bytes)
Deprecated.
Definition: mpack.h:7145
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:7294
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:7070
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:7324
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:6827
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:7267
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:7364
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:7311
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:6876
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:4620
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:3311
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:4743
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:5087
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:4543
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:5076
void(* mpack_reader_skip_t)(mpack_reader_t *reader, size_t count)
The MPack reader's skip function.
Definition: mpack.h:4439
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:4465
MPACK_INLINE void * mpack_reader_context(mpack_reader_t *reader)
Returns the custom context for reader callbacks.
Definition: mpack.h:4631
MPACK_INLINE mpack_error_t mpack_reader_error(mpack_reader_t *reader)
Queries the error state of the MPack reader.
Definition: mpack.h:4717
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:5098
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:4947
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:4429
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:4685
MPACK_INLINE void mpack_done_bin(mpack_reader_t *reader)
Finishes reading a binary data blob.
Definition: mpack.h:5120
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:5109
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:5034
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:4470
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:4410
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:4698
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:3766
MPACK_INLINE void * mpack_writer_context(mpack_writer_t *writer)
Returns the custom context for writer callbacks.
Definition: mpack.h:3424
MPACK_INLINE mpack_error_t mpack_writer_error(mpack_writer_t *writer)
Queries the error state of the MPack writer.
Definition: mpack.h:3552
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:3470
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:3596
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:3782
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:3613
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:3524
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:3125
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:3732
MPACK_INLINE void mpack_finish_type(mpack_writer_t *writer, mpack_type_t type)
Finishes writing the given compound type.
Definition: mpack.h:4106
void(* mpack_writer_teardown_t)(mpack_writer_t *writer)
A teardown function to be called when the writer is destroyed.
Definition: mpack.h:3130
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:3743
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:3516
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:3457
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:3090
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:3508
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:3099
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:4059
MPACK_INLINE void mpack_finish_bin(mpack_writer_t *writer)
Finishes writing a binary blob.
Definition: mpack.h:4074
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:3414
void print(wpi::raw_ostream &os, const S &format_str, Args &&... args)
Prints formatted data to the stream os.
Definition: raw_ostream.h:25
#define MPACK_READER_SMALL_FRACTION_DENOMINATOR
Definition: mpack.h:4369
constexpr auto max_value() -> T
Definition: format.h:489
@ value
the parser finished reading a JSON value
FMT_NOINLINE FMT_CONSTEXPR auto fill(OutputIt it, size_t n, const fill_t< Char > &fill) -> OutputIt
Definition: format.h:1779
@ error
throw a parse_error exception in case of a tag
constexpr auto count() -> size_t
Definition: core.h:1203
state
Definition: core.h:2271
type
Definition: core.h:556
Definition: MessagePack.h:15
MPACK_INLINE void mpack_write(mpack_writer_t *writer, int8_t value)
Definition: mpack.h:4210
MPACK_INLINE void mpack_write_kv(mpack_writer_t *writer, const char *key, int8_t value)
Definition: mpack.h:4264
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(string_view fmt, const T &... args) -> int
\rst Prints formatted data to stdout.
Definition: printf.h:655
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:108