Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 def _decode(self, obj, context):
     if self.swapped:
         obj = swap_bytes(obj, bytesize=self.bytesize)
     return bin_to_int(obj, signed=self.signed)
Ejemplo n.º 4
0
 def _decode(self, obj, context):
     if self.swapped:
         obj = swap_bytes(obj, bytesize = self.bytesize)
     return bin_to_int(obj, signed = self.signed)