Hi Oliver,
(I'm working with Andreas on this Project)
Am Mittwoch, 24. Juli 2013 03:54:18 UTC+2 schrieb Oliver:
>
> On Wed, Jul 24, 2013 at 12:27 AM, Andreas Reuter <
> [email protected] <javascript:>> wrote:
>
>> Hello,
>>
>> we are using Protobuf to communicate between two devices via Ad-hoc WiFi.
>> One of the devices is running a Java application and the other a Python
>> application.
>>
>
> [...]
>
>
>> 6. Upon closer inspection, we saw that the parser seems to be doing
>> alright, successfully assembling the packet message. However the message is
>> only a few bytes long, and after that the
>> parser just keeps reading the byte array(buffer, which is 128 byte long).
>> The byte array is filled with 0's. Upon reading a 0 the exception occurs.
>>
>
> Protobuf messages are not self-delimiting; you must provide some other
> mechanism yourself to find the end of the message.
> The common way is to prefix the message with a length field - see
> https://developers.google.com/protocol-buffers/docs/techniques#streaming
>
That's what I was suspecting, too. Unfortunately, python support for
delimiters is... cumbersome, but I managed to cobble something together
that works when sending protobuf messages from python to java via tcp, like
so:
from google.protobuf.internal import encoder
serializedMessage = packetMessage.SerializeToString()
delimiter = encoder._VarintBytes(len(serializedMessage))
return delimiter + serializedMessage
*But* As far as I know readDelimited() only works with inputStreams, which
kind of contradicts the whole UDP thing.
Since adding the delimiter was a tad tricky, I wasn't confident that the
following would work:
- add delimiter in python as mentioned above
- receive datagram in java
- read first bit to know length = n
- read next n bytes
- PacketMessage.parseFrom(chunkOfnBytes)
(also, it was very late)
> Or if there is no other data in the UDP datagram you could just use the
> datagram length directly (i.e. get rid of the trailing garbage - why are
> you padding the datagram in the first place?)
>
>
We are not padding it on purpose and I'd love to know how or why that
garbage data got in there. :(
Cheers,
Lotte
> Oliver
>
>
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.