File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,17 +66,20 @@ def from_text(cls, value: str) -> HalfVector:
6666 @classmethod
6767 def from_binary (cls , value : bytes ) -> HalfVector :
6868 dim , unused = struct .unpack_from ('>HH' , value )
69+ data = value [4 :]
6970
70- if len (value ) != 4 + 2 * dim :
71+ if len (data ) != 2 * dim :
7172 raise ValueError ('invalid length' )
7273
7374 if unused != 0 :
7475 raise ValueError ('expected unused to be 0' )
7576
76- vec = cls .__new__ (cls )
77- vec ._value = array .array ('H' , value [4 :])
77+ arr = array .array ('H' , data )
7878 if sys .byteorder != 'big' :
79- vec ._value .byteswap ()
79+ arr .byteswap ()
80+
81+ vec = cls .__new__ (cls )
82+ vec ._value = arr
8083 return vec
8184
8285 @classmethod
Original file line number Diff line number Diff line change @@ -64,17 +64,20 @@ def from_text(cls, value: str) -> Vector:
6464 @classmethod
6565 def from_binary (cls , value : bytes ) -> Vector :
6666 dim , unused = struct .unpack_from ('>HH' , value )
67+ data = value [4 :]
6768
68- if len (value ) != 4 + 4 * dim :
69+ if len (data ) != 4 * dim :
6970 raise ValueError ('invalid length' )
7071
7172 if unused != 0 :
7273 raise ValueError ('expected unused to be 0' )
7374
74- vec = cls .__new__ (cls )
75- vec ._value = array .array ('f' , value [4 :])
75+ arr = array .array ('f' , data )
7676 if sys .byteorder != 'big' :
77- vec ._value .byteswap ()
77+ arr .byteswap ()
78+
79+ vec = cls .__new__ (cls )
80+ vec ._value = arr
7881 return vec
7982
8083 @classmethod
You can’t perform that action at this time.
0 commit comments