Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #10 from maxlapshin/master

I've added tests from other amf implementations.
  • Loading branch information...
commit 6a2876ba59d96eafb5e4948895751db87a6e610d 2 parents f686db0 + f9ec361
@mrinalwadhwa authored
Showing with 220 additions and 109 deletions.
  1. +103 −3 src/amf0.erl
  2. +43 −10 src/amf0_tests.erl
  3. +74 −96 src/amf3_tests.erl
View
106 src/amf0.erl
@@ -15,7 +15,7 @@
-module(amf0).
-export([decode/1, encode/1]).
-
+-define(D(X), io:format("~p~n", [X])).
%%---------------------------------------
%% @doc Decode AMF 0 encoded binary data
@@ -88,7 +88,62 @@ read(<<?XML_DOCUMENT, Length:32, String:Length/binary, Remaining/binary>>, Objec
read(<<?AVMPLUS_OBJECT, AMF3/binary>>, Objects) ->
{Object, Remaining} = amf3:decode(AMF3),
- {{avmplus, Object}, Remaining, Objects}.
+ {{avmplus, Object}, Remaining, Objects};
+
+read(<<?STRICT_ARRAY, Size:32, Remaining/binary>>, Objects) ->
+ store_in_refs(fun(Objects1) ->
+ read_array(Remaining, Size, [], Objects1)
+ end, Objects);
+
+read(<<?ECMA_ARRAY, _Size:32, Remaining/binary>>, Objects) ->
+ {{object,Val}, Rest, Objects2} = store_in_refs(fun(Objects1) ->
+ read_object(Remaining, [], Objects1, ecma_array)
+ end, Objects),
+ {Val, Rest, Objects2};
+
+read(<<?OBJECT, Remaining/binary>>, Objects) ->
+ store_in_refs(fun(Objects1) ->
+ read_object(Remaining, [], Objects1, undefined)
+ end, Objects);
+
+read(<<?TYPED_OBJECT, Len:16, Class:Len/binary, Remaining/binary>>, Objects) ->
+ store_in_refs(fun(Objects1) ->
+ read_object(Remaining, [], Objects1, binary_to_atom(Class, utf8))
+ end, Objects);
+
+read(<<?REFERENCE, Index:16, Remaining/binary>>, Objects) ->
+ ?D({"Read",Index}),
+ {dict:fetch(Index, Objects), Remaining, Objects}.
+
+read_array(Remaining, Size, Array, Objects) when length(Array) == Size ->
+ {lists:reverse(Array), Remaining, Objects};
+
+read_array(Bin, Size, Array, Objects) ->
+ {Val, Remaining, Objects1} = read(Bin, Objects),
+ read_array(Remaining, Size, [Val|Array], Objects1).
+
+
+read_object(<<0:16, ?OBJECT_END, Remaining/binary>>, Object, Objects, Class) ->
+ Val = case Class of
+ undefined -> {object, lists:reverse(Object)};
+ ecma_array -> {object, lists:reverse(Object)};
+ _ -> {object, Class, lists:reverse(Object)}
+ end,
+ {Val, Remaining, Objects};
+
+read_object(<<Len:16, Key:Len/binary, Bin/binary>>, Object, Objects, Class) ->
+ {Val, Remaining, Objects1} = read(Bin, Objects),
+ K = case Class of
+ ecma_array -> Key;
+ _ -> binary_to_atom(Key, utf8)
+ end,
+ read_object(Remaining, [{K, Val}|Object], Objects1, Class).
+
+store_in_refs(Fun, Objects) ->
+ Index = dict:size(Objects),
+ Objects1 = dict:store(Index, place_holder, Objects),
+ {Val, Remaining, Objects2} = Fun(Objects1),
+ {Val, Remaining, dict:store(Index, Val, Objects2)}.
%%---------------------------------------
@@ -120,5 +175,50 @@ write({xmldoc, XML}, Objects) ->
write({avmplus, Object}, Objects) ->
Binary = amf3:encode(Object),
- {<<?AVMPLUS_OBJECT, Binary/binary>>, Objects}.
+ {<<?AVMPLUS_OBJECT, Binary/binary>>, Objects};
+
+write({object, Object}, Objects) ->
+ write_object(Object, <<?OBJECT>>, Objects);
+
+write({object, Name, Object}, Objects) ->
+ NameS = binarize(Name),
+ write_object(Object, <<?TYPED_OBJECT, (size(NameS)):16, NameS/binary>>, Objects);
+
+write([{Key,_Value}|_] = Object, Objects) when is_binary(Key) ->
+ write_object(Object, <<?ECMA_ARRAY, (length(Object)):32>>, Objects);
+
+
+write([{_Key,_Value}|_] = Object, Objects) ->
+ write({object, Object}, Objects);
+
+write(Array, Objects) when is_list(Array) ->
+ write_array(Array, <<?STRICT_ARRAY, (length(Array)):32>>, Objects).
+
+
+write_array([], Acc, Objects) ->
+ {Acc, Objects};
+
+write_array([Value|Array], Acc, Objects) ->
+ {Bin, Objects1} = write(Value, Objects),
+ write_array(Array, <<Acc/binary, Bin/binary>>, Objects1).
+
+
+write_object([], Acc, Objects) ->
+ {<<Acc/binary, 0:16, ?OBJECT_END>>, Objects};
+
+write_object([{Key,Value}|Array], Acc, Objects) ->
+ {Bin, Objects1} = write(Value, Objects),
+ KeyS = binarize(Key),
+ write_object(Array, <<Acc/binary, (size(KeyS)):16, KeyS/binary, Bin/binary>>, Objects1).
+
+
+binarize(S) when is_atom(S) -> atom_to_binary(S, latin1);
+binarize(S) when is_list(S) -> list_to_binary(S);
+binarize(S) when is_binary(S) -> S;
+binarize(S) when is_integer(S) -> binarize(integer_to_list(S)).
+
+
+
+
+
View
53 src/amf0_tests.erl
@@ -3,24 +3,31 @@
-define(assertEncode(Term, AMF), (AMF == amf0:encode(Term))).
+-define(_assertEncode(Term, AMF), ?_assertEqual(AMF, amf0:encode(Term))).
+
-define(assertDecode(Term, AMF), ({Term,<<>>} == amf0:decode(AMF))).
+-define(_assertDecode(Term, AMF), ?_assertEqual({Term,<<>>}, amf0:decode(AMF))).
+
-define(assertEncodeDecode(Term), ({Term,<<>>} == amf0:decode(amf0:encode(Term)))).
+-define(_assertEncodeDecode(Term), ?_assertEqual({Term,<<>>}, amf0:decode(amf0:encode(Term)))).
+
-define(assertDecodeEncode(AMF), (AMF == amf0:encode(element(1,amf0:decode(AMF))))).
+-define(_assertDecodeEncode(AMF), ?_assertEqual(AMF, amf0:encode(element(1,amf0:decode(AMF))))).
-define(a(Term, AMF), ?assert(?assertEncode(Term, AMF) and
?assertDecode(Term, AMF) and
?assertEncodeDecode(Term) and
?assertDecodeEncode(AMF))).
--define(_a(Term, AMF), ?_assert(?assertEncode(Term, AMF) and
- ?assertDecode(Term, AMF) and
- ?assertEncodeDecode(Term) and
- ?assertDecodeEncode(AMF))).
+-define(_a(Term, AMF), [?_assertEncode(Term, AMF),
+ ?_assertDecode(Term, AMF),
+ ?_assertEncodeDecode(Term),
+ ?_assertDecodeEncode(AMF)]).
number_test_() ->
[
- ?_a(10,<<16#00,16#40,16#24,16#00,16#00,16#00,16#00,16#00,16#00>>),
- ?_a(-500,<<16#00,16#C0,16#7F,16#40,16#00,16#00,16#00,16#00,16#00>>)
+ ?_a(10.0,<<16#00,16#40,16#24,16#00,16#00,16#00,16#00,16#00,16#00>>),
+ ?_a(-500.0,<<16#00,16#C0,16#7F,16#40,16#00,16#00,16#00,16#00,16#00>>)
].
true_test() -> ?a(true,<<16#01,16#01>>).
@@ -35,6 +42,7 @@ date_test() -> ?a({date,1261385577404.0},<<16#0B,16#42,16#72,16#5B,16#07,16#07,1
string_test_() ->
[
?_a(<<"hello">>,<<16#02,16#00,16#05,"hello">>),
+ ?_a(<<"">>,<<16#02,16#00,16#00>>),
?_a(<<"hello world">>,<<16#02,16#00,16#0B,"hello world">>)
].
@@ -51,12 +59,37 @@ string_atom_test_() ->
].
xmldoc_test_() ->
- [
- ?_a({xmldoc,<<"<test>hello</test>">>},<<16#0F,16#00,16#00,16#00,16#12,"<test>hello</test>">>)
- ].
+ ?_a({xmldoc,<<"<test>hello</test>">>},<<16#0F,16#00,16#00,16#00,16#12,"<test>hello</test>">>).
avmplus_test_() ->
[
?_assertEqual(list_to_binary([16#11,amf3:encode(<<"hello">>)]), amf0:encode({avmplus,<<"hello">>})),
?_assertEqual(element(1,amf3:decode(<<16#00>>)), element(2,element(1,amf0:decode(<<16#11,16#00>>))))
- ].
+ ].
+
+array_test_() ->
+ ?_a([true], <<10,0,0,0,1,1,1>>).
+
+ecma_array_test_() ->
+ ?_a([{<<"key">>,true}], <<8,0,0,0,1,0,3,"key",1,1,0,0,9>>).
+
+
+object_test_() ->
+ [ ?_assertEncode([{packet,raw},{s,true}], <<3,0,6,"packet",2,0,3,"raw",0,1,"s",1,1,0,0,9>>) ] ++
+ ?_a({object, [{packet,<<"raw">>},{s,true}]}, <<3,0,6,"packet",2,0,3,"raw",0,1,"s",1,1,0,0,9>>).
+
+typed_object_test_() ->
+ ?_a({object, 'Socket', [{packet,<<"raw">>},{s,true}]}, <<16,0,6,"Socket",0,6,"packet",2,0,3,"raw",0,1,"s",1,1,0,0,9>>) ++
+ [
+ ?_assertEncode({object, <<"Socket">>, [{packet,raw},{s,true}]}, <<16,0,6,"Socket",0,6,"packet",2,0,3,"raw",0,1,"s",1,1,0,0,9>>),
+ ?_assertEncode({object, "Socket", [{packet,raw},{s,true}]}, <<16,0,6,"Socket",0,6,"packet",2,0,3,"raw",0,1,"s",1,1,0,0,9>>)
+ ].
+
+
+references_test_() ->
+ [
+ ?_assertDecode([{object, [{zz,true}]},{object,[{zz,true}]}], <<10,0,0,0,2,3,0,2,"zz",1,1,0,0,9,7,0,1>>)
+ % ?_a([{object, [{<<"zz">>,true}]},{object,[{<<"zz">>,true}]}], <<10,0,0,0,2,3,0,2,"zz",1,1,0,0,9,7,0,1>>)
+ ].
+
+
View
170 src/amf3_tests.erl
@@ -3,19 +3,26 @@
-define(assertEncode(Term, AMF), (AMF == amf3:encode(Term))).
+-define(_assertEncode(Term, AMF), ?_assertEqual(AMF, amf3:encode(Term))).
+
-define(assertDecode(Term, AMF), ({Term,<<>>} == amf3:decode(AMF))).
+-define(_assertDecode(Term, AMF), ?_assertEqual({Term,<<>>}, amf3:decode(AMF))).
+
-define(assertEncodeDecode(Term), ({Term,<<>>} == amf3:decode(amf3:encode(Term)))).
+-define(_assertEncodeDecode(Term), ?_assertEqual({Term,<<>>}, amf3:decode(amf3:encode(Term)))).
+
-define(assertDecodeEncode(AMF), (AMF == amf3:encode(element(1,amf3:decode(AMF))))).
+-define(_assertDecodeEncode(AMF), ?_assertEqual(AMF, amf3:encode(element(1,amf3:decode(AMF))))).
-define(a(Term, AMF), ?assert(?assertEncode(Term, AMF) and
?assertDecode(Term, AMF) and
?assertEncodeDecode(Term) and
?assertDecodeEncode(AMF))).
--define(_a(Term, AMF), ?_assert(?assertEncode(Term, AMF) and
- ?assertDecode(Term, AMF) and
- ?assertEncodeDecode(Term) and
- ?assertDecodeEncode(AMF))).
+-define(_a(Term, AMF), [?_assertEncode(Term, AMF),
+ ?_assertDecode(Term, AMF),
+ ?_assertEncodeDecode(Term),
+ ?_assertDecodeEncode(AMF)]).
@@ -30,19 +37,17 @@ true_test() -> ?a(true, <<16#03>>).
%% integers -268435456 to 268435455 are encoded as integers
integer_test_() ->
- [
- ?_a(-268435456, <<16#04,16#C0,16#80,16#80,16#00>>),
- ?_a(-10, <<16#04,16#FF,16#FF,16#FF,16#F6>>),
- ?_a(-1, <<16#04,16#FF,16#FF,16#FF,16#FF>>),
- ?_a(0, <<16#04,16#00>>),
- ?_a(127, <<16#04,16#7F>>),
- ?_a(128, <<16#04,16#81,16#00>>),
- ?_a(16383, <<16#04,16#FF,16#7F>>),
- ?_a(16384, <<16#04,16#81,16#80,16#00>>),
- ?_a(2097151, <<16#04,16#FF,16#FF,16#7F>>),
- ?_a(2097152,<<16#04,16#80,16#C0,16#80,16#00>>),
- ?_a(268435455, <<16#04,16#BF,16#FF,16#FF,16#FF>>)
- ].
+ ?_a(-268435456, <<16#04,16#C0,16#80,16#80,16#00>>) ++
+ ?_a(-10, <<16#04,16#FF,16#FF,16#FF,16#F6>>) ++
+ ?_a(-1, <<16#04,16#FF,16#FF,16#FF,16#FF>>) ++
+ ?_a(0, <<16#04,16#00>>) ++
+ ?_a(127, <<16#04,16#7F>>) ++
+ ?_a(128, <<16#04,16#81,16#00>>) ++
+ ?_a(16383, <<16#04,16#FF,16#7F>>) ++
+ ?_a(16384, <<16#04,16#81,16#80,16#00>>) ++
+ ?_a(2097151, <<16#04,16#FF,16#FF,16#7F>>) ++
+ ?_a(2097152,<<16#04,16#80,16#C0,16#80,16#00>>) ++
+ ?_a(268435455, <<16#04,16#BF,16#FF,16#FF,16#FF>>).
%% Integer values -1.79e308 to -268435457 and 268435456 to 1.79e308 are encoded as doubles
@@ -56,28 +61,24 @@ integer_outside_range_test_() ->
%% All floating point Numbers are enoded as doubles
%% These constants of the AS3 Number class are also encoded as doubles >> -infinity, infinity, nan
double_test_() ->
- [
- ?_a(268435456.0, <<16#05,16#41,16#B0,16#00,16#00,16#00,16#00,16#00,16#00>>),
- ?_a(268435456.5, <<16#05,16#41,16#B0,16#00,16#00,16#00,16#80,16#00,16#00>>),
- ?_a(10.1, <<16#05,16#40,16#24,16#33,16#33,16#33,16#33,16#33,16#33>>),
- ?_a(-268435457.0, <<16#05,16#C1,16#B0,16#00,16#00,16#01,16#00,16#00,16#00>>),
- ?_a(-72057594037927940.0, <<16#05,16#C3,16#70,16#00,16#00,16#00,16#00,16#00,16#00>>),
- ?_a(72057594037927940.0, <<16#05,16#43,16#70,16#00,16#00,16#00,16#00,16#00,16#00>>),
- ?_a(1.79e308, <<16#05,16#7F,16#EF,16#DC,16#F1,16#58,16#AD,16#BB,16#99>>),
- ?_a(-1.79e308, <<16#05,16#FF,16#EF,16#DC,16#F1,16#58,16#AD,16#BB,16#99>>),
- ?_a(infinity, <<16#05,16#7F,16#F0,16#00,16#00,16#00,16#00,16#00,16#00>>),
- ?_a('-infinity', <<16#05,16#FF,16#F0,16#00,16#00,16#00,16#00,16#00,16#00>>),
- ?_a(nan, <<16#05,16#FF,16#F8,16#00,16#00,16#00,16#00,16#00,16#00>>)
- ].
+ ?_a(268435456.0, <<16#05,16#41,16#B0,16#00,16#00,16#00,16#00,16#00,16#00>>) ++
+ ?_a(268435456.5, <<16#05,16#41,16#B0,16#00,16#00,16#00,16#80,16#00,16#00>>) ++
+ ?_a(10.1, <<16#05,16#40,16#24,16#33,16#33,16#33,16#33,16#33,16#33>>) ++
+ ?_a(-268435457.0, <<16#05,16#C1,16#B0,16#00,16#00,16#01,16#00,16#00,16#00>>) ++
+ ?_a(-72057594037927940.0, <<16#05,16#C3,16#70,16#00,16#00,16#00,16#00,16#00,16#00>>) ++
+ ?_a(72057594037927940.0, <<16#05,16#43,16#70,16#00,16#00,16#00,16#00,16#00,16#00>>) ++
+ ?_a(1.79e308, <<16#05,16#7F,16#EF,16#DC,16#F1,16#58,16#AD,16#BB,16#99>>) ++
+ ?_a(-1.79e308, <<16#05,16#FF,16#EF,16#DC,16#F1,16#58,16#AD,16#BB,16#99>>) ++
+ ?_a(infinity, <<16#05,16#7F,16#F0,16#00,16#00,16#00,16#00,16#00,16#00>>) ++
+ ?_a('-infinity', <<16#05,16#FF,16#F0,16#00,16#00,16#00,16#00,16#00,16#00>>) ++
+ ?_a(nan, <<16#05,16#FF,16#F8,16#00,16#00,16#00,16#00,16#00,16#00>>).
string_test_() ->
- [
- ?_a(<<"">>, <<16#06,16#01>>),
- ?_a(<<"hello">>, <<16#06,16#0B,"hello">>),
- ?_a(<<"hello world">>, <<16#06,16#17,"hello world">>),
- ?_a(<<"œ∑´®†¥¨ˆøπ“‘«åß∂©˙∆˚¬…æΩç√˜µ≤≥÷">>, <<16#06,16#81,16#11,"œ∑´®†¥¨ˆøπ“‘«åß∂©˙∆˚¬…æΩç√˜µ≤≥÷">>)
- ].
+ ?_a(<<"">>, <<16#06,16#01>>) ++
+ ?_a(<<"hello">>, <<16#06,16#0B,"hello">>) ++
+ ?_a(<<"hello world">>, <<16#06,16#17,"hello world">>) ++
+ ?_a(<<"œ∑´®†¥¨ˆøπ“‘«åß∂©˙∆˚¬…æΩç√˜µ≤≥÷">>, <<16#06,16#81,16#11,"œ∑´®†¥¨ˆøπ“‘«åß∂©˙∆˚¬…æΩç√˜µ≤≥÷">>).
%% atoms are encoded as strings
@@ -89,155 +90,132 @@ string_atom_test_() ->
string_refernece_test_() ->
- [
?_a([<<"hello">>,<<"world">>,<<"hello">>,<<"world">>,<<"hello">>,<<"world">>],
- <<16#09,16#0D,16#01,16#06,16#0B,"hello",16#06,16#0B,"world",16#06,16#00,16#06,16#02,16#06,16#00,16#06,16#02>>),
+ <<16#09,16#0D,16#01,16#06,16#0B,"hello",16#06,16#0B,"world",16#06,16#00,16#06,16#02,16#06,16#00,16#06,16#02>>) ++
?_a({object,<<>>, [{<<"a">>, <<"hello">>},{<<"b">>, <<"hello">>}]},
- <<16#0A,16#0B,16#01,16#03,"a",16#06,16#0B,"hello",16#03,"b",16#06,16#02,16#01>>)
- ].
+ <<16#0A,16#0B,16#01,16#03,"a",16#06,16#0B,"hello",16#03,"b",16#06,16#02,16#01>>).
xmldoc_test_() ->
- [
- ?_a({xmldoc,<<"<text>hello</text>">>}, <<16#07,16#25,"<text>hello</text>">>)
- ].
+ ?_a({xmldoc,<<"<text>hello</text>">>}, <<16#07,16#25,"<text>hello</text>">>).
xmldoc_reference_test_() ->
- [
?_a([{xmldoc,<<"<t />">>},{xmldoc,<<"<t />">>}],
- <<16#09,16#05,16#01,16#07,16#0B,16#3C,16#74,16#20,16#2F,16#3E,16#07,16#02>>),
+ <<16#09,16#05,16#01,16#07,16#0B,16#3C,16#74,16#20,16#2F,16#3E,16#07,16#02>>) ++
?_a([{xmldoc,<<"<test>hello</test>">>},{xmldoc,<<"<test>world</test>">>},{xmldoc,<<"<test>hello</test>">>},
{xmldoc,<<"<test>world</test>">>},{xmldoc,<<"<test>hello</test>">>},{xmldoc,<<"<test>world</test>">>}],
<<16#09,16#0D,16#01,16#07,16#25,"<test>hello</test>",16#07,16#25,"<test>world</test>",16#07,16#02,
- 16#07,16#04,16#07,16#02,16#07,16#04>>),
+ 16#07,16#04,16#07,16#02,16#07,16#04>>) ++
?_a({object,<<>>,[{<<"a">>,{xmldoc,<<"<hello>test</hello>">>}},{<<"b">>,{xmldoc,<<"<hello>test</hello>">>}}]},
- <<16#0A,16#0B,16#01,16#03,"a",16#07,16#27,"<hello>test</hello>",16#03,"b",16#07,16#02,16#01>>)
- ].
+ <<16#0A,16#0B,16#01,16#03,"a",16#07,16#27,"<hello>test</hello>",16#03,"b",16#07,16#02,16#01>>).
date_test_() ->
- [
- ?_a({date,1260103478896.0},<<16#08,16#01,16#42,16#72,16#56,16#40,16#52,16#E7,16#00,16#00>>)
- ].
+ ?_a({date,1260103478896.0},<<16#08,16#01,16#42,16#72,16#56,16#40,16#52,16#E7,16#00,16#00>>).
date_reference_test_() ->
- [
?_a([{date,1263191109672.0},{date,1263191109672.0}],
- <<16#09,16#05,16#01,16#08,16#01,16#42,16#72,16#61,16#C0,16#EB,16#02,16#80,16#00,16#08,16#02>>),
+ <<16#09,16#05,16#01,16#08,16#01,16#42,16#72,16#61,16#C0,16#EB,16#02,16#80,16#00,16#08,16#02>>) ++
?_a({object,<<>>,[{<<"a">>,{date,1261385577404.0}},{<<"b">>,{date,1261385577404.0}}]},
<<16#0A,16#0B,16#01,16#03,16#61,16#08,16#01,16#42,16#72,16#5B,16#07,16#07,16#3B,16#C0,
- 16#00,16#03,16#62,16#08,16#02,16#01>>)
- ].
+ 16#00,16#03,16#62,16#08,16#02,16#01>>).
array_test_() ->
- [
%% dense
- ?_a([100],<<16#09,16#03,16#01,16#04,16#64>>),
- ?_a([100,200],<<16#09,16#05,16#01,16#04,16#64,16#04,16#81,16#48>>),
- ?_a([null,[100,200],false],<<16#09,16#07,16#01,16#01,16#09,16#05,16#01,16#04,16#64,16#04,16#81,16#48,16#02>>),
+ ?_a([100],<<16#09,16#03,16#01,16#04,16#64>>) ++
+ ?_a([100,200],<<16#09,16#05,16#01,16#04,16#64,16#04,16#81,16#48>>) ++
+ ?_a([null,[100,200],false],<<16#09,16#07,16#01,16#01,16#09,16#05,16#01,16#04,16#64,16#04,16#81,16#48,16#02>>) ++
%% associative only
- ?_a([{a,100},{b,200}],<<16#09,16#01,16#03,16#61,16#04,16#64,16#03,16#62,16#04,16#81,16#48,16#01>>),
+ ?_a([{a,100},{b,200}],<<16#09,16#01,16#03,16#61,16#04,16#64,16#03,16#62,16#04,16#81,16#48,16#01>>) ++
%% mixed
?_a([{a,100},{b,200},500,600],
- <<16#09,16#05,16#03,16#61,16#04,16#64,16#03,16#62,16#04,16#81,16#48,16#01,16#04,16#83,16#74,16#04,16#84,16#58>>)
- ].
+ <<16#09,16#05,16#03,16#61,16#04,16#64,16#03,16#62,16#04,16#81,16#48,16#01,16#04,16#83,16#74,16#04,16#84,16#58>>).
array_reference_test_() ->
- [
?_a([[100,200],[300,400],[100,200],[300,400],[100,200],[300,400]],
<<16#09,16#0D,16#01,16#09,16#05,16#01,16#04,16#64,16#04,16#81,16#48,16#09,16#05,
- 16#01,16#04,16#82,16#2C,16#04,16#83,16#10,16#09,16#02,16#09,16#04,16#09,16#02,16#09,16#04>>),
+ 16#01,16#04,16#82,16#2C,16#04,16#83,16#10,16#09,16#02,16#09,16#04,16#09,16#02,16#09,16#04>>) ++
?_a({object,<<>>,[{<<"a">>,[100,200]},{<<"b">>,[100,200]}]},
<<16#0A,16#0B,16#01,16#03,16#61,16#09,16#05,16#01,16#04,16#64,16#04,16#81,16#48,16#03,16#62,
- 16#09,16#02,16#01>>)
- ].
+ 16#09,16#02,16#01>>).
xml_test_() ->
- [
- ?_a({xml,<<"<text>hello</text>">>},<<16#0B,16#25,"<text>hello</text>">>)
- ].
+ ?_a({xml,<<"<text>hello</text>">>},<<16#0B,16#25,"<text>hello</text>">>).
xml_reference_test_() ->
- [
?_a([{xml,<<"<t/>">>},{xml,<<"<t/>">>}],
- <<16#09,16#05,16#01,16#0B,16#09,16#3C,16#74,16#2F,16#3E,16#0B,16#02>>),
+ <<16#09,16#05,16#01,16#0B,16#09,16#3C,16#74,16#2F,16#3E,16#0B,16#02>>) ++
?_a([{xml,<<"<test>hello</test>">>},{xml,<<"<test>world</test>">>},{xml,<<"<test>hello</test>">>},
{xml,<<"<test>world</test>">>},{xml,<<"<test>hello</test>">>},{xml,<<"<test>world</test>">>}],
<<16#09,16#0D,16#01,16#0B,16#25,"<test>hello</test>",16#0B,16#25,"<test>world</test>",
- 16#0B,16#02,16#0B,16#04,16#0B,16#02,16#0B,16#04>>),
+ 16#0B,16#02,16#0B,16#04,16#0B,16#02,16#0B,16#04>>) ++
?_a({object,<<>>,[{<<"a">>,{xml,<<"<hello>test</hello>">>}},{<<"b">>,{xml,<<"<hello>test</hello>">>}}]},
- <<16#0A,16#0B,16#01,16#03,"a",16#0B,16#27,"<hello>test</hello>",16#03,"b",16#0B,16#02,16#01>>)
- ].
+ <<16#0A,16#0B,16#01,16#03,"a",16#0B,16#27,"<hello>test</hello>",16#03,"b",16#0B,16#02,16#01>>).
bytearray_test_() ->
- [
- ?_a({bytearray,<<100,200>>},<<16#0C,16#05,100,200>>),
- ?_a({bytearray,<<2#00000001>>},<<12,3,1>>)
- ].
+ ?_a({bytearray,<<100,200>>},<<16#0C,16#05,100,200>>) ++
+ ?_a({bytearray,<<2#00000001>>},<<12,3,1>>).
bytearray_reference_test_() ->
- [
- ?_a([{bytearray,<<1>>},{bytearray,<<1>>}],<<16#09,16#05,16#01,16#0C,16#03,16#01,16#0C,16#02>>),
+ ?_a([{bytearray,<<1>>},{bytearray,<<1>>}],<<16#09,16#05,16#01,16#0C,16#03,16#01,16#0C,16#02>>) ++
?_a({object,<<>>,[{<<"a">>,{bytearray,<<100,200>>}},{<<"b">>,{bytearray,<<100,200>>}}]},
- <<16#0A,16#0B,16#01,16#03,16#61,16#0C,16#05,16#64,16#C8,16#03,16#62,16#0C,16#02,16#01>>)
- ].
+ <<16#0A,16#0B,16#01,16#03,16#61,16#0C,16#05,16#64,16#C8,16#03,16#62,16#0C,16#02,16#01>>).
object_test_() ->
- [
- ?_a({object,<<>>,[]},<<16#0A,16#0B,16#01,16#01>>),
- ?_a({object,<<"TestClass">>,[]},<<16#0A,16#03,16#13,"TestClass">>),
- ?_a([{object,<<>>,[]},{object,<<>>,[]}],<<16#09,16#05,16#01,16#0A,16#0B,16#01,16#01,16#0A,16#02>>),
+ ?_a({object,<<>>,[]},<<16#0A,16#0B,16#01,16#01>>) ++
+ ?_a({object,<<"TestClass">>,[]},<<16#0A,16#03,16#13,"TestClass">>) ++
+ ?_a([{object,<<>>,[]},{object,<<>>,[]}],<<16#09,16#05,16#01,16#0A,16#0B,16#01,16#01,16#0A,16#02>>) ++
?_a([{object,<<"TestClass">>,[]},{object,<<"TestClass">>,[]}],
- <<16#09,16#05,16#01,16#0A,16#03,16#13,"TestClass",16#0A,16#02>>),
+ <<16#09,16#05,16#01,16#0A,16#03,16#13,"TestClass",16#0A,16#02>>) ++
?_a([{object,<<"TestClass">>,[{n1,null},{n2,null}]},{object,<<"TestClass">>,[{n1,null},{n2,null}]}],
- <<16#09,16#05,16#01,16#0A,16#23,16#13,"TestClass",16#05,"n1",16#05,"n2",16#01,16#01,16#0A,16#02>>),
+ <<16#09,16#05,16#01,16#0A,16#23,16#13,"TestClass",16#05,"n1",16#05,"n2",16#01,16#01,16#0A,16#02>>) ++
?_a({object,<<>>,[{<<"a">>,100},{<<"b">>,200}]},
- <<16#0A,16#0B,16#01,16#03,16#61,16#04,16#64,16#03,16#62,16#04,16#81,16#48,16#01>>),
+ <<16#0A,16#0B,16#01,16#03,16#61,16#04,16#64,16#03,16#62,16#04,16#81,16#48,16#01>>) ++
?_a({object,<<"TestClass">>,[{n1,<<"hello">>},{n2,<<"world">>}]},
- <<16#0A,16#23,16#13,"TestClass",16#05,"n1",16#05,"n2",16#06,16#0B,"hello",16#06,16#0B,"world">>),
+ <<16#0A,16#23,16#13,"TestClass",16#05,"n1",16#05,"n2",16#06,16#0B,"hello",16#06,16#0B,"world">>) ++
?_a({object,<<>>,[{<<"a">>,{object,<<>>,[]}},{<<"b">>,{object,<<>>,[]}}]},
- <<16#0A,16#0B,16#01,16#03,16#61,16#0A,16#01,16#01,16#03,16#62,16#0A,16#02,16#01>>),
+ <<16#0A,16#0B,16#01,16#03,16#61,16#0A,16#01,16#01,16#03,16#62,16#0A,16#02,16#01>>) ++
?_a({object,<<>>,[{<<"a">>,{object,<<"TestClass">>,[{n1,null},{n2,null}]}}]},
<<16#0A,16#0B,16#01,16#03,16#61,16#0A,16#23,16#13,16#54,16#65,16#73,16#74,16#43,16#6C,
- 16#61,16#73,16#73,16#05,16#6E,16#31,16#05,16#6E,16#32,16#01,16#01,16#01>>),
+ 16#61,16#73,16#73,16#05,16#6E,16#31,16#05,16#6E,16#32,16#01,16#01,16#01>>) ++
?_a({object,<<>>,[{<<"a">>,{object,<<>>,[{<<"x">>,100},{<<"y">>,200}]}},
{<<"b">>,{object,<<>>,[{<<"x">>,100},{<<"y">>,200}]}}]},
<<16#0A,16#0B,16#01,16#03,16#61,16#0A,16#01,16#03,16#78,16#04,16#64,16#03,16#79,16#04,16#81,
- 16#48,16#01,16#03,16#62,16#0A,16#02,16#01>>),
+ 16#48,16#01,16#03,16#62,16#0A,16#02,16#01>>) ++
?_a({object,<<>>,[{<<"a">>,{object,<<"TestClass">>,[{n1,null},{n2,null}]}},
{<<"b">>,{object,<<"TestClass">>,[{n1,null},{n2,null}]}}]},
<<16#0A,16#0B,16#01,16#03,16#61,16#0A, 16#23,16#13,"TestClass",16#05,16#6E,16#31,16#05,16#6E,16#32,16#01,
- 16#01,16#03,16#62,16#0A, 16#05, 16#01,16#01,16#01>>),
+ 16#01,16#03,16#62,16#0A, 16#05, 16#01,16#01,16#01>>) ++
?_a({object,<<>>,[{<<"a">>,{object,<<"TestClass">>,[{n1,<<"hello">>},{n2,<<"hello">>}]}},
{<<"b">>,{object,<<"TestClass">>,[{n1,<<"hello">>},{n2,<<"hello">>}]}}]},
<<16#0A,16#0B,16#01,16#03,16#61,16#0A,16#23,16#13,"TestClass",16#05,16#6E,16#31,16#05,16#6E,16#32,16#06,
- 16#0B,"hello",16#06,16#08,16#03,16#62,16#0A,16#02,16#01>>)
- ].
+ 16#0B,"hello",16#06,16#08,16#03,16#62,16#0A,16#02,16#01>>).
+
Please sign in to comment.
Something went wrong with that request. Please try again.