diff options
author | Sverker Eriksson <[email protected]> | 2017-11-15 14:58:02 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2017-11-15 14:58:02 +0100 |
commit | 355e7855919e2a82856b27d45cb692a087da0385 (patch) | |
tree | 6c1f8aec1d80a42c4c5cf7f5b5455da39102e2d7 /erts/doc | |
parent | 0d9d1f1915ac70ba00418fd24a4293bb22c4fade (diff) | |
parent | 6a6019c287a54b71d4d0bcf0a72d244d89de90d1 (diff) | |
download | otp-355e7855919e2a82856b27d45cb692a087da0385.tar.gz otp-355e7855919e2a82856b27d45cb692a087da0385.tar.bz2 otp-355e7855919e2a82856b27d45cb692a087da0385.zip |
Merge PR-1605 from sverker/sverker/binary_to_term-used OTP-14780
Add 'used' option for binary_to_term/2
Diffstat (limited to 'erts/doc')
-rw-r--r-- | erts/doc/src/erlang.xml | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index c77f426919..3b7b9d6a50 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -557,9 +557,7 @@ hello <name name="binary_to_term" arity="2"/> <fsummary>Decode an Erlang external term format binary.</fsummary> <desc> - <p>As <c>binary_to_term/1</c>, but takes options that affect decoding - of the binary.</p> - <p>Option:</p> + <p>As <c>binary_to_term/1</c>, but takes these options:</p> <taglist> <tag><c>safe</c></tag> <item> @@ -575,18 +573,31 @@ hello creation of new external function references. None of those resources are garbage collected, so unchecked creation of them can exhaust available memory.</p> - </item> - </taglist> - <p>Failure: <c>badarg</c> if <c>safe</c> is specified and unsafe - data is decoded.</p> <pre> -> <input>binary_to_term(<<131,100,0,5,104,101,108,108,111>>, [safe]).</input> +> <input>binary_to_term(<<131,100,0,5,"hello">>, [safe]).</input> ** exception error: bad argument > <input>hello.</input> hello -> <input>binary_to_term(<<131,100,0,5,104,101,108,108,111>>, [safe]).</input> +> <input>binary_to_term(<<131,100,0,5,"hello">>, [safe]).</input> hello </pre> + </item> + <tag><c>used</c></tag> + <item> + <p>Changes the return value to <c>{Term, Used}</c> where <c>Used</c> + is the number of bytes actually read from <c>Binary</c>.</p> + <pre> +> <input>Input = <<131,100,0,5,"hello","world">>.</input> +<<131,100,0,5,104,101,108,108,111,119,111,114,108,100>> +> <input>{Term, Used} = binary_to_term(Input, [used]).</input> +{hello, 9} +> <input>split_binary(Input, Used).</input> +{<<131,100,0,5,104,101,108,108,111>>, <<"world">>} +</pre> + </item> + </taglist> + <p>Failure: <c>badarg</c> if <c>safe</c> is specified and unsafe + data is decoded.</p> <p>See also <seealso marker="#term_to_binary/1"><c>term_to_binary/1</c></seealso>, <seealso marker="#binary_to_term/1"> |