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

Commit

Permalink
Merge pull request #31 from maralla/reading_data
Browse files Browse the repository at this point in the history
once reading in cybin may not get correct length of data
  • Loading branch information
lxyu committed Aug 28, 2014
2 parents dda6970 + 3d2beb2 commit 1bc7c7d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions thriftpy/protocol/cybin/binbuf.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,21 @@ cdef class BinaryRW(object):
if self.rbuf.data_size < size:
cap = self.rbuf.buf_size - self.rbuf.data_size
new_data = self.trans._read(cap)
new_data_len = len(new_data)

while new_data_len < size - self.rbuf.data_size:
data = self.trans._read(cap - new_data_len)
new_data += data
new_data_len += len(data)

# buf + buf_size >= buf + cur + data_size + new_data_len -->
# buf_size - data_size >= cur + new_data_len -->
# cap - cur >= new_data_len
if cap - self.rbuf.cur < len(new_data):
if cap - self.rbuf.cur < new_data_len:
self.rbuf.move_to_start()
memcpy(self.rbuf.buf + self.rbuf.cur + self.rbuf.data_size,
<byte*>new_data, len(new_data))
self.rbuf.data_size += len(new_data)
<byte*>new_data, new_data_len)
self.rbuf.data_size += new_data_len

cdef read_byte(self, byte *ret):
self.ensure_rbuf(1)
Expand Down

0 comments on commit 1bc7c7d

Please sign in to comment.