Exemple #1
0
 def deserialize_safe(cls, byts, protocol_version):
     subtype, = cls.subtypes
     length = 4
     numelements = int32_unpack(byts[:length])
     p = length
     result = []
     inner_proto = max(3, protocol_version)
     for _ in range(numelements):
         itemlen = int32_unpack(byts[p:p + length])
         p += length
         item = byts[p:p + itemlen]
         p += itemlen
         result.append(subtype.from_binary(item, inner_proto))
     return cls.adapter(result)
Exemple #2
0
 def deserialize_safe(cls, byts, protocol_version):
     key_type, value_type = cls.subtypes
     length = 4
     numelements = int32_unpack(byts[:length])
     p = length
     themap = util.OrderedMapSerializedKey(key_type, protocol_version)
     inner_proto = max(3, protocol_version)
     for _ in range(numelements):
         key_len = int32_unpack(byts[p:p + length])
         p += length
         keybytes = byts[p:p + key_len]
         p += key_len
         val_len = int32_unpack(byts[p:p + length])
         p += length
         valbytes = byts[p:p + val_len]
         p += val_len
         key = key_type.from_binary(keybytes, inner_proto)
         val = value_type.from_binary(valbytes, inner_proto)
         themap._insert_unchecked(key, keybytes, val)
     return themap
Exemple #3
0
    def deserialize_safe(cls, byts, protocol_version):
        proto_version = max(3, protocol_version)
        p = 0
        values = []
        for col_type in cls.subtypes:
            if p == len(byts):
                break
            itemlen = int32_unpack(byts[p:p + 4])
            p += 4
            if itemlen >= 0:
                item = byts[p:p + itemlen]
                p += itemlen
            else:
                item = None
            # collections inside UDTs are always encoded with at least the
            # version 3 format
            values.append(col_type.from_binary(item, proto_version))

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

        return tuple(values)
Exemple #4
0
def read_int(f):
    return int32_unpack(f.read(4))
Exemple #5
0
 def deserialize(byts, protocol_version):
     return int32_unpack(byts)
Exemple #6
0
 def deserialize(byts, protocol_version):
     scale = int32_unpack(byts[:4])
     unscaled = varint_unpack(byts[4:])
     return Decimal('%de%d' % (unscaled, -scale))