[protobuf] [Java][Python][TCP] Reading messages that where written with writeDelimited and viceversa

2012-03-26 Thread Galileo Sanchez
Hello! I've been searching in this group a little bit, and found this 
https://groups.google.com/forum/?fromgroups#!searchin/protobuf/python$20delimited/protobuf/_3gAmvU4_80/rEeMA3A9H1UJ

Now, I'm  very very very new to python, never heard of it kind of new, 
 so I got a little confused on how to apply that patch
should I directly patch my compiled request.proto ( that would be 
request_pb2.py), or should I apply it to some other file that is on the 
source
of the python implementation of the protocol buffer api.

If it is useful, basically what I'm trying to do is, run a TCP java server, 
and write clients in python, c++,and as I already have a good
proficiency in java, I wrote the server first, and I used 
parseDelimitedTo(), and writeDelimitedTo, because it will be reading 
multiple request from different
clients and that seemed the better way to go. Actually it launches a new 
thread per client, but anyway, a client could send multiple requests

Just in case that patch isn't intended to the purpose I want, I tried a 
different approach and tried to write the delimiter, 
str(request.ByteSize())+request.SerializeToString()

but now I see that I need to add the size in a raw bit format

So the questions are:

Is the patch for what i thought it was? 
then  to wich file should I apply it?

else 
if (Should I write the size as a raw bit string?)
thenHow do I do that?

else
How do I write the message in a format that my Java server can understand?

Basically I just don't want to change my server implementation.

Thanks very much people, in the mean time I will be looking for other 
solutions...

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/gJFaTjB_PLUJ.
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: [protobuf] [Java][Python][TCP] Reading messages that where written with writeDelimited and viceversa

2012-03-26 Thread Galileo Sanchez
Thanks man... It worked great! I guess I should read the documentation a 
little more xP.



On Monday, March 26, 2012 9:49:17 PM UTC-3, Evan Jones wrote:

 On Mar 25, 2012, at 18:09 , Galileo Sanchez wrote:
  else 
  if (Should I write the size as a raw bit string?)
  thenHow do I do that?


 You need to use something like the following. Not 100% sure it works but 
 it should be close? Hope this helps,

 Evan


 # Output a message to be read with Java's parseDelimitedFrom
 import google.protobuf.internal.encoder as encoder
 out = message.SerializeToString()
 out = encoder._VarintBytes(len(out)) + out


 # Read a message from Java's writeDelimitedTo:
 import google.protobuf.internal.decoder as decoder

 # Read length
 (size, position) = decoder._DecodeVarint(buffer, 0)
 # Read the message
 message_object.ParseFromString(buffer[position:position+size])


 --
 http://evanjones.ca/



-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/GDPoYpNMZl4J.
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.