def _encode(self, obj, context): if obj < 0 and not self.signed: raise BitIntegerError("object is negative, but field is not signed", obj) obj2 = int_to_bin(obj, width=self.width) if self.swapped: obj2 = swap_bytes(obj2, bytesize=self.bytesize) return obj2
def _encode(self, obj, context): if obj < 0 and not self.signed: raise BitIntegerError( "object is negative, but field is not signed", obj) obj2 = int_to_bin(obj, width=self.width) if self.swapped: obj2 = swap_bytes(obj2, bytesize=self.bytesize) return obj2
def _decode(self, obj, context): if self.swapped: obj = swap_bytes(obj, bytesize=self.bytesize) return bin_to_int(obj, signed=self.signed)
def _decode(self, obj, context): if self.swapped: obj = swap_bytes(obj, bytesize = self.bytesize) return bin_to_int(obj, signed = self.signed)