Example #1
0
 def decode(self, s: bytearray) -> None:
     """
     Decode given bytearray s to this object.
     :param s: A bytearray with length at least `BYTES_LENGTH`.
     """
     assert len(s) >= self.BYTES_LENGTH, bp.NotEnoughBytes()
     ctx = bp.ProcessContext(False, s)
     self.bp_processor().process(ctx, bp.NIL_DATA_INDEXER, self)
Example #2
0
 def encode(self) -> bytearray:
     """
     Encode this object to bytearray.
     """
     s = bytearray(self.BYTES_LENGTH)
     ctx = bp.ProcessContext(True, s)
     self.bp_processor().process(ctx, bp.NIL_DATA_INDEXER, self)
     return ctx.s