Permalink
Browse files

changed behaviour of encode object

  • Loading branch information...
1 parent 445e635 commit f9ec361ac19a1fbe928422fa6444fa1103a755f8 @maxlapshin maxlapshin committed Oct 12, 2010
Showing with 5 additions and 4 deletions.
  1. +3 −2 src/amf0.erl
  2. +2 −2 src/amf0_tests.erl
View
5 src/amf0.erl
@@ -97,7 +97,7 @@ read(<<?STRICT_ARRAY, Size:32, Remaining/binary>>, Objects) ->
read(<<?ECMA_ARRAY, _Size:32, Remaining/binary>>, Objects) ->
{{object,Val}, Rest, Objects2} = store_in_refs(fun(Objects1) ->
- read_object(Remaining, [], Objects1, undefined)
+ read_object(Remaining, [], Objects1, ecma_array)
end, Objects),
{Val, Rest, Objects2};
@@ -126,14 +126,15 @@ read_array(Bin, Size, Array, Objects) ->
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
- undefined -> Key;
+ ecma_array -> Key;
_ -> binary_to_atom(Key, utf8)
end,
read_object(Remaining, [{K, Val}|Object], Objects1, Class).
View
4 src/amf0_tests.erl
@@ -76,7 +76,7 @@ ecma_array_test_() ->
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>>).
+ ?_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>>) ++
@@ -88,7 +88,7 @@ typed_object_test_() ->
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>>)
+ ?_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>>)
].

0 comments on commit f9ec361

Please sign in to comment.