iamandi / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Implemented delimited decoding and encoding #74

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Attached a patch with a "delimited version" of pb_encode and pb_decode as seen 
in Protocol Buffers C++ or Java. Allows decoding/encoding various messages from 
the same stream.

How works:
Inserts message length before message itself. This implementation uses a 
wrapper function that reads this length and passes it (see istream->bytes_left) 
to normal decoding function.

See:
https://developers.google.com/protocol-buffers/docs/techniques#streaming
https://developers.google.com/protocol-buffers/docs/reference/java/com/google/pr
otobuf/MessageLite#writeDelimitedTo

Sincerely,
Alejandro.

Original issue reported on code.google.com by Alejandr...@gmail.com on 23 Apr 2013 at 9:33

Attachments:

GoogleCodeExporter commented 9 years ago
Hmm yeah, they may be worth including considering the official Google library & 
protobuf-c also have equivalent functions.

I doubt pb_delim_decode_noinit() is useful enough though; if someone really 
needs it, he can just do the same on the application side.

Original comment by Petteri.Aimonen on 23 Apr 2013 at 9:46

GoogleCodeExporter commented 9 years ago
I agree with pb_delim_decode_noinit(), currently I do not use it. The reason to 
implement it was to follow the current API.

Original comment by Alejandr...@gmail.com on 25 Apr 2013 at 7:07

GoogleCodeExporter commented 9 years ago
Hi all,
I have another idea how to implement messages framing:

Define globally known message named Header which includes field payload len 
(int).
On wire encode messages like this:
length of header message (X.690 - DER encoding of length)
header message encoded with pb
user message itself encoded with pb

Header message is small, expandable, could contain more info about message then 
only size etc.
Reading of wire requires only few steps.
1-2 reading of length of header
reading of header
reading of message

Original comment by P.Sta...@gmail.com on 5 Jun 2013 at 2:55

GoogleCodeExporter commented 9 years ago
Indeed there are dozens of different ways to implement framing. However, not 
all of them deserve to be included in the core library.

The delimited encoding is widely enough used that it does.

Original comment by Petteri.Aimonen on 5 Jun 2013 at 3:00

GoogleCodeExporter commented 9 years ago
This issue was updated by revision bb985e99274b.

Original comment by Petteri.Aimonen on 6 Jul 2013 at 1:18

GoogleCodeExporter commented 9 years ago
Fix included in nanopb-0.2.2

Original comment by Petteri.Aimonen on 18 Aug 2013 at 7:17