Write to a stream: message.writeTo(stream); Parse from a stream:
message = MyType.parseFrom(stream); If you need to read/write multiple messages on the same stream (or the stream does not end immediately after the first message), use writeDelimitedTo() and parseDelimitedFrom(). On Thu, Jul 2, 2009 at 10:56 AM, J.V. <jvsr...@gmail.com> wrote: > > Thanks, for some reason I'm' getting the same error. If you have an > example of encoding to a stream and then decoding, it would be greatly > appreciated. > I will get it fully working and update the tutorial or post it somewhere > if desired. > > thanks > > jrv > > Kenton Varda wrote: > > You have to flush the CodedOutputStream. > > > > You should just do this instead: > > > > byte[] data = person.build().toByteArray(); > > > > On Thu, Jul 2, 2009 at 12:44 AM, J.V. <jvsr...@gmail.com > > <mailto:jvsr...@gmail.com>> wrote: > > > > > > I'm trying to get the following to work but nothing is being > > written to > > the output stream. > > any ideas? > > > > private void testEncode() throws Exception { > > OutputStream out = new ByteArrayOutputStream(); > > CodedOutputStream cos = CodedOutputStream.newInstance(out); > > > > Person.person.Builder person = Person.person.newBuilder(); > > person.setFirstName("First"); > > person.setLastName("Last"); > > person.build().writeTo(cos); > > } > > > > When I try to decode cos it throws an exception > > Exception in thread "main" > > com.google.protobuf.InvalidProtocolBufferException: Protocol message > > contained an invalid tag (zero). > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. 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 -~----------~----~----~----~------~----~------~--~---