def encode(self, obj, context): if obj < 0 and not self.signed: raise ValueError("%r is negative, but field is not signed" % (obj,)) obj2 = num_to_bits(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 ValueError("%r is negative, but field is not signed" % (obj, )) obj2 = num_to_bits(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 bits_to_num(obj, signed = self.signed)
def decode(self, obj, context): if self.swapped: obj = swap_bytes(obj, bytesize=self.bytesize) return bits_to_num(obj, signed=self.signed)