Skip to content

Commit

Permalink
Merge pull request #54 from RAttab/upkeep/tinyints
Browse files Browse the repository at this point in the history
Upkeep/tinyints
  • Loading branch information
lpgauth authored Mar 18, 2024
2 parents 1348e01 + 934e0fd commit bc6640e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/marina_body.erl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ decode_type(<<16#F:16, Rest/binary>>) ->
{timeuuid, Rest};
decode_type(<<16#10:16, Rest/binary>>) ->
{inet, Rest};
decode_type(<<16#13:16, Rest/binary>>) ->
{smallint, Rest};
decode_type(<<16#14:16, Rest/binary>>) ->
{tinyint, Rest};
decode_type(<<16#20:16, Rest/binary>>) ->
{Type, Rest2} = decode_type(Rest),
{{list, Type}, Rest2};
Expand Down
18 changes: 17 additions & 1 deletion src/marina_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
decode_string_list/1,
decode_string_map/1,
decode_string_multimap/1,
decode_tinyint/1,
decode_uuid/1,
encode_boolean/1,
encode_bytes/1,
encode_int/1,
encode_list/1,
encode_long/1,
encode_long_string/1,
encode_short/1,
encode_short_bytes/1,
encode_string/1,
encode_string_list/1,
encode_string_map/1,
encode_string_multimap/1
encode_string_multimap/1,
encode_tinyint/1
]).

%% public
Expand Down Expand Up @@ -90,6 +93,11 @@ decode_string_map(<<Length:16, Rest/binary>>) ->
decode_string_multimap(<<Length:16, Rest/binary>>) ->
decode_string_multimap(Rest, Length, []).

-spec decode_tinyint(binary()) -> {integer(), binary()}.

decode_tinyint(<<Value:8, Rest/binary>>) ->
{Value, Rest}.

-spec decode_uuid(binary()) -> {binary(), binary()}.

decode_uuid(<<Value:16/binary, Rest/binary>>) ->
Expand All @@ -112,6 +120,11 @@ encode_bytes(Value) ->
encode_int(Value) ->
<<Value:32>>.

-spec encode_list([binary()]) -> binary().

encode_list(Values) ->
iolist_to_binary([encode_short(length(Values)), Values]).

-spec encode_long(integer()) -> binary().

encode_long(Value) ->
Expand Down Expand Up @@ -154,6 +167,9 @@ encode_string_map(KeyValues) ->
encode_string_multimap(KeyValues) ->
encode_string_multimap(KeyValues, []).

encode_tinyint(Value) ->
<<Value:8>>.

%% private
decode_long_string_set(Bin, 0, Acc) ->
{lists:reverse(Acc), Bin};
Expand Down

0 comments on commit bc6640e

Please sign in to comment.