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 )
2
4
3
5
CMP is a C implementation of the MessagePack serialization format. It
4
6
currently implements version 5 of the [ MessagePack
@@ -32,6 +34,10 @@ static bool file_reader(cmp_ctx_t *ctx, void *data, size_t limit) {
32
34
return read_bytes(data, limit, (FILE * )ctx->buf);
33
35
}
34
36
37
+ static bool file_skipper(cmp_ctx_t * ctx, size_t count) {
38
+ return fseek((FILE * )ctx->buf, count, SEEK_CUR);
39
+ }
40
+
35
41
static size_t file_writer(cmp_ctx_t * ctx, const void * data, size_t count) {
36
42
return fwrite(data, sizeof(uint8_t), count, (FILE * )ctx->buf);
37
43
}
@@ -54,7 +60,7 @@ int main(void) {
54
60
if (fh == NULL)
55
61
error_and_exit("Error opening data.dat");
56
62
57
- cmp_init(&cmp, fh, file_reader, file_writer);
63
+ cmp_init(&cmp, fh, file_reader, file_skipper, file_writer);
58
64
59
65
if (!cmp_write_array(&cmp, 2))
60
66
error_and_exit(cmp_strerror(&cmp));
@@ -90,13 +96,14 @@ int main(void) {
90
96
if (!cmp_read_str(&cmp, message_pack, &str_size))
91
97
error_and_exit(cmp_strerror(&cmp));
92
98
93
- printf("Array Length: %zu .\n", array_size);
99
+ printf("Array Length: %u .\n", array_size);
94
100
printf("[\"%s\", \"%s\"]\n", hello, message_pack);
95
101
96
102
fclose(fh);
97
103
98
104
return EXIT_SUCCESS;
99
105
}
106
+
100
107
```
101
108
102
109
## Advanced Usage
@@ -108,36 +115,35 @@ See the `examples` folder.
108
115
CMP uses no internal buffers; conversions, encoding and decoding are done on
109
116
the fly.
110
117
111
- CMP's source and header file together are ~3,300 LOC.
118
+ CMP's source and header file together are ~4k LOC.
112
119
113
120
CMP makes no heap allocations.
114
121
115
122
CMP 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`.
118
124
119
125
CMP is written using C89 (ANSI C), aside, of course, from its use of
120
126
fixed-width integer types and `bool`.
121
127
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.
124
129
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.
127
133
128
134
CMP is portable. It uses fixed-width integer types, and checks the endianness
129
135
of the machine at runtime before swapping bytes (MessagePack is big-endian).
130
136
131
137
CMP provides a fairly comprehensive error reporting mechanism modeled after
132
138
`errno` and `strerror`.
133
139
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.
136
142
137
143
CMP is tested using the MessagePack test suite as well as a large set of custom
138
144
test cases. Its small test program is compiled with clang using `-Wall -Werror
139
145
-Wextra ...` along with several other flags, and generates no compilation
140
- errors.
146
+ errors in either Clang or GCC .
141
147
142
148
CMP's source is written as readably as possible, using explicit, descriptive
143
149
variable names and a consistent, clear style.
0 commit comments