Even if the message contains only one, non-repeated field, ParseFrom*() will
keep reading until EOF or an error.
At Google, we have lots of various container formats, for streaming,
record-based files, database tables, etc., where each record is a protocol
buffer.  All of these formats store the size of the message before the
message itself.  Our philosophy is that because we have protocol buffers,
all of these *other* formats and protocols can be designed to pass around
arbitrary byte blobs, which greatly simplifies them.  An arbitrary byte blob
is not necessarily self-delimiting, so it's up to these container formats to
keep track of the size separately.

On Thu, Sep 11, 2008 at 8:20 PM, <[EMAIL PROTECTED]> wrote:

>
> Kenton,
>
> > No, it won't work.  Protocol buffers are not self-delimiting.  They
> assume
> > that the input you provide is supposed to be one complete message, not a
> > message possibly followed by other stuff.
>
>
> There are a couple of related threads about delimiting the outer
> message (with either a marker or a length). The need for this seems to
> arise from streaming  (especially when input would block such as on a
> network socket).
>
> Could this not be solved by a simple convention in the proto file ?
> (Maybe I am missing something big here)
>
> Let us say we have a proto as follows
>
> message TRPProtocol
> {
>      message TRPPDU
>      {
>                required int32 version;
>                required int32 type;
>
>                optional HelloRequest   hello_req = 1;
>                optional HelloResponse  hello_resp = 2;
>                optional ConnectRequest connect_req =
> 3;
>                 // etc etc
>      };
>      required TRPPDU  thepdu=1;
> };
>
> On the wire the outer message is not length delimited, but the inner
> message is. The inner message is represented by the 'required' field
> 'thepdu'.
>
> It would then be possible to stream instances of the inner message
> "TRPPDU". I hope my understanding is correct. Could you write
> something like the following ?
>
> TRPProtocol::TRPPDU Pdu;
> Pdu.ParseFromFileDescriptor( socket_fd);   // socket_fd has been
> opened and initialized earlier
>
> to read just one message, respond to that if needed, and then read the
> next one.
>
> Is my understanding correct ? Is this how it is done at Google when
> using PB for client - server comms ?
>
> Thanks,
>
> Vivek
>
>
> >
> > You will need to somehow communicate the size of the message and make
> sure
> > to limit the input to that size.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to