Ejemplo n.º 1
0
 def deserialize_safe(cls, byts):
     subtype, = cls.subtypes
     numelements = uint16_unpack(byts[:2])
     p = 2
     result = []
     for n in xrange(numelements):
         itemlen = uint16_unpack(byts[p:p + 2])
         p += 2
         item = byts[p:p + itemlen]
         p += itemlen
         result.append(subtype.from_binary(item))
     return cls.adapter(result)
Ejemplo n.º 2
0
 def deserialize_safe(cls, byts):
     subkeytype, subvaltype = cls.subtypes
     numelements = uint16_unpack(byts[:2])
     p = 2
     themap = OrderedDict()
     for n in xrange(numelements):
         key_len = uint16_unpack(byts[p:p + 2])
         p += 2
         keybytes = byts[p:p + key_len]
         p += key_len
         val_len = uint16_unpack(byts[p:p + 2])
         p += 2
         valbytes = byts[p:p + val_len]
         p += val_len
         key = subkeytype.from_binary(keybytes)
         val = subvaltype.from_binary(valbytes)
         themap[key] = val
     return themap
Ejemplo n.º 3
0
    def deserialize_safe(cls, byts, protocol_version):
        result = []
        for subtype in cls.subtypes:
            if not byts:
                # CompositeType can have missing elements at the end
                break

            element_length = uint16_unpack(byts[:2])
            element = byts[2:2 + element_length]

            # skip element length, element, and the EOC (one byte)
            byts = byts[2 + element_length + 1:]
            result.append(subtype.from_binary(element, protocol_version))

        return tuple(result)
Ejemplo n.º 4
0
    def deserialize_safe(cls, byts):
        p = 0
        Result = collections.namedtuple(cls.typename, cls.fieldnames)
        result = []
        for col_type in cls.subtypes:
            if p == len(byts):
                break
            itemlen = uint16_unpack(byts[p:p + 2])
            p += 2
            item = byts[p:p + itemlen]
            p += itemlen
            result.append(col_type.from_binary(item))
            p += 1

        if len(result) < len(cls.subtypes):
            nones = [None] * (len(cls.subtypes) - len(result))
            result = result + nones

        return Result(*result)
Ejemplo n.º 5
0
def read_short(f):
    return uint16_unpack(f.read(2))
Ejemplo n.º 6
0
 def test_comparison(self):
     tok = BytesToken.from_string(six.text_type('0123456789abcdef'))
     token_high_order = uint16_unpack(tok.value[0:2])
     self.assertLess(BytesToken(uint16_pack(token_high_order - 1)), tok)
     self.assertGreater(BytesToken(uint16_pack(token_high_order + 1)), tok)
Ejemplo n.º 7
0
def read_short(f):
    return uint16_unpack(f.read(2))
Ejemplo n.º 8
0
 def test_comparison(self):
     tok = BytesToken.from_string(six.text_type('0123456789abcdef'))
     token_high_order = uint16_unpack(tok.value[0:2])
     self.assertLess(BytesToken(uint16_pack(token_high_order - 1)), tok)
     self.assertGreater(BytesToken(uint16_pack(token_high_order + 1)), tok)