Skip to content

Commit 43b48f6

Browse files
committed
Update to the comment
1 parent f174495 commit 43b48f6

1 file changed

Lines changed: 32 additions & 20 deletions

File tree

README.md

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
]}.
1919
```
2020

21+
Or as it is [now published at hex.pm](https://hex.pm/packages/msgpack), just
22+
23+
```erlang
24+
{deps, [msgpack]}.
25+
```
26+
27+
might work.
28+
2129
## Simple deserialization
2230

2331
```erlang
@@ -67,38 +75,42 @@ a binary is encoded as a binary. In unpacking, msgpacked binaries are
6775
decoded as atoms with `erlang:binary_to_existing_atom/2` with encoding
6876
`utf8`. Default value is an empty list.
6977

70-
### `{str, as_binary|as_list}`
71-
72-
Both in packing and unpacking. Only available at new spec. Default is `as_list`.
78+
### `{unpack_str, as_binary|as_list}`
7379

74-
This option indicates str type family is treated as binary or list in
75-
Erlang world.
80+
A switch to choose decoded term style of `str` type when *unpacking*.
81+
Only available at new spec. Default is `as_list`.
7682

7783
```
7884
mode as_binary as_list
7985
-----------+------------+-------
80-
packing
81-
binary() str bin
82-
string() bin* str*
83-
list() array array
84-
-----------+------------+-------
85-
unpacking
86-
bin string() binary()
86+
bin binary() binary()
8787
str binary() string()
8888
```
8989

90-
- (\*) fallback to list() handling if any error found
90+
### `{validate_string, boolean()}`
9191

92+
Only in unpacking, UTF-8 validation at unpacking from `str` type will
93+
be enabled. Default value is `false`.
94+
95+
### `{pack_str, from_binary|from_list|none}`
96+
97+
A switch to choose packing of `string()` when packing. Only available
98+
at new spec. Default is `from_list` for symmetry with `unpack_str`
99+
option.
92100

93-
```erlang
94-
Opt = [{enable_str, true}]
95-
{ok, "埼玉"} = msgpack:unpack(msgpack:pack("埼玉", Opt), Opt).
96-
=> {ok,[22524,29577]}
97101
```
98-
### `{validate_string, boolean()}`
102+
mode from_list from_binary none
103+
-----------+------------+--------------+-----------------
104+
binary() bin str*/bin bin
105+
string() str*/array array of int array of int
106+
list() array array array
107+
```
108+
109+
But the default option pays the cost of performance for symmetry. If
110+
the overhead of UTF-8 validation is unacceptable, choosing `none` as
111+
the option would be the best.
99112

100-
Both in packing and unpacking. UTF-8 validation in encoding to str and
101-
decoding from str type will be enabled. Default value is `true`.
113+
- \* Tries to pack as `str` if it is a valid `string()`.
102114

103115
### `{map_format, maps|jiffy|jsx}`
104116

0 commit comments

Comments
 (0)