diff options
| author | Matthias Radestock <matthias@rabbitmq.com> | 2012-11-05 12:22:21 +0000 |
|---|---|---|
| committer | Matthias Radestock <matthias@rabbitmq.com> | 2012-11-05 12:22:21 +0000 |
| commit | ec58eb9caf0b399afbd2c7e37c3f79d47d1fbdc0 (patch) | |
| tree | 9c952446407487e2e48008fd988dc632c2e0d823 /src | |
| parent | 91a212abeb9d6dff75d075593c6835336bd9fc5e (diff) | |
| download | rabbitmq-server-git-ec58eb9caf0b399afbd2c7e37c3f79d47d1fbdc0.tar.gz | |
code gen property encoder
pretty much symmetric to decoder
Involves renaming of the decoder helper funs, since those names are
more meaningful for the encoder
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_binary_generator.erl | 57 |
1 files changed, 1 insertions, 56 deletions
diff --git a/src/rabbit_binary_generator.erl b/src/rabbit_binary_generator.erl index 2ece86963f..a333c1ce05 100644 --- a/src/rabbit_binary_generator.erl +++ b/src/rabbit_binary_generator.erl @@ -21,7 +21,7 @@ -export([build_simple_method_frame/3, build_simple_content_frames/4, build_heartbeat_frame/0]). --export([generate_table/1, encode_properties/2]). +-export([generate_table/1]). -export([check_empty_frame_size/0]). -export([ensure_content_encoded/2, clear_encoded_content/1]). -export([map_exception/3]). @@ -42,8 +42,6 @@ -> [frame()]). -spec(build_heartbeat_frame/0 :: () -> frame()). -spec(generate_table/1 :: (rabbit_framing:amqp_table()) -> binary()). --spec(encode_properties/2 :: - ([rabbit_framing:amqp_property_type()], [any()]) -> binary()). -spec(check_empty_frame_size/0 :: () -> 'ok'). -spec(ensure_content_encoded/2 :: (rabbit_types:content(), rabbit_types:protocol()) -> @@ -168,59 +166,6 @@ long_string_to_binary(String) when is_binary(String) -> long_string_to_binary(String) -> [<<(length(String)):32>>, String]. -encode_properties([], []) -> - <<0, 0>>; -encode_properties(TypeList, ValueList) -> - encode_properties(0, TypeList, ValueList, 0, [], []). - -encode_properties(_Bit, [], [], - FirstShortAcc, FlagsAcc, PropsAcc) -> - list_to_binary([lists:reverse(FlagsAcc), - <<FirstShortAcc:16>>, - lists:reverse(PropsAcc)]); -encode_properties(_Bit, [], _ValueList, - _FirstShortAcc, _FlagsAcc, _PropsAcc) -> - exit(content_properties_values_overflow); -encode_properties(15, TypeList, ValueList, - FirstShortAcc, FlagsAcc, PropsAcc) -> - NewFlagsShort = FirstShortAcc bor 1, % set the continuation low bit - encode_properties(0, TypeList, ValueList, - 0, [<<NewFlagsShort:16>> | FlagsAcc], PropsAcc); -encode_properties(Bit, [bit | TypeList], [true | ValueList], - FirstShortAcc, FlagsAcc, PropsAcc) -> - encode_properties(Bit + 1, TypeList, ValueList, - FirstShortAcc bor (1 bsl (15 - Bit)), FlagsAcc, PropsAcc); -encode_properties(Bit, [bit | TypeList], [false | ValueList], - FirstShortAcc, FlagsAcc, PropsAcc) -> - encode_properties(Bit + 1, TypeList, ValueList, - FirstShortAcc, FlagsAcc, PropsAcc); -encode_properties(_Bit, [bit | _TypeList], [Other | _ValueList], - _FirstShortAcc, _FlagsAcc, _PropsAcc) -> - exit({content_properties_illegal_bit_value, Other}); -encode_properties(Bit, [_Type | TypeList], [undefined | ValueList], - FirstShortAcc, FlagsAcc, PropsAcc) -> - encode_properties(Bit + 1, TypeList, ValueList, - FirstShortAcc, FlagsAcc, PropsAcc); -encode_properties(Bit, [Type | TypeList], [Value | ValueList], - FirstShortAcc, FlagsAcc, PropsAcc) -> - encode_properties(Bit + 1, TypeList, ValueList, - FirstShortAcc bor (1 bsl (15 - Bit)), FlagsAcc, - [encode_property(Type, Value) | PropsAcc]). - -encode_property(shortstr, String) -> - Len = size(String), - if Len < 256 -> <<Len:8, String:Len/binary>>; - true -> exit(content_properties_shortstr_overflow) - end; -encode_property(longstr, String) -> Len = size(String), - <<Len:32, String:Len/binary>>; -encode_property(octet, Int) -> <<Int:8/unsigned>>; -encode_property(short, Int) -> <<Int:16/unsigned>>; -encode_property(long, Int) -> <<Int:32/unsigned>>; -encode_property(longlong, Int) -> <<Int:64/unsigned>>; -encode_property(timestamp, Int) -> <<Int:64/unsigned>>; -encode_property(table, Table) -> table_to_binary(Table). - check_empty_frame_size() -> %% Intended to ensure that EMPTY_FRAME_SIZE is defined correctly. case iolist_size(create_frame(?FRAME_BODY, 0, <<>>)) of |
