Skip to content

Commit 3e5002d

Browse files
committed
Release 1.1
1 parent 6429a45 commit 3e5002d

23 files changed

+1716
-759
lines changed

README.md

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#CWPack
22

3-
CWPack is a minimalistic and yet fast and complete implementation of the
3+
CWPack is a lightweight and yet complete implementation of the
44
[MessagePack](http://msgpack.org) serialization format
55
[version 5](https://github.com/msgpack/msgpack/blob/master/spec.md).
66

7+
## Fast, Faster, Fastest
8+
9+
CWPack is the fastest open-source messagepack implementation. It is faster then
10+
[MPack](https://github.com/ludocode/mpack)
11+
and both totally outperform
12+
[CMP](https://github.com/camgunz/cmp)
13+
714
## Design
815

916
CWPack does no memory allocations and no file handling. All that is done
@@ -27,54 +34,60 @@ void example (void)
2734
char buffer[20];
2835
cw_pack_context_init (&pc, buffer, 20, 0, 0);
2936

30-
if (cw_pack_map_size (&pc, 2)) ERROR;
31-
if (cw_pack_str (&pc, "compact", 7)) ERROR;
32-
if (cw_pack_boolean (&pc, true)) ERROR;
33-
if (cw_pack_str (&pc, "schema", 6)) ERROR;
34-
if (cw_pack_unsigned (&pc, 0)) ERROR;
37+
cw_pack_map_size (&pc, 2);
38+
cw_pack_str (&pc, "compact", 7);
39+
cw_pack_boolean (&pc, true);
40+
cw_pack_str (&pc, "schema", 6);
41+
cw_pack_unsigned (&pc, 0);
3542

3643
int length = pc.current - pc.start;
37-
if (length > 18) ERROR
44+
if (length > 18) ERROR;
3845

3946
cw_unpack_context uc;
4047
cw_unpack_context_init (&uc, pc.start, length, 0, 0);
4148

42-
if (cw_unpack_next(&uc)) ERROR;
49+
cw_unpack_next(&uc);
4350
if (uc.item.type != CWP_ITEM_MAP || uc.item.as.map.size != 2) ERROR;
4451

45-
if (cw_unpack_next(&uc)) ERROR;
52+
cw_unpack_next(&uc);
4653
if (uc.item.type != CWP_ITEM_STR || uc.item.as.str.length != 7)) ERROR;
4754
if (strncmp("compact", uc.item.as.str.start, 7)) ERROR;
4855

49-
if (cw_unpack_next(&uc)) ERROR;
56+
cw_unpack_next(&uc);
5057
if (uc.item.type != CWP_ITEM_BOOLEAN || uc.item.as.boolean != true) ERROR;
5158

52-
if (cw_unpack_next(&uc)) ERROR;
59+
cw_unpack_next(&uc);
5360
if (uc.item.type != CWP_ITEM_STR || uc.item.as.str.length != 6)) ERROR;
5461
if (strncmp("schema", uc.item.as.str.start, 6)) ERROR;
5562

56-
if (cw_unpack_next(&uc)) ERROR;
63+
cw_unpack_next(&uc);
5764
if (uc.item.type != CWP_ITEM_POSITIVE_INTEGER || uc.item.as.u64 != 0) ERROR;
5865

59-
if (cw_unpack_next(&uc) != CWP_RC_END_OF_INPUT) ERROR;
66+
cw_unpack_next(&uc);
67+
if (uc.return_code != CWP_RC_END_OF_INPUT) ERROR;
6068
}
6169
```
6270
71+
In the examples folder there are more examples.
72+
73+
## Backward compatibility
74+
75+
CWPack may be run in compatibility mode. It affects only packing; EXTs are considered illegal, BINs is transformed to STRs and generation of STR8 is supressed.
76+
6377
## Error handling
6478
6579
CWPack does not check for illegal values (e.g. in STRs for illegal unicode characters).
6680
67-
When an error is detected in a context, that context is stopped and all calls are returned
68-
with the stopped error code.
81+
When an error is detected in a context, that context is stopped and all future calls to that context are immediatly returned without any actions.
6982
7083
## Build
7184
72-
CWPack consists of a single src file with corresponding header file. It is written
73-
in C and the files are together ~ 1K lines. No build is neccesary, just include the
85+
CWPack consists of a single src file and two header files. It is written
86+
in strict ansi C and the files are together ~ 1.1K lines. No separate build is neccesary, just include the
7487
files in your own build.
7588
7689
CWPack has no dependencies to other libraries.
7790
78-
## Module test
91+
## Test
7992
80-
Included in the test folder in the repository is a simple module test and a shell script to run it.
93+
Included in the test folder are a module test and a performance test and shell scripts to run them.

example/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#CWPack - Example
2+
3+
The example contains a program that takes a json file and then converts it to a messagePack file, then converts the latter back to json.
4+
5+
In the script runExample.sh the 2 json files are also diffed.
6+
7+
The files `item.(h,c)` contains a memory tree representation of json data and the conversion routines:
8+
9+
- Item Tree To Json File
10+
- Item Tree To MessagePack File
11+
- Json File To Item Tree
12+
- MessagePack File To Item Tree
13+
14+
The conversion routines are just examples and not of production quality.

example/contexts.h

Lines changed: 0 additions & 64 deletions
This file was deleted.

example/item.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <stdio.h>
2828

2929
#include "item.h"
30-
#include "contexts.h"
30+
#include "basic_contexts.h"
3131

3232

3333

@@ -435,9 +435,10 @@ static void item32packContext(cw_pack_context* pc, item_root* item)
435435

436436
void item32cwpackFile (FILE* file, item_root* item)
437437
{
438-
cw_pack_context* pc = new_file_pack_context(10, file);
439-
item32packContext (pc, item);
440-
flush_file_pack_context(pc);
438+
stream_pack_context spc;
439+
init_stream_pack_context(&spc, 10, file);
440+
item32packContext (&spc.pc, item);
441+
flush_stream_pack_context(&spc);
441442
}
442443

443444

@@ -519,8 +520,9 @@ static item_root* packContext2item3 (cw_unpack_context* uc)
519520

520521
item_root* cwpackFile2item3 (FILE* file)
521522
{
522-
cw_unpack_context* uc = new_file_unpack_context(10, file);
523-
return packContext2item3(uc);
523+
stream_unpack_context suc;
524+
init_stream_unpack_context(&suc, 0, file);
525+
return packContext2item3(&suc.uc);
524526
}
525527

526528

example/item.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
#define item_h
2626

2727

28-
#ifdef __cplusplus
29-
extern "C" {
30-
#endif
31-
28+
3229

3330
/************** ITEMS **********************/
3431

@@ -85,8 +82,4 @@ extern "C" {
8582

8683

8784

88-
#ifdef __cplusplus
89-
}
90-
#endif
91-
9285
#endif /* item_h */

example/json2cwpack2json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <stdio.h>
2626

2727
#include "item.h"
28-
#include "contexts.h"
28+
#include "basic_contexts.h"
2929

3030

3131
int main(int argc, const char * argv[])

example/runExample.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
clang -ansi -I ../src/ -o json2cwpack2json *.c ../src/*.c
1+
clang -ansi -I ../src/ -I ../goodies/basic-contexts/ *.c ../src/*.c ../goodies/basic-contexts/*.c -o json2cwpack2json
22
./json2cwpack2json test1.json
33
diff -a test1.json test1.json.msgpack.json
4-
rm -f *.o test1.json.msgpack.json json2cwpack2json
4+
rm -f *.o json2cwpack2json

goodies/basic-contexts/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#CWPack - Goodies - Basic Contexts
2+
3+
4+
Basic contexts contains 3 contexts:
5+
6+
- **Dynamic Memory Pack Context** is used when you want to pack to a malloc´d memory buffer. At buffer overflow the context handler tries to reallocate the buffer to a larger size.
7+
8+
- **File Pack Context** is used when you pack to a file. At buffer overflow the context handler writes the buffer out and then reuses it. If an item is larger than the buffer, the handler tries to reallocate the buffer so the item would fit.
9+
10+
- **File Unpack Context** is used when you unpack from a file. As with File Pack Context, the handler asserts that an items will always fit in the buffer.

0 commit comments

Comments
 (0)