Oh, I missed that you were reading the FileDescriptorSet from a separate
file, not the same stream. This isn't exactly "self describing" since when
you transmit the message you assume the recipient knows what type the
message is, and has access to the FileDescriptorSet. See
http://code.google.com/apis/protocolbuffers/docs/techniques.html#self-description

On Thu, Jun 23, 2011 at 12:31 AM, slookin <sloo...@gmail.com> wrote:

> Thanks Jason,
>  It is all my code (link to real java class -
> http://test.look-in.net/pf/pf.zip.
>  Could you give me links with examples or explain why i should
> "serializes the FileDescriptorSet"?
>
> On Jun 22, 8:35 pm, Jason Hsueh <jas...@google.com> wrote:
> > On Wed, Jun 22, 2011 at 3:30 AM, slookin <sloo...@gmail.com> wrote:
> > > I trying to develop "flexible" server for reciving message, i'm not
> > > able to create java classes for each message type, but I can upload
> > > proto descripter on server. Of course client (sender) will use
> > > generated java classes for prepare messages:
> >
> > > My code (sender):
> > > Person.Builder person = Person.newBuilder();
> > > person.setId(Integer.valueOf(42));
> > > person.setEmail("test_em...@gmail.com");
> > > person.setName("Viktor Villari");
> > > Person p=person.build();
> > > FileOutputStream fstream = new FileOutputStream ("message.pf");
> > > CodedOutputStream outSream = CodedOutputStream.newInstance(fstream);
> > > p.writeTo(outSream);
> > > outSream.flush();
> > > System.out.println("sent");
> >
> > > Reciver (address.descriptor.proto - grenerated via descriptor.proto):
> > >        FileInputStream input = new FileInputStream
> > > ("address.descriptor.proto");
> > >                DescriptorProtos.FileDescriptorSet
> > > fdsProto=DescriptorProtos.FileDescriptorSet.parseFrom(input);
> > >                input = new FileInputStream ("message.pf");
> > >            //
> > > System.out.println(fds.getFile(0).getMessageType(0).getName());
> > >                System.out.println("File name =
> > > "+fdsProto.getFile(0).getName());
> > >                // System.out.println("Message type =
> > > "+fdsProto.getFile(0).getMessageType(0).getName());
> > >                // System.out.println("Field info =
> > > "+fdsProto.getFile(0).getMessageType(0).getField(0).getName()+"
> > > "+fdsProto.getFile(0).getMessageType(0).getField(0).getType());
> > >                FileDescriptor
> > > fileDescr=FileDescriptor.buildFrom(fdsProto.getFile(0), new
> > > FileDescriptor[0]);
> > >                System.out.println("Message type =
> > > "+fileDescr.getMessageTypes().get(0).getName());
> > >                System.out.println("Field info =
> > > "+fileDescr.getMessageTypes().get(0).getFields().get(0).getName()+"
> > > type=
> > > "+fileDescr.getMessageTypes().get(0).getFields().get(0).getType());
> > >                DynamicMessage
> > > dm=DynamicMessage.parseFrom(fdsProto.getDescriptor(),
> > > input);
> >
> > On this line, you are passing the descriptor for the FileDescriptorSet.
> You
> > should be using fileDescr to get at the Person message type. (Note that
> your
> > description scheme does not indicate what message type is actually used.
> But
> > I also don't see the code snippet that serializes the FileDescriptorSet,
> or
> > for that matter delimit between the FileDescriptorSet and the serialized
> > Person data, so maybe you are doing something elsewhere)
> >
> >
> >
> >
> >
> >
> >
> > >                System.out.println("DynamicMessage to string
> > > \n"+dm.toString());
> > >                //---- problem line
> > >                System.out.println("Person.name  = "+
> > > dm.getField(fileDescr.getMessageTypes().get(0).getFields().get(0)));
> > >                //----
> >
> > > Output:
> > > File name = addressbook.proto
> > > Message type = Person
> > > Field info = name type= STRING
> > > DynamicMessage to string
> > > 2: "Viktor Villari"
> > > 3: 42
> > > 4: "test_em...@gmail.com"
> >
> > > Exception in thread "main" java.lang.IllegalArgumentException:
> > > FieldDescriptor does not match message type.
> > >        at
> >
> > >
> com.google.protobuf.DynamicMessage.verifyContainingType(DynamicMessage.java:
> > > 242)
> > >        at
> com.google.protobuf.DynamicMessage.getField(DynamicMessage.java:
> > > 160)
> > >        at net.lookin.protobuf.Test.main(Test.java:64)
> >
> > > Why I recive exception?
> > > How I can access to specific field value in DynamicMessage?
> >
> > > --
> > > 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.
>
> --
> 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.
>
>

-- 
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.

Reply via email to