tavenzhang / protoc-gen-as3

Automatically exported from code.google.com/p/protoc-gen-as3
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Greedy socket reads cause error when theres more than one payload on the socket #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Sender sends two payloads in quick succession
2. Receiver is unable to read entire payload off of socket before second 
payload hits.
3. Receiver begins reading the second payload as part of the first payload, 
adding payload 2's data to payload 1 and/or throwing an error when payload 2 
has a common field with payload 1 and it tries to assign payload 2's value to 
the already assigned field from payload 1

What is the expected output? What do you see instead?
The expected output would be the correct reception of two unique payloads.
Instead you see a single payload consisting of 2 payloads data or an error when 
reading the second payload.

What version of the product are you using? On what operating system?
3.0.8.9

Please provide any additional information below.

Original issue reported on code.google.com by jbdraw...@gmail.com on 2 Dec 2010 at 11:12

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
See 
http://code.google.com/intl/zh-CN/apis/protocolbuffers/docs/techniques.html#stre
aming

Streaming Multiple Messages
If you want to write multiple messages to a single file or stream, it is up to 
you to keep track of where one message ends and the next begins. The Protocol 
Buffer wire format is not self-delimiting, so protocol buffer parsers cannot 
determine where a message ends on their own. The easiest way to solve this 
problem is to write the size of each message before you write the message 
itself. When you read the messages back in, you read the size, then read the 
bytes into a separate buffer, then parse from that buffer. (If you want to 
avoid copying bytes to a separate buffer, check out the CodedInputStream class 
(in both C++ and Java) which can be told to limit reads to a certain number of 
bytes.)

Original comment by pop.atry@gmail.com on 3 Dec 2010 at 4:05