Permalink
Browse files

remote initialize values in records, write typed object

  • Loading branch information...
1 parent 0b92c57 commit 0c6e6cd01747d99300b2250ccf1291d478db3b84 @trung committed Oct 6, 2009
Showing with 29 additions and 25 deletions.
  1. +13 −13 include/messages.hrl
  2. +6 −6 include/types.hrl
  3. +10 −6 src/amf0.erl
View
@@ -14,34 +14,34 @@
-record(abstract_message, {
clientId,
- destination = "",
- messageId = "",
- timestamp = 0,
- timeToLive = 0,
- headers = [],
+ destination,
+ messageId,
+ timestamp,
+ timeToLive,
+ headers,
body
}).
-record(rpc_message, {
parent = #abstract_message{},
- remoteUsername = "",
- remotePassword = ""
+ remoteUsername,
+ remotePassword
}).
-record(remoting_message, {
parent = #rpc_message{},
- source = "",
- operation = "",
- parameters = []
+ source,
+ operation,
+ parameters
}).
-record(async_message, {
parent = #abstract_message{},
- correlationId = "",
- correlationIdBytes = []
+ correlationId,
+ correlationIdBytes
}).
-record(command_message, {
parent = #async_message{},
- operation = ?UNKNOWN_OPERATION
+ operation
}).
View
@@ -1,14 +1,14 @@
%% AMF0 custom types
%% as it's hard to differentiate between normal list and string, we create record type string
--record(string, {data = ""}).
+-record(string, {data}).
--record(long_string, {data = ""}).
+-record(long_string, {data}).
--record(ecma_array, {data = []}).
+-record(ecma_array, {data}).
--record(asobject, {array = []}).
+-record(asobject, {array}).
--record(xml, {data = []}).
+-record(xml, {data}).
%% AMF3 custom types
--record(string_3, {data = ""}).
+-record(string_3, {data}).
View
@@ -211,7 +211,7 @@ write_object(Obj) ->
Type ->
Fields = record_utils:fields_atom(Type),
ObjBin = list_to_binary([write_object_info(Obj, X) || X <- Fields ]),
- ObjEnd = write_object_end(),
+ {ok, ObjEnd} = write_object_end(),
write_object_now(?typed_object_marker, [ClassNameBin, ObjBin, ObjEnd])
end
end.
@@ -221,9 +221,13 @@ write_object(amf3, Obj) -> amf3:write_object(Obj).
write_object_info(Obj, Field) ->
{ok, FieldBin} = write_string(#string{data = atom_to_list(Field)}),
- {ok, Value} = record_utils:get(Obj, Field),
- {ok, ValueBin} = write_object(Value),
- [FieldBin, ValueBin].
+ case record_utils:get(Obj, Field) of
+ {ok, undefined} ->
+ [];
+ {ok, Value} ->
+ {ok, ValueBin} = write_object(Value),
+ [FieldBin, ValueBin]
+ end.
%% return {ok, ReturnBin} or {bad, Reason}
write_u8(Value) -> {ok, <<Value:8>>}.
@@ -308,7 +312,7 @@ strict_array_to_binary(Value) ->
{ok, list_to_binary([LenBin, ObjBinArray])}.
write_typed_object(Value) ->
- {bad, {"Not yet implemented", ?MODULE, ?LINE}}.
+ {bad, {"Not yet implemented", Value, ?MODULE, ?LINE}}.
write_reference(Value) ->
{ok, Bin} = reference_to_binary(Value),
@@ -330,7 +334,7 @@ ecma_array_to_binary(#ecma_array{data = Value}) ->
{ok, LenBin} = write_u32(0),
ArrayBin = [write_ecma_array_item(X) || X <- Value],
{ok, ObjectEndBin} = write_object_end(),
- {ok, list_to_binary([ArrayBin ++ [ObjectEndBin]])}.
+ {ok, list_to_binary([LenBin, ArrayBin, ObjectEndBin])}.
write_null() ->
{ok, <<?null_marker:8>>}.

0 comments on commit 0c6e6cd

Please sign in to comment.