7
7
import lxml
8
8
import lxml .etree
9
9
10
+
10
11
class PrimitiveType (enum .Enum ):
11
12
CHAR = 'char'
12
13
UINT8 = 'uint8'
@@ -281,10 +282,10 @@ def encode(self, vals: Iterable[str]) -> int:
281
282
return bitstring .BitArray (v .name in vals for v in reversed (self .choices )).uint
282
283
283
284
def decode (self , val : int ) -> List [str ]:
284
- if isinstance (self .encodingType , SetEncodingType ):
285
- length = FORMAT_SIZES [PrimitiveType [self .encodingType .name ]] * 8
286
- else :
287
- length = FORMAT_SIZES [self .encodingType .primitiveType ] * 8
285
+ # if isinstance(self.encodingType, SetEncodingType):
286
+ # length = FORMAT_SIZES[PrimitiveType[self.encodingType.name]] * 8
287
+ # else:
288
+ # length = FORMAT_SIZES[self.encodingType.primitiveType] * 8
288
289
289
290
return [c .name for c in self .choices if (1 << c .value ) & val ]
290
291
@@ -559,7 +560,7 @@ def wrap(self, buf: Union[bytes, memoryview], header_only=False) -> WrappedMessa
559
560
560
561
return WrappedMessage (buf , header , body )
561
562
562
- def create_wrappers (self ) -> WrappedMessage :
563
+ def create_wrappers (self ):
563
564
cursor = Cursor (0 )
564
565
565
566
pointers = {}
@@ -573,7 +574,6 @@ def create_wrappers(self) -> WrappedMessage:
573
574
_walk_fields_wrap (self , pointers , m .fields , cursor )
574
575
self .message_wrappers [i ] = WrappedComposite (m .name , pointers , None , 0 )
575
576
576
-
577
577
def _unpack_format (
578
578
schema : Schema ,
579
579
type_ : Union [Field , Group , PrimitiveType , Type , RefType , Set , Enum , Composite ],
@@ -640,6 +640,7 @@ def _unpack_format(
640
640
if isinstance (type_ , Composite ):
641
641
return prefix + '' .join (_unpack_format (schema , t , '' , buffer , buffer_cursor ) for t in type_ .types )
642
642
643
+ assert False , f"unreachable: { type_ } "
643
644
644
645
def _pack_format (_schema : Schema , composite : Composite ):
645
646
fmt = []
@@ -793,7 +794,7 @@ def _walk_fields_encode(schema: Schema, fields: List[Union[Group, Field]],
793
794
if t == PrimitiveType .CHAR :
794
795
vals .append (obj [f .name ].encode ())
795
796
else :
796
- vals .append (f . type . nullValue ) if obj [f .name ] is None else vals . append ( obj [ f . name ] )
797
+ vals .append (obj [ f . name ] if obj [f .name ] is not None else f . type . nullValue )
797
798
cursor .val += FORMAT_SIZES [t ]
798
799
799
800
elif isinstance (f .type , Set ):
@@ -822,7 +823,7 @@ def _walk_fields_encode(schema: Schema, fields: List[Union[Group, Field]],
822
823
823
824
elif isinstance (f .type , PrimitiveType ):
824
825
fmt .append (FORMAT [f .type ])
825
- vals .append (obj [f .name ].encode ()) if f .type == PrimitiveType .CHAR else vals . append ( obj [f .name ])
826
+ vals .append (obj [f .name ].encode () if f .type == PrimitiveType .CHAR else obj [f .name ])
826
827
cursor .val += FORMAT_SIZES [f .type ]
827
828
else :
828
829
assert 0
0 commit comments