40
40
-define (AMQP10_MESSAGE_ANNOTATIONS_HEADER , <<" x-amqp-1.0-message-annotations" >>).
41
41
-define (PROTOMOD , rabbit_framing_amqp_0_9_1 ).
42
42
-define (CLASS_ID , 60 ).
43
+ -define (LONGSTR_UTF8_LIMIT , 4096 ).
43
44
44
45
-opaque state () :: # content {}.
45
46
@@ -534,16 +535,19 @@ wrap(_Type, undefined) ->
534
535
wrap (Type , Val ) ->
535
536
{Type , Val }.
536
537
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
539
545
true ->
540
546
{utf8 , V };
541
547
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
545
548
{binary , V }
546
549
end ;
550
+ from_091 (longstr , V ) -> {binary , V };
547
551
from_091 (long , V ) -> {long , V };
548
552
from_091 (unsignedbyte , V ) -> {ubyte , V };
549
553
from_091 (short , V ) -> {short , V };
@@ -614,7 +618,7 @@ to_091(Key, {int, V}) -> {Key, signedint, V};
614
618
to_091 (Key , {double , V }) -> {Key , double , V };
615
619
to_091 (Key , {float , V }) -> {Key , float , V };
616
620
to_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 };
618
622
to_091 (Key , {boolean , V }) -> {Key , bool , V };
619
623
to_091 (Key , true ) -> {Key , bool , true };
620
624
to_091 (Key , false ) -> {Key , bool , false };
@@ -637,7 +641,7 @@ to_091({int, V}) -> {signedint, V};
637
641
to_091 ({double , V }) -> {double , V };
638
642
to_091 ({float , V }) -> {float , V };
639
643
to_091 ({timestamp , V }) -> {timestamp , V div 1000 };
640
- to_091 ({binary , V }) -> {binary , V };
644
+ to_091 ({binary , V }) -> {longstr , V };
641
645
to_091 ({boolean , V }) -> {bool , V };
642
646
to_091 (true ) -> {bool , true };
643
647
to_091 (false ) -> {bool , false };
0 commit comments