4242-define (AMQP10_FOOTER , <<" x-amqp-1.0-footer" >>).
4343-define (PROTOMOD , rabbit_framing_amqp_0_9_1 ).
4444-define (CLASS_ID , 60 ).
45+ -define (LONGSTR_UTF8_LIMIT , 4096 ).
4546
4647-opaque state () :: # content {}.
4748
@@ -663,16 +664,19 @@ wrap(_Type, undefined) ->
663664wrap (Type , Val ) ->
664665 {Type , Val }.
665666
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
668674 true ->
669675 {utf8 , V };
670676 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
674677 {binary , V }
675678 end ;
679+ from_091 (longstr , V ) -> {binary , V };
676680from_091 (long , V ) -> {long , V };
677681from_091 (unsignedbyte , V ) -> {ubyte , V };
678682from_091 (short , V ) -> {short , V };
@@ -743,7 +747,7 @@ to_091(Key, {int, V}) -> {Key, signedint, V};
743747to_091 (Key , {double , V }) -> {Key , double , V };
744748to_091 (Key , {float , V }) -> {Key , float , V };
745749to_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 };
747751to_091 (Key , {boolean , V }) -> {Key , bool , V };
748752to_091 (Key , true ) -> {Key , bool , true };
749753to_091 (Key , false ) -> {Key , bool , false };
@@ -766,7 +770,7 @@ to_091({int, V}) -> {signedint, V};
766770to_091 ({double , V }) -> {double , V };
767771to_091 ({float , V }) -> {float , V };
768772to_091 ({timestamp , V }) -> {timestamp , V div 1000 };
769- to_091 ({binary , V }) -> {binary , V };
773+ to_091 ({binary , V }) -> {longstr , V };
770774to_091 ({boolean , V }) -> {bool , V };
771775to_091 (true ) -> {bool , true };
772776to_091 (false ) -> {bool , false };
0 commit comments