Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

TCyBinaryProtocol breaks streaming #70

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

TCyBinaryProtocol breaks streaming #70

eevee opened this issue Dec 23, 2014 · 1 comment

Comments

@eevee
Copy link

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
Copy link
Contributor

maralla commented Dec 24, 2014

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants