From c875f46fe83381d5917b3a7a8453e2ae58d233a8 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 26 Sep 2016 22:46:06 +0200 Subject: erts: Add examples to binary_to_term and term_to_binary --- erts/doc/src/erlang.xml | 28 +++++++++++++++++++++++++--- 1 file 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)).

Returns an Erlang term that is the result of decoding binary object Binary, which must be encoded - according to the Erlang external term format.

+ according to the + Erlang external term format.

+
+> Bin = term_to_binary(hello).
+<<131,100,0,5,104,101,108,108,111>>
+> hello = binary_to_term(Bin).
+hello
+

When decoding binaries from untrusted sources, consider using binary_to_term/2 to prevent Denial @@ -555,6 +562,14 @@ Z = erlang:adler32_combine(X,Y,iolist_size(Data2)).

Failure: badarg if safe is specified and unsafe data is decoded.

+
+> binary_to_term(<<131,100,0,5,104,101,108,108,111>>, [safe]).
+** exception error: bad argument
+> hello.
+hello
+> binary_to_term(<<131,100,0,5,104,101,108,108,111>>, [safe]).
+hello
+

See also term_to_binary/1, @@ -8599,12 +8614,19 @@ ok

Returns a binary data object that is the result of encoding - Term according to the Erlang external - term format.

+ Term according to the + Erlang external + term format.

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.

+
+> Bin = term_to_binary(hello).
+<<131,100,0,5,104,101,108,108,111>>
+> hello = binary_to_term(Bin).
+hello
+

See also binary_to_term/1.

-- cgit v1.2.3