Skip to content

Commit

Permalink
New mc_amqp state
Browse files Browse the repository at this point in the history
  • Loading branch information
ansd committed Apr 15, 2024
1 parent 2d80ec9 commit 0464769
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 211 deletions.
7 changes: 5 additions & 2 deletions deps/amqp10_common/src/amqp10_binary_parser.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
-export([parse/1,
parse_many/2]).

-ifdef(TEST).
-export([parse_many_slow/1]).
-endif.

%% TODO put often matched binary function clauses to the top?

%% server_mode is a special parsing mode used by RabbitMQ when parsing
Expand All @@ -25,7 +29,7 @@
%% AMQP 3.2.4 & 3.2.5
-define(NUMERIC_DESCRIPTOR_IS_PROPERTIES_OR_APPLICATION_PROPERTIES(Code),
Code =:= 16#73 orelse
Code =< 16#74).
Code =:= 16#74).
-define(SYMBOLIC_DESCRIPTOR_IS_PROPERTIES_OR_APPLICATION_PROPERTIES(Name),
Name =:= <<"amqp:properties:list">> orelse
Name =:= <<"amqp:application-properties:map">>).
Expand Down Expand Up @@ -185,7 +189,6 @@ mapify([Key, Value | Rest]) ->
[{Key, Value} | mapify(Rest)].

-ifdef(TEST).
-export([parse_many_slow/1]).
%% This is the old, slow, original parser implemenation before
%% https://github.com/rabbitmq/rabbitmq-server/pull/4811
%% where many sub binaries are being created.
Expand Down
4 changes: 2 additions & 2 deletions deps/amqp10_common/src/amqp10_framing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
decode_bin/1,
decode_bin/2,
symbol_for/1,
number_for/1,
number_for/1,
pprint/1]).

%% debug
Expand Down Expand Up @@ -187,7 +187,7 @@ encode_bin(X) ->

-spec decode_bin(binary()) -> [term()].
decode_bin(Binary) ->
[decode(Section) || Section <- amqp10_binary_parser:parse_many(Binary, #{})].
[decode(Section) || Section <- amqp10_binary_parser:parse_many(Binary, [])].

-spec decode_bin(binary(), amqp10_binary_parser:opts()) -> [term()].
decode_bin(Binary, Opts) ->
Expand Down
4 changes: 2 additions & 2 deletions deps/amqp10_common/test/binary_generator_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ roundtrip(Term) ->
Bin = iolist_to_binary(amqp10_binary_generator:generate(Term)),
% generate returns an iolist but parse expects a binary
?assertEqual({Term, <<>>}, amqp10_binary_parser:parse(Bin)),
?assertEqual([Term], amqp10_binary_parser:parse_many(Bin, #{})).
?assertEqual([Term], amqp10_binary_parser:parse_many(Bin, [])).

%% Return the roundtripped term.
roundtrip_return(Term) ->
Bin = iolist_to_binary(amqp10_binary_generator:generate(Term)),
%% We assert only that amqp10_binary_parser:parse/1 and
%% amqp10_binary_parser:parse_all/1 return the same term.
{RoundTripTerm, <<>>} = amqp10_binary_parser:parse(Bin),
?assertEqual([RoundTripTerm], amqp10_binary_parser:parse_many(Bin, #{})),
?assertEqual([RoundTripTerm], amqp10_binary_parser:parse_many(Bin, [])),
RoundTripTerm.
14 changes: 8 additions & 6 deletions deps/amqp10_common/test/binary_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ roundtrip(_Config) ->
end, <<>>, Terms),

?assertEqual(Terms, amqp10_binary_parser:parse_many_slow(Bin)),
?assertEqual(Terms, amqp10_binary_parser:parse_many(Bin, #{})).
?assertEqual(Terms, amqp10_binary_parser:parse_many(Bin, [])).

array_with_extra_input(_Config) ->
Bin = <<83,16,192,85,10,177,0,0,0,1,48,161,12,114,97,98,98,105,116, 109,113,45,98,111,120,112,255,255,0,0,96,0,50,112,0,0,19,136,163,5,101,110,45,85,83,224,14,2,65,5,102,105,45,70,73,5,101,110,45,85,83,64,64,193,24,2,163,20,68,69,70,69,78,83,73,67,83,46,84,69,83,84,46,83,85,73,84,69,65>>,
Expand All @@ -81,10 +81,12 @@ array_with_extra_input(_Config) ->
65, <<105,45,70,73,5,101,110,45,85,83>>, [true,true]},

?assertExit(Expected, amqp10_binary_parser:parse_many_slow(Bin)),
?assertExit(Expected, amqp10_binary_parser:parse_many(Bin, #{})).
?assertExit(Expected, amqp10_binary_parser:parse_many(Bin, [])).

unsupported_type(_Config) ->
Bin = <<2/integer, "hey">>,
Expected = {primitive_type_unsupported, 16#02, <<"hey">>},
?assertThrow(Expected, amqp10_binary_parser:parse_many_slow(Bin)),
?assertThrow(Expected, amqp10_binary_parser:parse_many(Bin, #{})).
UnsupportedType = 16#02,
Bin = <<UnsupportedType, "hey">>,
?assertThrow({primitive_type_unsupported, UnsupportedType},
amqp10_binary_parser:parse_many_slow(Bin)),
?assertThrow({primitive_type_unsupported, UnsupportedType, {position, 0}},
amqp10_binary_parser:parse_many(Bin, [])).
3 changes: 2 additions & 1 deletion deps/rabbit/src/mc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
-export_type([
state/0,
ann_key/0,
ann_value/0
ann_value/0,
annotations/0
]).

-type proto_state() :: term().
Expand Down

0 comments on commit 0464769

Please sign in to comment.