diff options
author | Lukas Larsson <[email protected]> | 2016-10-03 10:42:04 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2016-10-03 10:42:04 +0200 |
commit | 5618dedfe1da25c7941052cdc1bc648e22ad3fbe (patch) | |
tree | aadbaf439cddc3d38644b963bde6b175ae167ea7 | |
parent | d0272e2d855d62c599d6ab8f2762d67cb1fea061 (diff) | |
parent | c875f46fe83381d5917b3a7a8453e2ae58d233a8 (diff) | |
download | otp-5618dedfe1da25c7941052cdc1bc648e22ad3fbe.tar.gz otp-5618dedfe1da25c7941052cdc1bc648e22ad3fbe.tar.bz2 otp-5618dedfe1da25c7941052cdc1bc648e22ad3fbe.zip |
Merge branch 'lukas/erts/bin_to_term_doc_example/PR-1181' into maint
* lukas/erts/bin_to_term_doc_example/PR-1181:
erts: Add examples to binary_to_term and term_to_binary
-rw-r--r-- | erts/doc/src/erlang.xml | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index 950a5fe189..b0d25389fd 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -516,7 +516,14 @@ Z = erlang:adler32_combine(X,Y,iolist_size(Data2)).</code> <desc> <p>Returns an Erlang term that is the result of decoding binary object <c><anno>Binary</anno></c>, which must be encoded - according to the Erlang external term format.</p> + according to the <seealso marker="erts:erl_ext_dist"> + Erlang external term format</seealso>.</p> + <pre> +> <input>Bin = term_to_binary(hello).</input> +<<131,100,0,5,104,101,108,108,111>> +> <input>hello = binary_to_term(Bin).</input> +hello +</pre> <warning> <p>When decoding binaries from untrusted sources, consider using <c>binary_to_term/2</c> to prevent Denial @@ -555,6 +562,14 @@ Z = erlang:adler32_combine(X,Y,iolist_size(Data2)).</code> </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> +** exception error: bad argument +> <input>hello.</input> +hello +> <input>binary_to_term(<<131,100,0,5,104,101,108,108,111>>, [safe]).</input> +hello +</pre> <p>See also <seealso marker="#term_to_binary/1"><c>term_to_binary/1</c></seealso>, <seealso marker="#binary_to_term/1"> @@ -8599,12 +8614,19 @@ ok </fsummary> <desc> <p>Returns a binary data object that is the result of encoding - <c><anno>Term</anno></c> according to the Erlang external - term format.</p> + <c><anno>Term</anno></c> according to the + <seealso marker="erts:erl_ext_dist">Erlang external + term format.</seealso></p> <p>This can be used for various purposes, for example, writing a term to a file in an efficient way, or sending an Erlang term to some type of communications channel not supported by distributed Erlang.</p> + <pre> +> <input>Bin = term_to_binary(hello).</input> +<<131,100,0,5,104,101,108,108,111>> +> <input>hello = binary_to_term(Bin).</input> +hello +</pre> <p>See also <seealso marker="#binary_to_term/1"> <c>binary_to_term/1</c></seealso>.</p> </desc> |