1- # cmp
1+ # CMP
2+
3+ [ ![ Build Status] ( https://travis-ci.org/camgunz/cmp.svg?branch=master )] ( https://travis-ci.org/camgunz/cmp ) [ ![ Coverage Status] ( https://coveralls.io/repos/github/camgunz/cmp/badge.svg?branch=develop )] ( https://coveralls.io/github/camgunz/cmp?branch=develop )
24
35CMP is a C implementation of the MessagePack serialization format. It
46currently implements version 5 of the [ MessagePack
@@ -32,6 +34,10 @@ static bool file_reader(cmp_ctx_t *ctx, void *data, size_t limit) {
3234 return read_bytes(data, limit, (FILE * )ctx->buf);
3335}
3436
37+ static bool file_skipper(cmp_ctx_t * ctx, size_t count) {
38+ return fseek((FILE * )ctx->buf, count, SEEK_CUR);
39+ }
40+
3541static size_t file_writer(cmp_ctx_t * ctx, const void * data, size_t count) {
3642 return fwrite(data, sizeof(uint8_t), count, (FILE * )ctx->buf);
3743}
@@ -54,7 +60,7 @@ int main(void) {
5460 if (fh == NULL)
5561 error_and_exit("Error opening data.dat");
5662
57- cmp_init(&cmp, fh, file_reader, file_writer);
63+ cmp_init(&cmp, fh, file_reader, file_skipper, file_writer);
5864
5965 if (!cmp_write_array(&cmp, 2))
6066 error_and_exit(cmp_strerror(&cmp));
@@ -90,13 +96,14 @@ int main(void) {
9096 if (!cmp_read_str(&cmp, message_pack, &str_size))
9197 error_and_exit(cmp_strerror(&cmp));
9298
93- printf("Array Length: %zu .\n", array_size);
99+ printf("Array Length: %u .\n", array_size);
94100 printf("[\"%s\", \"%s\"]\n", hello, message_pack);
95101
96102 fclose(fh);
97103
98104 return EXIT_SUCCESS;
99105}
106+
100107```
101108
102109## Advanced Usage
@@ -108,36 +115,35 @@ See the `examples` folder.
108115CMP uses no internal buffers; conversions, encoding and decoding are done on
109116the fly.
110117
111- CMP's source and header file together are ~3,300 LOC.
118+ CMP's source and header file together are ~4k LOC.
112119
113120CMP makes no heap allocations.
114121
115122CMP uses standardized types rather than declaring its own, and it depends only
116- on `stdbool.h`, `stdint.h` and `string.h`. It has no link-time dependencies,
117- not even the C Standard Library.
123+ on `stdbool.h`, `stdint.h` and `string.h`.
118124
119125CMP is written using C89 (ANSI C), aside, of course, from its use of
120126fixed-width integer types and `bool`.
121127
122- On the other hand, CMP's test suite depends upon the C Standard Library and
123- requires C99.
128+ On the other hand, CMP's test suite requires C99.
124129
125- CMP only requires the programmer supply a read function and a write function.
126- In this way, the programmer can use CMP on memory, files, sockets, etc.
130+ CMP only requires the programmer supply a read function, a write function, and
131+ an optional skip function. In this way, the programmer can use CMP on memory,
132+ files, sockets, etc.
127133
128134CMP is portable. It uses fixed-width integer types, and checks the endianness
129135of the machine at runtime before swapping bytes (MessagePack is big-endian).
130136
131137CMP provides a fairly comprehensive error reporting mechanism modeled after
132138`errno` and `strerror`.
133139
134- CMP is threadsafe ; while contexts cannot be shared between threads, each thread
135- may use its own context freely.
140+ CMP is thread aware ; while contexts cannot be shared between threads, each
141+ thread may use its own context freely.
136142
137143CMP is tested using the MessagePack test suite as well as a large set of custom
138144test cases. Its small test program is compiled with clang using `-Wall -Werror
139145-Wextra ...` along with several other flags, and generates no compilation
140- errors.
146+ errors in either Clang or GCC .
141147
142148CMP's source is written as readably as possible, using explicit, descriptive
143149variable names and a consistent, clear style.
0 commit comments