Skip to content

Commit d85eeec

Browse files
committed
Add type translation table
1 parent d866f54 commit d85eeec

1 file changed

Lines changed: 44 additions & 11 deletions

File tree

README.md

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
## Prerequisites for runtime
88

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).
1111

1212
## edit rebar.config to use in your application
1313

@@ -37,35 +37,67 @@ Ham = msgpack:pack(Spam),
3737

3838
### `{spec, new|old}`
3939

40-
Both packing and unpacking.
40+
Both for packing and unpacking. Major difference between old and new spec is:
4141

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.
4352

4453
```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}]).
4756
```
4857

4958
### `{allow_atom, none|pack}`
5059

51-
Only in packing
60+
Only in packing. Atoms are packed as binaries.
5261

5362
### `{known_atoms, [atom()]}`
5463

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`.
5668

57-
### `{str, as_binary|as_list|as_validated_list}`
69+
### `{str, as_binary|as_list}`
5870

5971
Both in packing and unpacking. Only available at new spec.
6072

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+
6291

6392
```erlang
6493
Opt = [{enable_str, true}]
6594
{ok, "埼玉"} = msgpack:unpack(msgpack:pack("埼玉", Opt), Opt).
6695
=> {ok,[22524,29577]}
6796
```
97+
### `{validate_string, boolean()}`
6898

99+
Both in packing and unpacking. UTF-8 validation in encoding to str and
100+
decoding from str type will be enabled.
69101

70102
### `{map_format, maps|jiffy|jsx}`
71103

@@ -103,7 +135,8 @@ Apache License 2.0
103135

104136
## 0.5.0
105137

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.
107140

108141
## 0.4.0
109142

0 commit comments

Comments
 (0)