示例#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
示例#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