42
42
-define (AMQP10_FOOTER , <<" x-amqp-1.0-footer" >>).
43
43
-define (PROTOMOD , rabbit_framing_amqp_0_9_1 ).
44
44
-define (CLASS_ID , 60 ).
45
+ -define (LONGSTR_UTF8_LIMIT , 4096 ).
45
46
46
47
-opaque state () :: # content {}.
47
48
@@ -663,16 +664,19 @@ wrap(_Type, undefined) ->
663
664
wrap (Type , Val ) ->
664
665
{Type , Val }.
665
666
666
- from_091 (longstr , V ) ->
667
- case mc_util :is_valid_shortstr (V ) of
667
+ from_091 (longstr , V )
668
+ when is_binary (V ) andalso
669
+ byte_size (V ) =< ? LONGSTR_UTF8_LIMIT ->
670
+ % % if a longstr is longer than 4096 bytes we just assume it is binary
671
+ % % it _may_ still be valid utf8 but checking this for every longstr header
672
+ % % value is going to be excessively slow
673
+ case mc_util :is_utf8_no_null (V ) of
668
674
true ->
669
675
{utf8 , V };
670
676
false ->
671
- % % if a string is longer than 255 bytes we just assume it is binary
672
- % % it _may_ still be valid utf8 but checking this is going to be
673
- % % excessively slow
674
677
{binary , V }
675
678
end ;
679
+ from_091 (longstr , V ) -> {binary , V };
676
680
from_091 (long , V ) -> {long , V };
677
681
from_091 (unsignedbyte , V ) -> {ubyte , V };
678
682
from_091 (short , V ) -> {short , V };
@@ -743,7 +747,7 @@ to_091(Key, {int, V}) -> {Key, signedint, V};
743
747
to_091 (Key , {double , V }) -> {Key , double , V };
744
748
to_091 (Key , {float , V }) -> {Key , float , V };
745
749
to_091 (Key , {timestamp , V }) -> {Key , timestamp , V div 1000 };
746
- to_091 (Key , {binary , V }) -> {Key , binary , V };
750
+ to_091 (Key , {binary , V }) -> {Key , longstr , V };
747
751
to_091 (Key , {boolean , V }) -> {Key , bool , V };
748
752
to_091 (Key , true ) -> {Key , bool , true };
749
753
to_091 (Key , false ) -> {Key , bool , false };
@@ -766,7 +770,7 @@ to_091({int, V}) -> {signedint, V};
766
770
to_091 ({double , V }) -> {double , V };
767
771
to_091 ({float , V }) -> {float , V };
768
772
to_091 ({timestamp , V }) -> {timestamp , V div 1000 };
769
- to_091 ({binary , V }) -> {binary , V };
773
+ to_091 ({binary , V }) -> {longstr , V };
770
774
to_091 ({boolean , V }) -> {bool , V };
771
775
to_091 (true ) -> {bool , true };
772
776
to_091 (false ) -> {bool , false };
0 commit comments