[protobuf] Cannot parse message with CodedInputStream over a pipe
Hi, I've a pipe where i write several pb messages, assuming that their size is kown to be 10766 bytes i wrote this code: IstreamInputStream input(std::cin); CodedInputStream in(input); while(!std:cin.eof()) { CodedInputStream::Limit limit = in.PushLimit(10766); request.Clear(); if(!request.ParseFromCodedStream(in)) { // die (cannot parse stdin) shoud die or send back error? LOG(Cannot parse pb message.); return -1; } in.PopLimit(limit); } On the caller application i open a pipe to the previous app and write a pb message of 10766 bytes and don't close the pipe but the first application never finishes the if evaluation. How does one read several messages from a pipe or file? -- You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
Re: [protobuf] Cannot parse message with CodedInputStream over a pipe
On Jul 30, 2010, at 11:18 , jetcube wrote: On the caller application i open a pipe to the previous app and write a pb message of 10766 bytes and don't close the pipe but the first application never finishes the if evaluation. PushLimit() is a little funny: It doesn't stop the CodedInputStream from attempting to fill its buffer. Thus, I think your problem is that the IstreamInputStream is probably blocked on the pipe, waiting for more data. Try using request.ParseFromBoundedZeroCopyStream() instead. Or manually use a LimitingInputStream to limit the number of bytes read, which is what that method does under the covers (I think). Evan -- Evan Jones http://evanjones.ca/ -- You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.