Exemple #1
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)
Exemple #2
0
def read_short(f):
    return uint16_unpack(f.read(2))
 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)