77import lxml
88import lxml .etree
99
10+
1011class PrimitiveType (enum .Enum ):
1112 CHAR = 'char'
1213 UINT8 = 'uint8'
@@ -281,10 +282,10 @@ def encode(self, vals: Iterable[str]) -> int:
281282 return bitstring .BitArray (v .name in vals for v in reversed (self .choices )).uint
282283
283284 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
288289
289290 return [c .name for c in self .choices if (1 << c .value ) & val ]
290291
@@ -559,7 +560,7 @@ def wrap(self, buf: Union[bytes, memoryview], header_only=False) -> WrappedMessa
559560
560561 return WrappedMessage (buf , header , body )
561562
562- def create_wrappers (self ) -> WrappedMessage :
563+ def create_wrappers (self ):
563564 cursor = Cursor (0 )
564565
565566 pointers = {}
@@ -573,7 +574,6 @@ def create_wrappers(self) -> WrappedMessage:
573574 _walk_fields_wrap (self , pointers , m .fields , cursor )
574575 self .message_wrappers [i ] = WrappedComposite (m .name , pointers , None , 0 )
575576
576-
577577def _unpack_format (
578578 schema : Schema ,
579579 type_ : Union [Field , Group , PrimitiveType , Type , RefType , Set , Enum , Composite ],
@@ -640,6 +640,7 @@ def _unpack_format(
640640 if isinstance (type_ , Composite ):
641641 return prefix + '' .join (_unpack_format (schema , t , '' , buffer , buffer_cursor ) for t in type_ .types )
642642
643+ assert False , f"unreachable: { type_ } "
643644
644645def _pack_format (_schema : Schema , composite : Composite ):
645646 fmt = []
@@ -793,7 +794,7 @@ def _walk_fields_encode(schema: Schema, fields: List[Union[Group, Field]],
793794 if t == PrimitiveType .CHAR :
794795 vals .append (obj [f .name ].encode ())
795796 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 )
797798 cursor .val += FORMAT_SIZES [t ]
798799
799800 elif isinstance (f .type , Set ):
@@ -822,7 +823,7 @@ def _walk_fields_encode(schema: Schema, fields: List[Union[Group, Field]],
822823
823824 elif isinstance (f .type , PrimitiveType ):
824825 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 ])
826827 cursor .val += FORMAT_SIZES [f .type ]
827828 else :
828829 assert 0
0 commit comments