On Wed, Aug 3, 2011 at 1:51 AM, cola <[email protected]> wrote:
> Hello, > > I've got the following issue: > When using self-written streambuf that may block on underflow() > (reimplements std::streambuf::underflow() ). > > Implementation of my underflow() waits for the next chunk of raw bytes > for some time. If the data arrives then streambuf continues operate. > If no data arrives EOS returned. > > The sticky thing is that when all necessary bytes to represent the > message are in buffer ParseFromIstream( my_costom_bufstream) tries to > consume all input, and it may block or/and consume more bytes than > needed. > > Is there a workaround to force protobuf not to read more than > necessary from the istream? > I've worked around this using a custom wire format (there's 1 or 2 remaining slots left) w/c is a delimiter. In my case, its 0x07 being appended as a tag (the last byte of the message stream) When the parsing code sees that tag, it stops. > Size prefixing protocol is the way, but it leads to supplier side > efficiency losses :(. > With the above approach, you don't have to prefix. You'll only have to append that 1 byte right after your message. It all works like a charm because the length of every protobuf field (excluding group) can be derived (predictable). For you to make it work, you'll probably have to patch CodedInputStream. You can take a look at *protostuff* if you need a reference for an existing implementation (java though) Hope that helps. > > > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > > -- When the cat is away, the mouse is alone. - David Yu -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
