Example #1
0
 def parse(cls, bfr):
     self = cls()
     # pylint: disable=attribute-defined-outside-init
     self.tag_id = bfr.take(4)
     with Pfx(self.tag_id):
         size = UInt32BE.parse_value(bfr)
         self.flags = UInt16BE.parse_value(bfr)
         if size < 1:
             warning("size < 1")
         else:
             data_bs = bfr.take(size)
         data_type = self.tag_id_class(self.tag_id)
         if data_type is None:
             self.dataframe_body = data_bs
         else:
             databfr = CornuCopyBuffer([data_bs])
             self.datafrome_body = data_type.parse(databfr)
             if not databfr.at_eof():
                 warning("unparsed data: %r" % (databfr.take(...), ))
     return self
Example #2
0
 def parse(cls, bfr):
     self = cls()
     # pylint: disable=attribute-defined-outside-init
     self.tag_id = bfr.take(3)
     with Pfx(self.tag_id):
         sz0, sz1, sz2 = bfr.take(3)
         size = sz0 << 16 | sz1 << 8 | sz2
         if size < 1:
             warning("size < 1")
         else:
             data_bs = bfr.take(size)
         if not data_bs or data_bs[0] == 0:
             # forbidden empty data or data zeroed out
             data_type = None
         else:
             data_type = self.tag_id_class(self.tag_id)
         if data_type is None:
             self.value = data_bs
         else:
             databfr = CornuCopyBuffer([data_bs])
             self.value = data_type.parse(databfr)
             if not databfr.at_eof():
                 warning("unparsed data: %r" % (databfr.take(...), ))
     return self