TCyBinaryProtocol breaks streaming #70

Closed
eevee opened this Issue Dec 23, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@eevee

eevee commented Dec 23, 2014

After every read_struct, the protocol calls self.trans.clean(), which discards whatever else was left in the buffer. The non-cythonized protocol doesn't do this. Ex:

import thriftpy
from thriftpy.transport import TMemoryBuffer
from thriftpy.transport import TCyBufferedTransportFactory
from thriftpy.protocol import TCyBinaryProtocolFactory
from thriftpy.protocol import TBinaryProtocolFactory

demo_thrift = thriftpy.load('demo.thrift')  # struct Event { 1: i32 id }

buf = TMemoryBuffer()
trans = TCyBufferedTransportFactory().get_transport(buf)
proto = TCyBinaryProtocolFactory().get_protocol(trans)

proto.write_struct(demo_thrift.Event(123))
proto.write_struct(demo_thrift.Event(456))
trans.flush()

stream = buf.getvalue()

buf = TMemoryBuffer(stream)
trans = TCyBufferedTransportFactory().get_transport(buf)
proto = TBinaryProtocolFactory().get_protocol(trans)

event1 = demo_thrift.Event()
event2 = demo_thrift.Event()
proto.read_struct(event1)
print(event1)
proto.read_struct(event2)
print(event2)

buf = TMemoryBuffer(stream)
trans = TCyBufferedTransportFactory().get_transport(buf)
proto = TCyBinaryProtocolFactory().get_protocol(trans)

event1 = demo_thrift.Event()
event2 = demo_thrift.Event()
proto.read_struct(event1)
print(event1)
proto.read_struct(event2)
print(event2)

Pure-Python version works; Cython doesn't. (I don't know if this is a correct use of Thrift, but we're doing it, so I'm stuck with it. ;))

I'd send a PR but I'm not sure why this clause exists or what the intended behavior is. Maybe it was meant to be called when there's an exception, like in write_struct?

@maralla

This comment has been minimized.

Show comment
Hide comment
@maralla

maralla Dec 24, 2014

Contributor

Yeah self.trans.clean() should be only happened when exception raised.

Contributor

maralla commented Dec 24, 2014

Yeah self.trans.clean() should be only happened when exception raised.

@maralla maralla closed this in ee682be Dec 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment