|
6 | 6 |
|
7 | 7 | ## Prerequisites for runtime |
8 | 8 |
|
9 | | -[Erlang/OTP](http://erlang.org/), >= 17.0 |
10 | | -Also based on [the new msgpack spec 232a0d](https://github.com/msgpack/msgpack/blob/232a0d14c6057000cc4a478f0dfbb5942ac54e9e/spec.md). |
| 9 | +[Erlang/OTP](http://erlang.org/), >= 17.0 Also based on |
| 10 | +[the new msgpack spec 0b8f5a](https://github.com/msgpack/msgpack/blob/0b8f5ac67cdd130f4d4d4fe6afb839b989fdb86a/spec.md). |
11 | 11 |
|
12 | 12 | ## edit rebar.config to use in your application |
13 | 13 |
|
@@ -37,35 +37,67 @@ Ham = msgpack:pack(Spam), |
37 | 37 |
|
38 | 38 | ### `{spec, new|old}` |
39 | 39 |
|
40 | | -Both packing and unpacking. |
| 40 | +Both for packing and unpacking. Major difference between old and new spec is: |
41 | 41 |
|
42 | | -[old spec](https://github.com/msgpack/msgpack/blob/master/spec-old.md): |
| 42 | +- raw family (`0xa0~0xbf`, `0xda`, `0xdb`) becomes new str family |
| 43 | +- `0xd9` is new as str8 |
| 44 | +- new bin space (`0xc4, 0xc5, 0xc6` as bin8, bin16, bin32) |
| 45 | +- new ext space (`0xc7, 0xc8, 0xc9` as ext8, ext16, ext32) |
| 46 | +- new fixext space (`0xd4, 0xd5, 0xd6, 0xd7, 0xd8` as fixext1, fixext2, fixext4, fixext8, fixext16), |
| 47 | + |
| 48 | +The default is new spec. Old spec mode does not handle these new types but |
| 49 | +returns error. To use |
| 50 | +[old spec](https://github.com/msgpack/msgpack/blob/master/spec-old.md) |
| 51 | +mode, this option is explicitly added. |
43 | 52 |
|
44 | 53 | ```erlang |
45 | | -OldHam = msgpack:pack(Spam, [{enable_str,false}]), |
46 | | -{ok, Spam} = msgpack:unpack(OldHam, [{enable_str,false}]). |
| 54 | +OldHam = msgpack:pack(Spam, [{spec, old}]), |
| 55 | +{ok, Spam} = msgpack:unpack(OldHam, [{spec, old}]). |
47 | 56 | ``` |
48 | 57 |
|
49 | 58 | ### `{allow_atom, none|pack}` |
50 | 59 |
|
51 | | -Only in packing |
| 60 | +Only in packing. Atoms are packed as binaries. |
52 | 61 |
|
53 | 62 | ### `{known_atoms, [atom()]}` |
54 | 63 |
|
55 | | -Both in packing and unpacking |
| 64 | +Both in packing and unpacking. In packing, if an atom is in this list |
| 65 | +a binary is encoded as a binary. In unpacking, msgpacked binaries are |
| 66 | +decoded as atoms with `erlang:binary_to_existing_atom/2` with encoding |
| 67 | +`utf8`. |
56 | 68 |
|
57 | | -### `{str, as_binary|as_list|as_validated_list}` |
| 69 | +### `{str, as_binary|as_list}` |
58 | 70 |
|
59 | 71 | Both in packing and unpacking. Only available at new spec. |
60 | 72 |
|
61 | | -Now this supports string type! |
| 73 | +This option indicates str type family is treated as binary or list in |
| 74 | +Erlang world. |
| 75 | + |
| 76 | +``` |
| 77 | +mode as_binary as_list |
| 78 | +-----------+------------+------- |
| 79 | +packing |
| 80 | +binary() str bin |
| 81 | +string() bin* str* |
| 82 | +list() array array |
| 83 | +-----------+------------+------- |
| 84 | +unpacking |
| 85 | +bin string() binary() |
| 86 | +str binary() string() |
| 87 | +``` |
| 88 | + |
| 89 | +- (\*) fallback to list() handling if any error found |
| 90 | + |
62 | 91 |
|
63 | 92 | ```erlang |
64 | 93 | Opt = [{enable_str, true}] |
65 | 94 | {ok, "埼玉"} = msgpack:unpack(msgpack:pack("埼玉", Opt), Opt). |
66 | 95 | => {ok,[22524,29577]} |
67 | 96 | ``` |
| 97 | +### `{validate_string, boolean()}` |
68 | 98 |
|
| 99 | +Both in packing and unpacking. UTF-8 validation in encoding to str and |
| 100 | +decoding from str type will be enabled. |
69 | 101 |
|
70 | 102 | ### `{map_format, maps|jiffy|jsx}` |
71 | 103 |
|
@@ -103,7 +135,8 @@ Apache License 2.0 |
103 | 135 |
|
104 | 136 | ## 0.5.0 |
105 | 137 |
|
106 | | -- Renewed optional arguments to pack/unpack interface. |
| 138 | +- Renewed optional arguments to pack/unpack interface. This is |
| 139 | + incompatible change from 0.4 series. |
107 | 140 |
|
108 | 141 | ## 0.4.0 |
109 | 142 |
|
|
0 commit comments