-
Notifications
You must be signed in to change notification settings - Fork 22
/
mpack-config.h
201 lines (170 loc) · 5.28 KB
/
mpack-config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* This is a sample MPack configuration file. Copy it to mpack-config.h somewhere
* in your project's include tree and, optionally, edit it to suit your setup.
* In most cases you can leave this file with the default config.
*/
#ifndef MPACK_CONFIG_H
#define MPACK_CONFIG_H 1
/*
* Features
*/
/** Enables compilation of the base Tag Reader. */
#define MPACK_READER 1
/** Enables compilation of the static Expect API. */
#define MPACK_EXPECT 1
/** Enables compilation of the dynamic Node API. */
#define MPACK_NODE 1
/** Enables compilation of the Writer. */
#define MPACK_WRITER 1
/*
* Dependencies
*/
/**
* Enables the use of C stdlib. This allows the library to use malloc
* for debugging and in allocation helpers.
*/
#define MPACK_STDLIB 1
/**
* Enables the use of C stdio. This adds helpers for easily
* reading/writing C files and makes debugging easier.
*/
#define MPACK_STDIO 1
/**
* \def MPACK_MALLOC
*
* Defines the memory allocation function used by mpack. This is used by
* helpers for automatically allocating data the correct size, and for
* debugging functions. If this macro is undefined, the allocation helpers
* will not be compiled.
*
* A memory allocator is required for the Node API.
*/
/**
* \def MPACK_REALLOC
*
* Defines the realloc function used by mpack. It is used by growable buffers
* to resize more quickly.
*
* This is optional, even when MPACK_MALLOC is used. If MPACK_MALLOC is
* set and MPACK_REALLOC is not, MPACK_MALLOC is used with a simple copy
* to grow buffers.
*/
#if defined(MPACK_STDLIB) && !defined(MPACK_MALLOC)
#define MPACK_MALLOC malloc
#define MPACK_REALLOC realloc
#endif
/**
* \def MPACK_FREE
*
* Defines the memory free function used by mpack. This is used by helpers
* for automatically allocating data the correct size. If this macro is
* undefined, the allocation helpers will not be compiled.
*
* A memory allocator is required for the Node API.
*/
#if defined(MPACK_STDLIB) && !defined(MPACK_FREE)
#define MPACK_FREE free
#endif
/**
* Enables the setjmp()/longjmp() error handling option. MPACK_MALLOC is required.
*
* Note that you don't have to use it; this just enables the option. It can be
* disabled to avoid the dependency on setjmp.h .
*/
#if defined(MPACK_MALLOC)
#define MPACK_SETJMP 1
#endif
/*
* Debugging options
*/
/**
* \def MPACK_DEBUG
*
* Enables debug features. You may want to wrap this around your
* own debug preprocs. By default, they are enabled if DEBUG or _DEBUG
* are defined.
*
* Note that MPACK_DEBUG cannot be defined differently for different
* source files because it affects layout of structs defined in header
* files. Your entire project must be compiled with the same value of
* MPACK_DEBUG. (This is why NDEBUG is not used.)
*/
#if defined(DEBUG) || defined(_DEBUG)
#define MPACK_DEBUG 1
#else
#define MPACK_DEBUG 0
#endif
/**
* Set this to 1 to implement a custom mpack_assert_fail() function. This
* function must not return, and must have the following signature:
*
* void mpack_assert_fail(const char* message)
*
* Asserts are only used when MPACK_DEBUG is enabled, and can be triggered
* by bugs in mpack or bugs due to incorrect usage of mpack.
*/
#define MPACK_CUSTOM_ASSERT 0
/**
* \def MPACK_READ_TRACKING
*
* Enables compound type size tracking for readers. This ensures that the
* correct number of elements or bytes are read from a compound type.
*
* This is enabled by default in debug builds (provided a malloc() is
* available.)
*/
#if MPACK_DEBUG && MPACK_READER && defined(MPACK_MALLOC)
#define MPACK_READ_TRACKING 1
#endif
/**
* \def MPACK_WRITE_TRACKING
*
* Enables compound type size tracking for writers. This ensures that the
* correct number of elements or bytes are written in a compound type.
*
* Note that without write tracking enabled, it is possible for buggy code
* to emit invalid MessagePack without flagging an error by writing the wrong
* number of elements or bytes in a compound type. With tracking enabled,
* MPACK will catch such errors and break on the offending line of code.
*
* This is enabled by default in debug builds (provided a malloc() is
* available.)
*/
#if MPACK_DEBUG && MPACK_WRITER && defined(MPACK_MALLOC)
#define MPACK_WRITE_TRACKING 1
#endif
/*
* Miscellaneous
*/
/**
* Stack space to use when initializing a reader or writer with a
* stack-allocated buffer.
*/
#define MPACK_STACK_SIZE 4096
/**
* Buffer size to use for allocated buffers (such as for a file writer.)
*/
#define MPACK_BUFFER_SIZE 65536
/**
* Number of nodes in each allocated node page.
*
* Nodes are 16 bytes when compiled for a 32-bit architecture and
* 24 bytes when compiled for a 64-bit architecture.
*
* Using as many nodes fit in one memory page seems to provide the
* best performance, and has very little waste when parsing small
* messages.
*/
#define MPACK_NODE_PAGE_SIZE (4096 / sizeof(mpack_node_t))
/**
* The initial depth for the node parser. When MPACK_MALLOC is available,
* the node parser has no practical depth limit, and it is not recursive
* so there is no risk of overflowing the call stack.
*/
#define MPACK_NODE_INITIAL_DEPTH 8
/**
* The maximum depth for the node parser if MPACK_MALLOC is not available.
* The parsing stack is placed on the call stack.
*/
#define MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC 32
#endif