|
18 | 18 | ]}. |
19 | 19 | ``` |
20 | 20 |
|
| 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 | + |
21 | 29 | ## Simple deserialization |
22 | 30 |
|
23 | 31 | ```erlang |
@@ -67,38 +75,42 @@ a binary is encoded as a binary. In unpacking, msgpacked binaries are |
67 | 75 | decoded as atoms with `erlang:binary_to_existing_atom/2` with encoding |
68 | 76 | `utf8`. Default value is an empty list. |
69 | 77 |
|
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}` |
73 | 79 |
|
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`. |
76 | 82 |
|
77 | 83 | ``` |
78 | 84 | mode as_binary as_list |
79 | 85 | -----------+------------+------- |
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() |
87 | 87 | str binary() string() |
88 | 88 | ``` |
89 | 89 |
|
90 | | -- (\*) fallback to list() handling if any error found |
| 90 | +### `{validate_string, boolean()}` |
91 | 91 |
|
| 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. |
92 | 100 |
|
93 | | -```erlang |
94 | | -Opt = [{enable_str, true}] |
95 | | -{ok, "埼玉"} = msgpack:unpack(msgpack:pack("埼玉", Opt), Opt). |
96 | | - => {ok,[22524,29577]} |
97 | 101 | ``` |
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. |
99 | 112 |
|
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()`. |
102 | 114 |
|
103 | 115 | ### `{map_format, maps|jiffy|jsx}` |
104 | 116 |
|
|
0 commit comments