def testXid(self): sc = StringCodec() xid = Xid(format=0, global_id="gid", branch_id="bid") sc.write_compound(xid) assert sc.encoded == '\x00\x00\x00\x10\x06\x04\x07\x00\x00\x00\x00\x00\x03gid\x03bid' dec = sc.read_compound(Xid) assert xid.__dict__ == dec.__dict__
def check(self, type, value, compare=True): t = PRIMITIVE[type] sc = StringCodec() sc.write_primitive(t, value) decoded = sc.read_primitive(t) if compare: assert decoded == value, "%s, %s" % (decoded, value) return decoded
def testSessionHeader(self): sc = StringCodec() sc.write_compound(Header(sync=True)) assert sc.encoded == "\x01\x01" sc = StringCodec() sc.write_compound(Header(sync=False)) assert sc.encoded == "\x01\x00"
def encdec(self, value): sc = StringCodec() sc.write_compound(value) decoded = sc.read_compound(value.__class__) return decoded
def decode(x): sc = StringCodec(x) return sc.read_primitive(type)
def encode(x): sc = StringCodec() sc.write_primitive(type, x) return sc.encoded