Skip to content

Commit

Permalink
Support maps in provided values
Browse files Browse the repository at this point in the history
  • Loading branch information
matehat committed Jan 24, 2016
1 parent ef658a2 commit b205ee6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/cqerl_datatypes.erl
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ encode_data({{ColType, Type}, List}, _Query) when ColType == list; ColType == se
Entries = << << (GetValueBinary(Value))/binary >> || Value <- List2 >>,
<< Length:?INT, Entries/binary >>;

encode_data({{map, KeyType, ValType}, List}, _Query) ->
encode_data({{map, KeyType, ValType}, List}, _Query) when is_list(List) ->
Length = length(List),
GetElementBinary = fun(Type, Value) ->
Bin = encode_data({Type, Value}, _Query),
Expand All @@ -430,6 +430,17 @@ encode_data({{map, KeyType, ValType}, List}, _Query) ->
(GetElementBinary(ValType, Value))/binary >> || {Key, Value} <- List >>,
<< Length:?INT, Entries/binary >>;

encode_data({{map, KeyType, ValType}, List}, _Query) ->
Length = map_size(List),
GetElementBinary = fun(Type, Value) ->
Bin = encode_data({Type, Value}, _Query),
{ok, Bytes} = encode_bytes(Bin),
Bytes
end,
Entries = << << (GetElementBinary(KeyType, Key))/binary,
(GetElementBinary(ValType, Value))/binary >> || {Key, Value} <- maps:to_list(List) >>,
<< Length:?INT, Entries/binary >>;

encode_data({{tuple, Types}, Tuple}, _Query) when is_tuple(Tuple) ->
encode_data({{tuple, Types}, tuple_to_list(Tuple)}, _Query);
encode_data({{tuple, Types}, List}, _Query) when is_list(List) ->
Expand Down

0 comments on commit b205ee6

Please sign in to comment.