From 0a633e1fa9e475e6260c35e33befc49e02f90c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 25 Mar 2014 09:43:08 +0100 Subject: Correct the PrimStrings example The decode functions now return a binary, not an iolist, so we must both change the output and remove the call to list_to_binary when decoding. --- lib/asn1/doc/src/asn1_ug.xml | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'lib/asn1') diff --git a/lib/asn1/doc/src/asn1_ug.xml b/lib/asn1/doc/src/asn1_ug.xml index fb379214fc..1da4cce5a9 100644 --- a/lib/asn1/doc/src/asn1_ug.xml +++ b/lib/asn1/doc/src/asn1_ug.xml @@ -720,24 +720,33 @@ TextFileVal2 = [88,76,55,44,99,121 .......... a lot of characters here ....] characters are all represented by quadruples beginning with three zeros like {0,0,0,65} for the 'A' character. When decoding a value for these strings the result is a list of - quadruples, or integers when the value is an ASCII character. - The following example shows how it works:

-

In a file PrimStrings.asn1 the type BMP is defined as -

-BMP ::= BMPString then using BER encoding (ber - option)the input/output format will be:

+ quadruples, or integers when the value is an ASCII character.

+ +

The following example shows how it works. We have the following + specification in the file PrimStrings.asn1.

+
+PrimStrings DEFINITIONS AUTOMATIC TAGS ::=
+BEGIN
+   BMP ::= BMPString
+END
+       
+ +

Encoding and decoding some strings:

+
-1> {ok,Bytes1} = 'PrimStrings':encode('BMP', [{0,0,53,53},{0,0,45,56}]).
-{ok,[30,4,"55-8"]}
-2> 'PrimStrings':decode('BMP', list_to_binary(Bytes1)).
+1> asn1ct:compile('PrimStrings', [ber]).
+ok
+2> {ok,Bytes1} = 'PrimStrings':encode('BMP', [{0,0,53,53},{0,0,45,56}]).
+{ok,<<30,4,53,54,45,56>>}
+3> 'PrimStrings':decode('BMP', Bytes1).
 {ok,[{0,0,53,53},{0,0,45,56}]}
-3> {ok,Bytes2} = 'PrimStrings':encode('BMP', [{0,0,53,53},{0,0,0,65}]).
-{ok,[30,4,[53,53,0,65]]}
-4> 'PrimStrings':decode('BMP', list_to_binary(Bytes2)).
+4> {ok,Bytes2} = 'PrimStrings':encode('BMP', [{0,0,53,53},{0,0,0,65}]).
+{ok,<<30,4,53,53,0,65>>}
+5> 'PrimStrings':decode('BMP', Bytes2).
 {ok,[{0,0,53,53},65]}
-5> {ok,Bytes3} = 'PrimStrings':encode('BMP', "BMP string").
-{ok,[30,20,[0,66,0,77,0,80,0,32,0,115,0,116,0,114,0,105,0,110,0,103]]}
-6> 'PrimStrings':decode('BMP', list_to_binary(Bytes3)).
+6> {ok,Bytes3} = 'PrimStrings':encode('BMP', "BMP string").
+{ok,<<30,20,0,66,0,77,0,80,0,32,0,115,0,116,0,114,0,105,0,110,0,103>>}
+7> 'PrimStrings':decode('BMP', Bytes3).
 {ok,"BMP string"}      

The UTF8String is represented in Erlang as a list of integers, where each integer represents the unicode value of one -- cgit v1.2.3