Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
 def decode(self, obj, context):
     if self.swapped:
         obj = swap_bytes(obj, bytesize = self.bytesize)
     return bits_to_num(obj, signed = self.signed)
Beispiel #4
0
 def decode(self, obj, context):
     if self.swapped:
         obj = swap_bytes(obj, bytesize=self.bytesize)
     return bits_to_num(obj, signed=self.signed)