@@ -812,18 +812,13 @@ class _SimpleParameterizedType(_ParameterizedType):
812812 @classmethod
813813 def deserialize_safe (cls , byts , protocol_version ):
814814 subtype , = cls .subtypes
815- if protocol_version >= 3 :
816- unpack = int32_unpack
817- length = 4
818- else :
819- unpack = uint16_unpack
820- length = 2
821- numelements = unpack (byts [:length ])
815+ length = 4
816+ numelements = int32_unpack (byts [:length ])
822817 p = length
823818 result = []
824819 inner_proto = max (3 , protocol_version )
825820 for _ in range (numelements ):
826- itemlen = unpack (byts [p :p + length ])
821+ itemlen = int32_unpack (byts [p :p + length ])
827822 p += length
828823 if itemlen < 0 :
829824 result .append (None )
@@ -839,16 +834,15 @@ def serialize_safe(cls, items, protocol_version):
839834 raise TypeError ("Received a string for a type that expects a sequence" )
840835
841836 subtype , = cls .subtypes
842- pack = int32_pack if protocol_version >= 3 else uint16_pack
843837 buf = io .BytesIO ()
844- buf .write (pack (len (items )))
838+ buf .write (int32_pack (len (items )))
845839 inner_proto = max (3 , protocol_version )
846840 for item in items :
847841 if item is None :
848- buf .write (pack (- 1 ))
842+ buf .write (int32_pack (- 1 ))
849843 else :
850844 itembytes = subtype .to_binary (item , inner_proto )
851- buf .write (pack (len (itembytes )))
845+ buf .write (int32_pack (len (itembytes )))
852846 buf .write (itembytes )
853847 return buf .getvalue ()
854848
@@ -872,18 +866,13 @@ class MapType(_ParameterizedType):
872866 @classmethod
873867 def deserialize_safe (cls , byts , protocol_version ):
874868 key_type , value_type = cls .subtypes
875- if protocol_version >= 3 :
876- unpack = int32_unpack
877- length = 4
878- else :
879- unpack = uint16_unpack
880- length = 2
881- numelements = unpack (byts [:length ])
869+ length = 4
870+ numelements = int32_unpack (byts [:length ])
882871 p = length
883872 themap = util .OrderedMapSerializedKey (key_type , protocol_version )
884873 inner_proto = max (3 , protocol_version )
885874 for _ in range (numelements ):
886- key_len = unpack (byts [p :p + length ])
875+ key_len = int32_unpack (byts [p :p + length ])
887876 p += length
888877 if key_len < 0 :
889878 keybytes = None
@@ -893,7 +882,7 @@ def deserialize_safe(cls, byts, protocol_version):
893882 p += key_len
894883 key = key_type .from_binary (keybytes , inner_proto )
895884
896- val_len = unpack (byts [p :p + length ])
885+ val_len = int32_unpack (byts [p :p + length ])
897886 p += length
898887 if val_len < 0 :
899888 val = None
@@ -908,9 +897,8 @@ def deserialize_safe(cls, byts, protocol_version):
908897 @classmethod
909898 def serialize_safe (cls , themap , protocol_version ):
910899 key_type , value_type = cls .subtypes
911- pack = int32_pack if protocol_version >= 3 else uint16_pack
912900 buf = io .BytesIO ()
913- buf .write (pack (len (themap )))
901+ buf .write (int32_pack (len (themap )))
914902 try :
915903 items = themap .items ()
916904 except AttributeError :
@@ -919,16 +907,16 @@ def serialize_safe(cls, themap, protocol_version):
919907 for key , val in items :
920908 if key is not None :
921909 keybytes = key_type .to_binary (key , inner_proto )
922- buf .write (pack (len (keybytes )))
910+ buf .write (int32_pack (len (keybytes )))
923911 buf .write (keybytes )
924912 else :
925- buf .write (pack (- 1 ))
913+ buf .write (int32_pack (- 1 ))
926914 if val is not None :
927915 valbytes = value_type .to_binary (val , inner_proto )
928- buf .write (pack (len (valbytes )))
916+ buf .write (int32_pack (len (valbytes )))
929917 buf .write (valbytes )
930918 else :
931- buf .write (pack (- 1 ))
919+ buf .write (int32_pack (- 1 ))
932920 return buf .getvalue ()
933921
934922
0 commit comments