Пример #1
0
 def __init__(self,
              pkr,
              dec_mapping,
              enc_mapping,
              dec_default=NotImplemented,
              enc_default=NotImplemented):
     Adapter.__init__(self, pkr)
     self.enc_mapping = enc_mapping
     self.enc_default = enc_default
     self.dec_mapping = dec_mapping
     self.dec_default = dec_default
Пример #2
0
 def __init__(self, underlying, encoding):
     Adapter.__init__(self, underlying)
     self.encoding = encoding
Пример #3
0
 def __init__(self, lengthpkr):
     underlying = Sequence(lengthpkr, Raw(this[0]))
     Adapter.__init__(self, underlying)
Пример #4
0
 def __init__(self, lengthpkr):
     Adapter.__init__(self, Sequence(lengthpkr, Raw(this[0])))
Пример #5
0
 def __init__(self, lengthpkr):
     Adapter.__init__(self, Sequence(lengthpkr, Raw(this[0])))
Пример #6
0
 def __init__(self, underlying, bits):
     Adapter.__init__(self, underlying)
     self.maxval = 1 << bits
     self.midval = self.maxval >> 1
Пример #7
0
 def __init__(self):
     self.fmt = _struct.Struct(self.FORMAT)
     Adapter.__init__(self, Raw(self.fmt.size))
Пример #8
0
 def __init__(self, bottom, top):
     Adapter.__init__(self, bottom)
     self.top = top
Пример #9
0
    __slots__ = ["maxval", "midval"]

    def __init__(self, underlying, bits):
        Adapter.__init__(self, underlying)
        self.maxval = 1 << bits
        self.midval = self.maxval >> 1

    def encode(self, obj, ctx):
        return obj + self.maxval if obj < 0 else obj

    def decode(self, obj, ctx):
        return obj - self.maxval if obj & self.midval else obj


uint24b = Adapter(Sequence(uint8, uint16b),
                  decode=lambda obj, _: (obj[0] << 16) | obj[1],
                  encode=lambda obj, _: (obj >> 16, obj & 0xffff))
sint24b = TwosComplement(uint24b, 24)
uint24l = Adapter(uint24b,
                  decode=lambda obj, _:
                  ((obj >> 16) & 0xff) | (obj & 0xff00) | ((obj & 0xff) << 16),
                  encode=lambda obj, _:
                  ((obj >> 16) & 0xff) | (obj & 0xff00) | ((obj & 0xff) << 16))
sint24l = TwosComplement(uint24l, 24)


class MaskedInteger(Adapter):
    r"""
    >>> m = MaskedInteger(uint16l,
    ...     bottom4 = (0, 4), 
    ...     upper12 = (4, 12),
Пример #10
0
 def __init__(self, bottom, top):
     Adapter.__init__(self, bottom)
     self.top = top
Пример #11
0
 def __init__(self, underlying, **flags):
     Adapter.__init__(self, underlying)
     self.flags = flags
Пример #12
0
 def __init__(self, length, padchar=six.b("\x00"), strict=False):
     self.length = _contextify(length)
     self.padchar = padchar
     self.strict = strict
     Adapter.__init__(self, Raw(self.length))
Пример #13
0
 def __init__(self, underlying, encoding):
     Adapter.__init__(self, underlying)
     self.encoding = encoding
Пример #14
0
 def __init__(self, length, padchar = six.b("\x00"), strict = False):
     self.length = _contextify(length)
     self.padchar = padchar
     self.strict = strict
     Adapter.__init__(self, Raw(self.length))
Пример #15
0
 def __init__(self):
     self.fmt = _struct.Struct(self.FORMAT)
     Adapter.__init__(self, Raw(self.fmt.size))
Пример #16
0
 def __init__(self, underlying, **flags):
     Adapter.__init__(self, underlying)
     self.flags = flags
Пример #17
0
 def __init__(self, width, swapped=False, signed=False, bytesize=8):
     Adapter.__init__(self, Raw(width))
     self.width = width
     self.swapped = swapped
     self.signed = signed
     self.bytesize = bytesize
Пример #18
0
 def __init__(self, pkr, dec_mapping, enc_mapping, dec_default = NotImplemented, enc_default = NotImplemented):
     Adapter.__init__(self, pkr)
     self.enc_mapping = enc_mapping
     self.enc_default = enc_default
     self.dec_mapping = dec_mapping
     self.dec_default = dec_default
Пример #19
0
 def __init__(self, underlying, bits):
     Adapter.__init__(self, underlying)
     self.maxval = 1 << bits
     self.midval = self.maxval >> 1
Пример #20
0
 def __init__(self, width, swapped = False, signed = False, bytesize = 8):
     Adapter.__init__(self, Raw(width))
     self.width = width
     self.swapped = swapped
     self.signed = signed
     self.bytesize = bytesize
Пример #21
0
 def __init__(self, underlying, **fields):
     Adapter.__init__(self, underlying)
     self.fields = [(k, offset, (1 << size) - 1)
                    for k, (offset, size) in fields.items()]
Пример #22
0
 def __init__(self, underlying, **fields):
     Adapter.__init__(self, underlying)
     self.fields = [(k, offset, (1 << size) - 1) for k, (offset, size) in fields.items()]
Пример #23
0
 def __init__(self, lengthpkr):
     underlying = Sequence(lengthpkr, Raw(this[0]))
     Adapter.__init__(self, underlying)