Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

read/write typed object for amf0

  • Loading branch information...
commit 9ad6cd807dadbfd818eb8c50b8f1e360c457fee7 1 parent 0c6e6cd
@trung authored
View
3  Makefile
@@ -20,4 +20,5 @@ docs:
-run edoc_run application "'BeepBeep'" '"."' '[no_packages]'
clean:
- (cd src;$(MAKE) clean)
+ (cd src;$(MAKE) clean)
+ (cd test;$(MAKE) clean)
View
9 src/amf0.erl
@@ -111,12 +111,13 @@ read_xml(Bin) ->
{ok, #xml{data = LongString#long_string.data}, NextBin}.
read_typed_object_property(Bin, Obj) ->
- {ok, PropertyName, BinAfterName} = read_string(Bin),
+ {ok, {string, PropertyName}, BinAfterName} = read_string(Bin),
+ io:fwrite("~n~p~n", [PropertyName]),
case read_object(BinAfterName) of
{object_end_marker, NextBin, _} ->
{ok, Obj, NextBin};
{ok, ObjValue, NextBin} ->
- {ok, NewObj, _} = record_utils:set(Obj, PropertyName, ObjValue),
+ {ok, NewObj, _} = record_utils:set(Obj, list_to_atom(PropertyName), ObjValue),
read_typed_object_property(NextBin, NewObj)
end.
@@ -204,7 +205,7 @@ write_object(Obj) ->
{ok, undefined} ->
{bad, {"Unknown object", ObjType, ?MODULE, ?LINE}};
{ok, ClassName} ->
- {ok, ClassNameBin} = write_string(#string{data = ClassName}),
+ {ok, ClassNameBin} = string_to_binary(#string{data = ClassName}),
case ObjType of
undefined ->
{bad, {"Object type not found even it was registered", ClassName, Obj}};
@@ -220,7 +221,7 @@ write_object(ref, Ref) -> write_reference(Ref);
write_object(amf3, Obj) -> amf3:write_object(Obj).
write_object_info(Obj, Field) ->
- {ok, FieldBin} = write_string(#string{data = atom_to_list(Field)}),
+ {ok, FieldBin} = string_to_binary(#string{data = atom_to_list(Field)}),
case record_utils:get(Obj, Field) of
{ok, undefined} ->
[];
View
14 src/record_utils.erl
@@ -57,14 +57,8 @@ get(Obj, timeToLive) when is_record(Obj, abstract_message) ->
get(Obj, timestamp) when is_record(Obj, abstract_message) ->
{ok, Obj#abstract_message.timestamp};
-get(Obj, PropertyName) when is_record(Obj, asobject) ->
- Ret = [X || {P, X} <- Obj#asobject.array, P == PropertyName],
- if
- length(Ret) == 0 -> {bad, {"PropertyName not found in the object", Obj, PropertyName}};
- true ->
- [Value|_] = Ret,
- {ok, Value}
- end;
+get(Obj, array) when is_record(Obj, asobject) ->
+ {ok, Obj#asobject.array};
get(Obj, correlationId) when is_record(Obj, async_message) ->
{ok, Obj#async_message.correlationId};
@@ -157,8 +151,8 @@ set(Obj, timestamp, Value) when is_record(Obj, abstract_message) ->
NewObj = Obj#abstract_message{timestamp = Value},
{ok, NewObj, {timestamp, Value}};
-set(Obj, PropertyName, Value) when is_record(Obj, asobject) ->
- NewObj = #asobject{array = Obj#asobject.array ++ [{PropertyName, Value}]},
+set(Obj, array, Value) when is_record(Obj, asobject) ->
+ NewObj = Obj#asobject{array = Value},
{ok, NewObj, {array, Value}};
set(Obj, correlationId, Value) when is_record(Obj, async_message) ->
View
1  test/amf0_test.erl
@@ -13,6 +13,7 @@
verify(ExpectedValue) ->
{ok, Bin} = amf0:write_object(ExpectedValue),
?assert(Bin /= <<>>),
+ ?debugFmt("~p~n", [Bin]),
{ok, ActualValue, _Rest} = amf0:read_object(Bin),
?assertEqual(ExpectedValue, ActualValue).
Please sign in to comment.
Something went wrong with that request. Please try again.