@@ -252,6 +252,22 @@ def read_length_coded_pascal_string(self, size):
252252 length = self .read_uint_by_size (size )
253253 return self .read (length )
254254
255+ def read_variable_length_string (self ):
256+ """Read a variable length string where the first 1-5 bytes stores the
257+ length of the string.
258+
259+ For each byte, the first bit being high indicates another byte must be
260+ read.
261+ """
262+ byte = 0x80
263+ length = 0
264+ bits_read = 0
265+ while byte & 0x80 != 0 :
266+ byte = byte2int (self .read (1 ))
267+ length = length | ((byte & 0x7f ) << bits_read )
268+ bits_read = bits_read + 7
269+ return self .read (length )
270+
255271 def read_int24 (self ):
256272 a , b , c = struct .unpack ("BBB" , self .read (3 ))
257273 res = a | (b << 8 ) | (c << 16 )
@@ -342,7 +358,7 @@ def read_binary_json_type(self, t, length):
342358 elif t in (JSONB_TYPE_SMALL_ARRAY , JSONB_TYPE_LARGE_ARRAY ):
343359 return self .read_binary_json_array (length - 1 , large )
344360 elif t in (JSONB_TYPE_STRING ,):
345- return self .read_length_coded_pascal_string ( 1 )
361+ return self .read_variable_length_string ( )
346362 elif t in (JSONB_TYPE_LITERAL ,):
347363 value = self .read_uint8 ()
348364 if value == JSONB_LITERAL_NULL :
0 commit comments