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))