Re: Problem to MergeFromCodedStream()
On Mon, Jan 12, 2009 at 8:32 PM, Dave Bailey d...@daveb.net wrote: I agree, and it seems to be a question that comes up frequently in this forum, so maybe we should add a page to the Wiki that discusses how to send and receive a stream of protobuf (or any) messages. I did add some documentation on that here: http://code.google.com/apis/protocolbuffers/docs/techniques.html#streaming Things like run length encoding, magic bytes, checksums, record types - these are either highly desirable or absolutely necessary when streaming blocks of opaque binary data over a network connection, reading a sequence of them from a file, or whatever. I think there may be a misconception out there that libprotobuf somehow magically takes care of all those things. It seems to me that people need to conceive of a serialized protobuf object as the payload to a packet, and it is their job to design a packet header that describes the payload with sufficient information such that it can be extracted and dispatched to the appropriate handler. Well said. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@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: Problem to MergeFromCodedStream()
Thank you very much for your help. I want parsing string 's' by reading each a byte from s. What is alternative way that you can recommend to me. On Jan 12, 11:28 am, chongyc chongy...@gmail.com wrote: I write test code following below. t2r::prot::Request msg0, msg2, msg3, msg4; std::string s; // set all fields of msg. . . bool b; b = msg0.SerializeToString(s); // OK msg0.PrintDebugString(); b = msg2.ParseFromString(s); // OK b = msg2.IsInitialized(); // OK msg0.PrintDebugString(); for(int i= 0; i s.size(); ++i) { char c = s[i]; std::cout == i = std::endl; google::protobuf::io::ArrayInputStream inp(c, 1); google::protobuf::io::CodedInputStream decoder(inp); b = msg3.MergeFromCodedStream(decoder); // FAILED msg3.PrintDebugString(); std::cout std::endl; b = msg4.MergePartialFromCodedStream (decoder); // OK msg4.PrintDebugString(); b = msg4.IsInitialized(); // FAILED } b = msg3.IsInitialized(); // FAILED b = msg4.IsInitialized(); // FAILED I want parsing string 's' by reading each a byte from s. What is wrong. Please help me. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@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: Problem to MergeFromCodedStream()
Read all the bytes into a buffer, then parse the buffer once you have the whole thing. On Mon, Jan 12, 2009 at 4:11 PM, chongyc chongy...@gmail.com wrote: Thank you very much for your help. I want parsing string 's' by reading each a byte from s. What is alternative way that you can recommend to me. On Jan 12, 11:28 am, chongyc chongy...@gmail.com wrote: I write test code following below. t2r::prot::Request msg0, msg2, msg3, msg4; std::string s; // set all fields of msg. . . bool b; b = msg0.SerializeToString(s); // OK msg0.PrintDebugString(); b = msg2.ParseFromString(s);// OK b = msg2.IsInitialized(); // OK msg0.PrintDebugString(); for(int i= 0; i s.size(); ++i) { char c = s[i]; std::cout == i = std::endl; google::protobuf::io::ArrayInputStream inp(c, 1); google::protobuf::io::CodedInputStream decoder(inp); b = msg3.MergeFromCodedStream(decoder); // FAILED msg3.PrintDebugString(); std::cout std::endl; b = msg4.MergePartialFromCodedStream (decoder); // OK msg4.PrintDebugString(); b = msg4.IsInitialized(); // FAILED } b = msg3.IsInitialized(); // FAILED b = msg4.IsInitialized(); // FAILED I want parsing string 's' by reading each a byte from s. What is wrong. Please help me. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@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: Problem to MergeFromCodedStream()
When I send multiple messages, I should delimit them, and parse the buffer. What is the best way delimitting it that you can recommend me ? On Jan 13, 8:18 am, Kenton Varda ken...@google.com wrote: Read all the bytes into a buffer, then parse the buffer once you have the whole thing. On Mon, Jan 12, 2009 at 4:11 PM, chongyc chongy...@gmail.com wrote: Thank you very much for your help. I want parsing string 's' by reading each a byte from s. What is alternative way that you can recommend to me. On Jan 12, 11:28 am, chongyc chongy...@gmail.com wrote: I write test code following below. t2r::prot::Request msg0, msg2, msg3, msg4; std::string s; // set all fields of msg. . . bool b; b = msg0.SerializeToString(s); // OK msg0.PrintDebugString(); b = msg2.ParseFromString(s); // OK b = msg2.IsInitialized(); // OK msg0.PrintDebugString(); for(int i= 0; i s.size(); ++i) { char c = s[i]; std::cout == i = std::endl; google::protobuf::io::ArrayInputStream inp(c, 1); google::protobuf::io::CodedInputStream decoder(inp); b = msg3.MergeFromCodedStream(decoder); // FAILED msg3.PrintDebugString(); std::cout std::endl; b = msg4.MergePartialFromCodedStream (decoder); // OK msg4.PrintDebugString(); b = msg4.IsInitialized(); // FAILED } b = msg3.IsInitialized(); // FAILED b = msg4.IsInitialized(); // FAILED I want parsing string 's' by reading each a byte from s. What is wrong. Please help me. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@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: Problem to MergeFromCodedStream()
Send the size of the message first, then the data. On Mon, Jan 12, 2009 at 4:34 PM, chongyc chongy...@gmail.com wrote: When I send multiple messages, I should delimit them, and parse the buffer. What is the best way delimitting it that you can recommend me ? On Jan 13, 8:18 am, Kenton Varda ken...@google.com wrote: Read all the bytes into a buffer, then parse the buffer once you have the whole thing. On Mon, Jan 12, 2009 at 4:11 PM, chongyc chongy...@gmail.com wrote: Thank you very much for your help. I want parsing string 's' by reading each a byte from s. What is alternative way that you can recommend to me. On Jan 12, 11:28 am, chongyc chongy...@gmail.com wrote: I write test code following below. t2r::prot::Request msg0, msg2, msg3, msg4; std::string s; // set all fields of msg. . . bool b; b = msg0.SerializeToString(s); // OK msg0.PrintDebugString(); b = msg2.ParseFromString(s);// OK b = msg2.IsInitialized(); // OK msg0.PrintDebugString(); for(int i= 0; i s.size(); ++i) { char c = s[i]; std::cout == i = std::endl; google::protobuf::io::ArrayInputStream inp(c, 1); google::protobuf::io::CodedInputStream decoder(inp); b = msg3.MergeFromCodedStream(decoder); // FAILED msg3.PrintDebugString(); std::cout std::endl; b = msg4.MergePartialFromCodedStream (decoder); // OK msg4.PrintDebugString(); b = msg4.IsInitialized(); // FAILED } b = msg3.IsInitialized(); // FAILED b = msg4.IsInitialized(); // FAILED I want parsing string 's' by reading each a byte from s. What is wrong. Please help me. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@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 -~--~~~~--~~--~--~---