Re: [protobuf] [De]serialization of messages to java strings

2009-11-24 Thread Adam Vartanian
> What am I doing wrong?  What's the best way to do java string > serialization of protobuf messages? The native wire format of protocol buffers is just a sequence of bytes, so it can contain values that are invalid UTF-8 (or any encoding that has invalid byte sequences). Trying to pack that into

Re: [protobuf] Java -using GPB -which type of stream should I be using over sockets?

2009-12-02 Thread Adam Vartanian
> I have created a test Java application that uses ObjectInputStream and > ObjectOutputStream over sockets.  No problems, it works! I use my GPB > class writeTo and parseFrom to send and reconstitute my GPB class > using the ObjectInput and Output Streams > > But: isn't GPB allowing for seriali

Re: [protobuf] Re: Java -using GPB -which type of stream should I be using over sockets?

2009-12-02 Thread Adam Vartanian
> If protocol buffers doesn't use object I/O streams, which streams does > it use?  The argument in Java simply asks for an OutputStream > argument, and of course that could mean File, ByteArray, Object, Data, > etc I mean that it only depends on the methods in OutputStream. You can provide a

Re: [protobuf] Receiving/Parsing Messages

2009-12-03 Thread Adam Vartanian
> I just started looking into protobuf for a project of mine. > From the Java Api page I could not really find how to parse a > generated (compiled .proto is present) but "unknown" message. > > So for example: I have messages types MessageA and MessageB. The > client component receives some bytes r

Re: [protobuf] Re: Receiving/Parsing Messages

2009-12-03 Thread Adam Vartanian
> Another option is to send some kind of identifier preceding the > message (just like the total size of the message), right? Yep. In fact, the wrapper message is effectively a protobuf-native version of that, using the tag number as the type identifier. - Adam -- You received this message bec

Re: [protobuf] Re: Java -using GPB -which type of stream should I be using over sockets?

2009-12-07 Thread Adam Vartanian
> Anyway, for anyone else wanting to use ByteArrayStream in Java for > writing a Google , here is some code I've used: > > ServerSocket serverSocket = new ServerSocket(2004, 10); > Socket socket = serverSocket.accept(); > OutputStream outputStream = socket.getOutputStream(); > outputStream.flush();

Re: [protobuf] Re: Receiving/Parsing Messages

2009-12-07 Thread Adam Vartanian
>> Adam, Could you please show simple example how to use tag number for >> dispatch purpose. > > I believe he was referring to this sort of thing: > > http://code.google.com/apis/protocolbuffers/docs/techniques.html#union Yes, exactly. In code, if you're using the enum-based technique: switch (m

Re: [protobuf] Message References

2009-12-08 Thread Adam Vartanian
> A standard protocol buffer message type ptr_B from which a "flat" Java > class will be generated does not seem adequat to to so. > Instead some new abstract Class "RefMessage" with a > method " getReferencedObject()" would be the solution. ptr_X > messages simply had to be transformed to Java cla

Re: [protobuf] Externally compiled protobuf messages

2009-12-11 Thread Adam Vartanian
> An example: > Foo.jar contains the compiled Java code for the following protobuf: > option java_package = "com.foo"; > message FooMsg { >   optional int32 a = 1; >   optional int32 b = 2; >   ... > } > > In my code, I want to do this: > option java_package = "com.bar"; > message BarMsg { >   opti

Re: [protobuf] Builders containing builders

2009-12-16 Thread Adam Vartanian
> I wish I could pass a builder object to a method and have the method > modify either a value of the builder or a value of a sub-message in > the builder! > > I came across this thread, which described exactly the problem I have. > The Car/Engine example in the thread is perfectly illustrative of

Re: [protobuf] how to define a one-way rpc message?

2010-02-03 Thread Adam Vartanian
> the only workaround that i can think of would be creating a "Void" > message that is declared as the answer and the rpc implementation to > then "ignore" those. > > like this: > > message Void > { > } > > service myService > { > rpc OneWayWithoutResponse(FirmwareEvent) returns (Void); > } > > is

Re: [protobuf] How to prevent different protocol buffers from being parseFrom(byte[])

2010-02-18 Thread Adam Vartanian
> I am confused on how to detect this scenario, and ultimately prevent > such things occurring. You can't, at least in the simple way. Protocol buffers on the wire have no type information associated with them, and they're explicitly designed so that they can accept fields they don't expect to be

Re: [protobuf] serializing the message using the compiled file.

2010-04-12 Thread Adam Vartanian
> I want to serialize the message (id, title and teh text). > Can someone please help me out with this. You can call yourmessage.toByteArray() (or toByteString()) to get it as an object, or yourmessage.writeTo(OutputStream) to send it to an OutputStream. - Adam -- You received this message beca

Re: [protobuf] serialization size from 2.0.x to 2.3.x, also message design best practices

2010-04-27 Thread Adam Vartanian
> In the case of repeated strings etc (excluding the "enum" case), I've been > toying whether something is possible by associating certain objects / values > with unique identifiers on the wire. Potentially this would also allow > "graph" (rather than "tree") serialization. > This is obviously well

Re: [protobuf] Re: Self describing messages

2010-07-26 Thread Adam Vartanian
> I don't want to send the whole enchilada on the wire - just the > descriptor for the message being sent. > > As I showed above, I know how to get the descriptor on the wire, but > the other side (getting the descriptor off the wire and parsing the > message using it) is unclear to me. You'll nee

Re: [protobuf] can i use protocol buffer to encrypt and send a file

2010-10-14 Thread Adam Vartanian
>   I have a file which i need to encrypt and send so can i use > protocol buffer for this buffer? please do reply me. Protocol buffers don't provide any built-in encryption or anything like that, no, all they provide is a serialization format. You could use protocol buffers to send a file you en

Re: [protobuf] Parse PB bytes into a generic message

2010-10-27 Thread Adam Vartanian
> I need a generic parser in java, which can de-serialize PB bytes > buffer into a Message or GeneratedMessage. But, GeneratedMessage > provides no such method to merge an arbitary PB bytes and provide an > instance  of itself. >From just a message's bytes you can't turn it into a Message. The se

Re: [protobuf] Re: Parse PB bytes into a generic message

2010-10-27 Thread Adam Vartanian
> Since the client and server are remote, i am not sure how i can send > Descriptor along with message? All the different kinds of descriptors have associated protocol messages available through their toProto() methods, so you can serialize them, send them over the wire, and deserialize them on th

Re: [protobuf] uint32 vs int32: who is the most efficient? (Java)

2011-05-05 Thread Adam Vartanian
> Then my question is this: why to use int32 type even though uint32 > uses less bytes covering the same range? The main reason would be if you ever plan on reading the message from non-Java code. What you've stated is only true in Java because it has no unsigned integral types, so protobufs have

Re: [protobuf] Dynamic protocol buffer generation in Java

2011-08-24 Thread Adam Vartanian
> I'd like to use dynamically generate/use protocol buffer objects in a > running Java application.  This would be running in a production > environment (jre, not jdk) where protoc is not available. > > Has anyone written a utility in Java to parse a protocol buffer > definition and dynamically bui