Skip to content

Commit 752bc30

Browse files
committed
Various documentation updates
1 parent e435e76 commit 752bc30

File tree

11 files changed

+91
-86
lines changed

11 files changed

+91
-86
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ MPack is a C implementation of an encoder and decoder for the [MessagePack](http
88
* [Extensively documented](http://ludocode.github.io/mpack/)
99
* [Extremely fast](https://github.com/ludocode/schemaless-benchmarks#speed---desktop-pc)
1010

11-
The core of MPack contains a buffered reader and writer with a custom callback to fill or flush the buffer. Helper functions can be enabled to read values of expected type, to work with files, to allocate strings automatically, to check UTF-8 encoding, and more. The MPack featureset can be configured at compile-time to set which features, components and debug checks are compiled, and what dependencies are available.
11+
The core of MPack contains a buffered reader and writer, and a tree-style parser that decodes into a tree of dynamically typed nodes. Helper functions can be enabled to read values of expected type, to work with files, to allocate strings automatically, to check UTF-8 encoding, and more. The MPack featureset can be configured at compile-time to set which features, components and debug checks are compiled, and what dependencies are available.
1212

1313
The MPack code is small enough to be embedded directly into your codebase. The easiest way to use it is to download the [amalgamation package](https://github.com/ludocode/mpack/releases) and insert the source files directly into your project. Copy `mpack.h` and `mpack.c` into to your codebase, and copy `mpack-config.h.sample` as `mpack-config.h`. You can use the defaults or edit it if you'd like to customize the MPack featureset.
1414

@@ -53,6 +53,8 @@ if (mpack_tree_destroy(tree) != mpack_ok) {
5353
5454
Note that no additional error handling is needed in the above code. If the file is missing or corrupt, if map keys are missing or if nodes are not in the expected types, special "nil" nodes and false/zero values are returned and the tree is placed in an error state. An error check is only needed before using the data.
5555
56+
The above example decodes into allocated pages of nodes. A fixed node pool can be provided to the parser instead in memory-constrained environments. For maximum performance and minimal memory usage, the [Expect API](docs/expect.md) can be used to parse data of a predefined schema.
57+
5658
## The Write API
5759
5860
The MPack Write API encodes structured data to MessagePack.
@@ -112,7 +114,7 @@ MPack is rich in features while maintaining very high performance and a small co
112114

113115
A larger feature comparison table is available [here](docs/features.md) which includes descriptions of the various entries in the table.
114116

115-
This [benchmarking suite](https://github.com/ludocode/schemaless-benchmarks) compares the performance of MPack to other implementations of schemaless serialization formats. MPack outperforms all other MessagePack implementations, and in some tests MPack is several times faster than [RapidJSON](https://github.com/miloyip/rapidjson) for equivalent data.
117+
[This benchmarking suite](https://github.com/ludocode/schemaless-benchmarks) compares the performance of MPack to other implementations of schemaless serialization formats. MPack outperforms all JSON and MessagePack libraries, and in some tests MPack is several times faster than [RapidJSON](https://github.com/miloyip/rapidjson) for equivalent data.
116118

117119
## Why Not Just Use JSON?
118120

@@ -126,7 +128,7 @@ Conceptually, MessagePack stores data similarly to JSON: they are both composed
126128

127129
- Binary data is not supported by JSON at all. Small binary blobs such as icons and thumbnails need to be Base64 encoded or passed out-of-band.
128130

129-
The above issues greatly increase the complexity of the decoder. Full-featured JSON decoders are quite large, and minimal decoders tend to leave out such features as string unescaping and float parsing, instead leaving these up to the user or platform. This can lead to hard-to-find platform-specific and locale-specific bugs. This also significantly decreases performance, making JSON unattractive for use in applications such as mobile games.
131+
The above issues greatly increase the complexity of the decoder. Full-featured JSON decoders are quite large, and minimal decoders tend to leave out such features as string unescaping and float parsing, instead leaving these up to the user or platform. This can lead to hard-to-find platform-specific and locale-specific bugs, as well as a greater potential for security vulnerabilites. This also significantly decreases performance, making JSON unattractive for use in applications such as mobile games.
130132

131133
While the space inefficiencies of JSON can be partially mitigated through minification and compression, the performance inefficiencies cannot. More importantly, if you are minifying and compressing the data, then why use a human-readable format in the first place?
132134

docs/doxygen-layout.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<!-- Layout definition for a group page -->
1313
<group>
14-
<briefdescription visible="yes"/>
14+
<detaileddescription visible="yes" title="Description"/>
1515
<groupgraph visible="$GROUP_GRAPHS"/>
1616
<memberdecl>
1717
<nestedgroups visible="yes" title=""/>
@@ -34,7 +34,6 @@
3434
<friends title=""/>
3535
<membergroups visible="yes"/>
3636
</memberdecl>
37-
<detaileddescription title=""/>
3837
<memberdef>
3938
<pagedocs/>
4039
<inlineclasses title=""/>

docs/doxygen-mpack-css.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ table.doxtable th {
22
background-color: #e0e7ff;
33
color: #000;
44
}
5-
.textblock code {
6-
background-color: #f3f3f3;
5+
.textblock code,
6+
.contents p code, .contents p em,
7+
.contents dd code, .contents dd em {
8+
padding: 1pt 2pt 1pt 2pt;
9+
background-color: #f5f5f5;
710
}
811
.textblock li {
912
margin: 3pt 0 3pt 0;

docs/expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
The Expect API is used to imperatively parse data of a fixed (hardcoded) schema. It is most useful when parsing very large MessagePack files, parsing in memory-constrained environments, or generating parsing code from a schema. The API is similar to [CMP](https://github.com/camgunz/cmp), but has many helper functions especially for map keys and expected value ranges. Some of these will be covered below.
55

6-
If you are not writing code for an embedded device or generating parsing code from a schema, you should not follow this guide. You should most likely be using the Node API instead.
6+
*If you are not writing code for an embedded device or generating parsing code from a schema, you should not follow this guide. You should most likely be using the Node API instead.*
77

88
## A simple example
99

src/mpack-config.h.sample

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*
1616
* Copy @c mpack-config.h.sample to @c mpack-config.h somewhere in your
1717
* project's include tree and, optionally, edit it to suit your setup.
18-
*
1918
* In almost all cases you can leave this file with the default config.
2019
*
2120
* You can also override the default configuration by pre-defining options
@@ -109,34 +108,34 @@
109108
/**
110109
* @def MPACK_MALLOC
111110
*
112-
* Defines the memory allocation function used by mpack. This is used by
111+
* Defines the memory allocation function used by MPack. This is used by
113112
* helpers for automatically allocating data the correct size, and for
114113
* debugging functions. If this macro is undefined, the allocation helpers
115114
* will not be compiled.
116115
*
117-
* The default is malloc() if MPACK_STDLIB is enabled.
116+
* The default is malloc() if @ref MPACK_STDLIB is enabled.
118117
*/
119118
/**
120119
* @def MPACK_FREE
121120
*
122-
* Defines the memory free function used by mpack. This is used by helpers
121+
* Defines the memory free function used by MPack. This is used by helpers
123122
* for automatically allocating data the correct size. If this macro is
124123
* undefined, the allocation helpers will not be compiled.
125124
*
126-
* The default is free() if MPACK_MALLOC has not been customized and
127-
* MPACK_STDLIB is enabled.
125+
* The default is free() if @ref MPACK_MALLOC has not been customized and
126+
* @ref MPACK_STDLIB is enabled.
128127
*/
129128
/**
130129
* @def MPACK_REALLOC
131130
*
132-
* Defines the realloc function used by mpack. It is used by growable
131+
* Defines the realloc function used by MPack. It is used by growable
133132
* buffers to resize more efficiently.
134133
*
135-
* The default is realloc() if MPACK_MALLOC has not been customized and
136-
* MPACK_STDLIB is enabled.
134+
* The default is realloc() if @ref MPACK_MALLOC has not been customized and
135+
* @ref MPACK_STDLIB is enabled.
137136
*
138-
* This is optional, even when MPACK_MALLOC is used. If MPACK_MALLOC is
139-
* set and MPACK_REALLOC is not, MPACK_MALLOC is used with a simple copy
137+
* This is optional, even when @ref MPACK_MALLOC is used. If @ref MPACK_MALLOC is
138+
* set and @ref MPACK_REALLOC is not, @ref MPACK_MALLOC is used with a simple copy
140139
* to grow buffers.
141140
*/
142141
#if defined(MPACK_STDLIB) && !defined(MPACK_MALLOC)
@@ -158,13 +157,13 @@
158157
* @def MPACK_DEBUG
159158
*
160159
* Enables debug features. You may want to wrap this around your
161-
* own debug preprocs. By default, they are enabled if DEBUG or _DEBUG
160+
* own debug preprocs. By default, this is enabled if @c DEBUG or @c _DEBUG
162161
* are defined.
163162
*
164-
* Note that MPACK_DEBUG cannot be defined differently for different
163+
* Note that @ref MPACK_DEBUG cannot be defined differently for different
165164
* source files because it affects layout of structs defined in header
166165
* files. Your entire project must be compiled with the same value of
167-
* MPACK_DEBUG. (This is why NDEBUG is not used.)
166+
* @ref MPACK_DEBUG. (This is why @c NDEBUG is not used.)
168167
*/
169168
#if !defined(MPACK_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
170169
#define MPACK_DEBUG 1
@@ -179,7 +178,7 @@
179178
* on embedded devices. If this is disabled, string functions such as
180179
* mpack_error_to_string() and mpack_type_to_string() return an empty string.
181180
*
182-
* This is on by default if MPACK_STRINGS is not defined.
181+
* This is on by default if it is not defined.
183182
*/
184183
#if !defined(MPACK_STRINGS)
185184
#define MPACK_STRINGS 1
@@ -189,10 +188,12 @@
189188
* Set this to 1 to implement a custom mpack_assert_fail() function. This
190189
* function must not return, and must have the following signature:
191190
*
192-
* void mpack_assert_fail(const char* message)
191+
* @code{.c}
192+
* void mpack_assert_fail(const char* message)
193+
* @endcode
193194
*
194-
* Asserts are only used when MPACK_DEBUG is enabled, and can be triggered
195-
* by bugs in mpack or bugs due to incorrect usage of mpack.
195+
* Asserts are only used when @ref MPACK_DEBUG is enabled, and can be triggered
196+
* by bugs in MPack or bugs due to incorrect usage of MPack.
196197
*/
197198
#ifndef MPACK_CUSTOM_ASSERT
198199
#define MPACK_CUSTOM_ASSERT 0
@@ -223,7 +224,7 @@
223224
* Note that without write tracking enabled, it is possible for buggy code
224225
* to emit invalid MessagePack without flagging an error by writing the wrong
225226
* number of elements or bytes in a compound type. With tracking enabled,
226-
* MPACK will catch such errors and break on the offending line of code.
227+
* MPack will catch such errors and break on the offending line of code.
227228
*
228229
* This is enabled by default in debug builds (provided a malloc() is
229230
* available.)
@@ -310,7 +311,7 @@
310311
#endif
311312

312313
/**
313-
* The maximum depth for the node parser if MPACK_MALLOC is not available.
314+
* The maximum depth for the node parser if @ref MPACK_MALLOC is not available.
314315
* The parsing stack is placed on the call stack.
315316
*/
316317
#ifndef MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC

src/mpack/mpack-common.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,11 @@ MPACK_INLINE bool mpack_tag_equal(mpack_tag_t left, mpack_tag_t right) {
344344

345345
/*
346346
* Helpers to perform unaligned network-endian loads and stores
347-
* at arbitrary addresses.
347+
* at arbitrary addresses. Byte-swapping builtins are used if they
348+
* are available and if they improve performance.
348349
*
349350
* These will remain available in the public API so feel free to
350351
* use them for other purposes, but they are undocumented.
351-
*
352-
* The bswap builtins are used when needed and available. With
353-
* GCC 5.2 they appear to give better performance and smaller
354-
* code size on little-endian ARM while compiling to the same
355-
* assembly as the bit-shifting code on x86_64.
356352
*/
357353

358354
MPACK_INLINE uint8_t mpack_load_u8(const char* p) {

0 commit comments

Comments
 (0)