4040-define (AMQP10_MESSAGE_ANNOTATIONS_HEADER , <<" x-amqp-1.0-message-annotations" >>).
4141-define (PROTOMOD , rabbit_framing_amqp_0_9_1 ).
4242-define (CLASS_ID , 60 ).
43+ -define (LONGSTR_UTF8_LIMIT , 4096 ).
4344
4445-opaque state () :: # content {}.
4546
@@ -534,16 +535,19 @@ wrap(_Type, undefined) ->
534535wrap (Type , Val ) ->
535536 {Type , Val }.
536537
537- from_091 (longstr , V ) ->
538- case mc_util :is_valid_shortstr (V ) of
538+ from_091 (longstr , V )
539+ when is_binary (V ) andalso
540+ byte_size (V ) =< ? LONGSTR_UTF8_LIMIT ->
541+ % % if a longstr is longer than 4096 bytes we just assume it is binary
542+ % % it _may_ still be valid utf8 but checking this for every longstr header
543+ % % value is going to be excessively slow
544+ case mc_util :is_utf8_no_null (V ) of
539545 true ->
540546 {utf8 , V };
541547 false ->
542- % % if a string is longer than 255 bytes we just assume it is binary
543- % % it _may_ still be valid utf8 but checking this is going to be
544- % % excessively slow
545548 {binary , V }
546549 end ;
550+ from_091 (longstr , V ) -> {binary , V };
547551from_091 (long , V ) -> {long , V };
548552from_091 (unsignedbyte , V ) -> {ubyte , V };
549553from_091 (short , V ) -> {short , V };
@@ -614,7 +618,7 @@ to_091(Key, {int, V}) -> {Key, signedint, V};
614618to_091 (Key , {double , V }) -> {Key , double , V };
615619to_091 (Key , {float , V }) -> {Key , float , V };
616620to_091 (Key , {timestamp , V }) -> {Key , timestamp , V div 1000 };
617- to_091 (Key , {binary , V }) -> {Key , binary , V };
621+ to_091 (Key , {binary , V }) -> {Key , longstr , V };
618622to_091 (Key , {boolean , V }) -> {Key , bool , V };
619623to_091 (Key , true ) -> {Key , bool , true };
620624to_091 (Key , false ) -> {Key , bool , false };
@@ -637,7 +641,7 @@ to_091({int, V}) -> {signedint, V};
637641to_091 ({double , V }) -> {double , V };
638642to_091 ({float , V }) -> {float , V };
639643to_091 ({timestamp , V }) -> {timestamp , V div 1000 };
640- to_091 ({binary , V }) -> {binary , V };
644+ to_091 ({binary , V }) -> {longstr , V };
641645to_091 ({boolean , V }) -> {bool , V };
642646to_091 (true ) -> {bool , true };
643647to_091 (false ) -> {bool , false };
0 commit comments