[protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-28 Thread Giancarlo Frison
Perfect, it works!

Thank you Robert, Pherl and everyone for the help.

On Jul 28, 4:16 pm, Robert  wrote:
> Hi,
>
> I do only create one FileDescriptor instance that contains all message
> definitions, because they are all constructed dynamically.
> For creating the FileDescriptorProtoBuilder I call:
>                 FileDescriptorProto.Builder fileDescriptorProtoBuilder =
> FileDescriptorProto.newBuilder();
> Then I create all the message protos by calling (here A and B):
>                 DescriptorProto.Builder messageProtoBuilderA =
> DescriptorProto.newBuilder();
>                 messageProtoBuilderA.setName( "A" );
>                 DescriptorProto.Builder messageProtoBuilderB =
> DescriptorProto.newBuilder();
>                 messageProtoBuilderB.setName( "B" );
>
> If message A references message B using field f I call:
>                 messageProtoBuilderA.addFieldBuilder()
>                         .setName("f")
>                         .setNumber(2)
>                         .setTypeName("B");
>
> Then I add the message protos to the file descriptor:
>                 
> fileDescriptorProtoBuilder.addMessageType(messageProtoBuilderA);
>                 
> fileDescriptorProtoBuilder.addMessageType(messageProtoBuilderB);
>
> Finally I create the file descriptor using:
>                 FileDescriptorProto fileDescriptorProto =
> fileDescriptorProtoBuilder.build();
>                 FileDescriptor fileDescriptor =
> FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]);
>
> Now I can create concrete messages by calling:
>                 Builder messageA =
> DynamicMessage.newBuilder( fileDescriptor.findMessageTypeByName("A") );
>                 Builder messageB =
> DynamicMessage.newBuilder( fileDescriptor.findMessageTypeByName("B") );
>
>                 messageA.setField(
>                         
> fileDescriptor.findMessageTypeByName("A").findFieldByName("f"),
>                         messageB.build() );
>
> I hope I did not add any errors when abstracting the code and that I
> understood your problem correctly.
>
> Kind regards,
> Robert
>
> On 28 Jul., 14:35, Giancarlo Frison  wrote:
>
>
>
>
>
>
>
> > on the field type descriptor previously create i set name as:
> > b2.setName(typename)
>
> > in the container class (which has reference the b2 field) I setup the
> > field as:
> > fb = DescriptorProtos.FieldDescriptorProto.newBuilder()
> >                 .setName(fieldName).setNumber(i+
> > +).setLabel(label).setTypeName(typename);
> > b1.addField(fb.build());
>
> > For creating the b1 descriptor, first I generate the descriptor of b2
> > then:
> > d1 = b1.build();
> > fdp1 =
> > DescriptorProtos.FileDescriptorProto.newBuilder().addMessageType(d1).build( 
> > ­);
>
> > but I get an error because fdp1.getDependenciesCount()==0
> > (Descriptors.java:233) Dependencies passed to
> > FileDescriptor.buildFrom() don't match those listed in the
> > FileDescriptorProto.
>
> > thrown here:
> > dynamicDescriptor = Descriptors.FileDescriptor.buildFrom(fdp1, fds);
>
> > (fds is array of 1, the b2 descriptor)
>
> > Why the d1 builder doesn't have the dependency defined adding the
> > complex typed field?
>
> > Thanks!!
>
> > Ps.: Robert, it's very kind of you whether send me the related
> > snippet. Thank you
>
> > On Jul 27, 8:10 pm, Pherl Liu  wrote:
>
> > > Take a look at the buildFrom() method. You need to provide an array of
> > > FileDescriptor as dependencies. If one of your message field is a complex
> > > type, you should build that complex type first, and pass the built
> > > FileDescriptor object to the buildFrom() in the dependencies array.
>
> > > On Wed, Jul 27, 2011 at 7:36 AM, Giancarlo Frison 
> > > wrote:
>
> > > > if I call setTypeName(messageName), how protobuf match the name with
> > > > related Descriptor?
> > > > How can I map messageName and the descriptor of the type?
>
> > > > On Jul 27, 3:56 pm, Robert  wrote:
> > > > > Hi,
>
> > > > > you either call setType() for primitive types or setTypeName(String)
> > > > > for referenced messages.
> > > > > You pass in the name of the message.
>
> > > > > Kind regards,
> > > > > Robert
>
> > > > > On 27 Jul., 10:35, Giancarlo Frison  wrote:
>
> > > > > > Thank you very much Pherl!
>
> > > > > > An another question. What about not-primitive fields, or message
> > > > > > fields?
>
> > > > > > when I add fields I do:
>
> > > > > >     DescriptorProtos.DescriptorProto.Builder desBuilder
> > > > > >     
> > > > > >     DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
> > > > > > DescriptorProtos.FieldDescriptorProto.newBuilder()
> > > > > >         .setName(fieldName).setNumber(i+
> > > > > > +).setType(type).setLabel(label);
> > > > > >     desBuilder.addField(fd1Builder.build());
>
> > > > > > with message typed field I set type as
> > > > > > 'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
> > > > > > describe the field type?
> > > > > > I mean, I suppose to describe the field with 

[protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-28 Thread Robert
Hi,

I do only create one FileDescriptor instance that contains all message
definitions, because they are all constructed dynamically.
For creating the FileDescriptorProtoBuilder I call:
FileDescriptorProto.Builder fileDescriptorProtoBuilder =
FileDescriptorProto.newBuilder();
Then I create all the message protos by calling (here A and B):
DescriptorProto.Builder messageProtoBuilderA =
DescriptorProto.newBuilder();
messageProtoBuilderA.setName( "A" );
DescriptorProto.Builder messageProtoBuilderB =
DescriptorProto.newBuilder();
messageProtoBuilderB.setName( "B" );

If message A references message B using field f I call:
messageProtoBuilderA.addFieldBuilder()
.setName("f")
.setNumber(2)
.setTypeName("B");

Then I add the message protos to the file descriptor:
fileDescriptorProtoBuilder.addMessageType(messageProtoBuilderA);
fileDescriptorProtoBuilder.addMessageType(messageProtoBuilderB);

Finally I create the file descriptor using:
FileDescriptorProto fileDescriptorProto =
fileDescriptorProtoBuilder.build();
FileDescriptor fileDescriptor =
FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]);

Now I can create concrete messages by calling:
Builder messageA =
DynamicMessage.newBuilder( fileDescriptor.findMessageTypeByName("A") );
Builder messageB =
DynamicMessage.newBuilder( fileDescriptor.findMessageTypeByName("B") );

messageA.setField(

fileDescriptor.findMessageTypeByName("A").findFieldByName("f"),
messageB.build() );

I hope I did not add any errors when abstracting the code and that I
understood your problem correctly.

Kind regards,
Robert



On 28 Jul., 14:35, Giancarlo Frison  wrote:
> on the field type descriptor previously create i set name as:
> b2.setName(typename)
>
> in the container class (which has reference the b2 field) I setup the
> field as:
> fb = DescriptorProtos.FieldDescriptorProto.newBuilder()
>                 .setName(fieldName).setNumber(i+
> +).setLabel(label).setTypeName(typename);
> b1.addField(fb.build());
>
> For creating the b1 descriptor, first I generate the descriptor of b2
> then:
> d1 = b1.build();
> fdp1 =
> DescriptorProtos.FileDescriptorProto.newBuilder().addMessageType(d1).build(­);
>
> but I get an error because fdp1.getDependenciesCount()==0
> (Descriptors.java:233) Dependencies passed to
> FileDescriptor.buildFrom() don't match those listed in the
> FileDescriptorProto.
>
> thrown here:
> dynamicDescriptor = Descriptors.FileDescriptor.buildFrom(fdp1, fds);
>
> (fds is array of 1, the b2 descriptor)
>
> Why the d1 builder doesn't have the dependency defined adding the
> complex typed field?
>
> Thanks!!
>
> Ps.: Robert, it's very kind of you whether send me the related
> snippet. Thank you
>
> On Jul 27, 8:10 pm, Pherl Liu  wrote:
>
>
>
> > Take a look at the buildFrom() method. You need to provide an array of
> > FileDescriptor as dependencies. If one of your message field is a complex
> > type, you should build that complex type first, and pass the built
> > FileDescriptor object to the buildFrom() in the dependencies array.
>
> > On Wed, Jul 27, 2011 at 7:36 AM, Giancarlo Frison wrote:
>
> > > if I call setTypeName(messageName), how protobuf match the name with
> > > related Descriptor?
> > > How can I map messageName and the descriptor of the type?
>
> > > On Jul 27, 3:56 pm, Robert  wrote:
> > > > Hi,
>
> > > > you either call setType() for primitive types or setTypeName(String)
> > > > for referenced messages.
> > > > You pass in the name of the message.
>
> > > > Kind regards,
> > > > Robert
>
> > > > On 27 Jul., 10:35, Giancarlo Frison  wrote:
>
> > > > > Thank you very much Pherl!
>
> > > > > An another question. What about not-primitive fields, or message
> > > > > fields?
>
> > > > > when I add fields I do:
>
> > > > >     DescriptorProtos.DescriptorProto.Builder desBuilder
> > > > >     
> > > > >     DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
> > > > > DescriptorProtos.FieldDescriptorProto.newBuilder()
> > > > >         .setName(fieldName).setNumber(i+
> > > > > +).setType(type).setLabel(label);
> > > > >     desBuilder.addField(fd1Builder.build());
>
> > > > > with message typed field I set type as
> > > > > 'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
> > > > > describe the field type?
> > > > > I mean, I suppose to describe the field with a inner
> > > > > 'DescriptorProtos.DescriptorProto.Builder', is it correct? How I can
> > > > > do to describe a complex type field?
>
> > > > > Thanks!
>
> > > > > On Jul 26, 8:21 pm, Pherl Liu  wrote:
>
> > > > > > Not sure if I understand your question correctly. You can set the
> > > label in
> > > > > > FieldDescriptorProto:
>
> 

[protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-28 Thread Giancarlo Frison
on the field type descriptor previously create i set name as:
b2.setName(typename)

in the container class (which has reference the b2 field) I setup the
field as:
fb = DescriptorProtos.FieldDescriptorProto.newBuilder()
.setName(fieldName).setNumber(i+
+).setLabel(label).setTypeName(typename);
b1.addField(fb.build());

For creating the b1 descriptor, first I generate the descriptor of b2
then:
d1 = b1.build();
fdp1 =
DescriptorProtos.FileDescriptorProto.newBuilder().addMessageType(d1).build();

but I get an error because fdp1.getDependenciesCount()==0
(Descriptors.java:233) Dependencies passed to
FileDescriptor.buildFrom() don't match those listed in the
FileDescriptorProto.

thrown here:
dynamicDescriptor = Descriptors.FileDescriptor.buildFrom(fdp1, fds);

(fds is array of 1, the b2 descriptor)

Why the d1 builder doesn't have the dependency defined adding the
complex typed field?

Thanks!!

Ps.: Robert, it's very kind of you whether send me the related
snippet. Thank you


On Jul 27, 8:10 pm, Pherl Liu  wrote:
> Take a look at the buildFrom() method. You need to provide an array of
> FileDescriptor as dependencies. If one of your message field is a complex
> type, you should build that complex type first, and pass the built
> FileDescriptor object to the buildFrom() in the dependencies array.
>
> On Wed, Jul 27, 2011 at 7:36 AM, Giancarlo Frison wrote:
>
>
>
>
>
>
>
> > if I call setTypeName(messageName), how protobuf match the name with
> > related Descriptor?
> > How can I map messageName and the descriptor of the type?
>
> > On Jul 27, 3:56 pm, Robert  wrote:
> > > Hi,
>
> > > you either call setType() for primitive types or setTypeName(String)
> > > for referenced messages.
> > > You pass in the name of the message.
>
> > > Kind regards,
> > > Robert
>
> > > On 27 Jul., 10:35, Giancarlo Frison  wrote:
>
> > > > Thank you very much Pherl!
>
> > > > An another question. What about not-primitive fields, or message
> > > > fields?
>
> > > > when I add fields I do:
>
> > > >     DescriptorProtos.DescriptorProto.Builder desBuilder
> > > >     
> > > >     DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
> > > > DescriptorProtos.FieldDescriptorProto.newBuilder()
> > > >         .setName(fieldName).setNumber(i+
> > > > +).setType(type).setLabel(label);
> > > >     desBuilder.addField(fd1Builder.build());
>
> > > > with message typed field I set type as
> > > > 'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
> > > > describe the field type?
> > > > I mean, I suppose to describe the field with a inner
> > > > 'DescriptorProtos.DescriptorProto.Builder', is it correct? How I can
> > > > do to describe a complex type field?
>
> > > > Thanks!
>
> > > > On Jul 26, 8:21 pm, Pherl Liu  wrote:
>
> > > > > Not sure if I understand your question correctly. You can set the
> > label in
> > > > > FieldDescriptorProto:
>
> > > > > LABEL_OPTIONAL = 1;
>
> > > > > LABEL_REQUIRED      = 2;LABEL_REPEATED      = 3;
>
> > > > > On Tue, Jul 26, 2011 at 12:21 AM, Giancarlo Frison <
> > gfri...@chelab.com>wrote:
>
> > > > > > There is this example that I'm approaching to re-implement
>
> >http://flori.posterous.com/dynamically-creating-protocol-buffer-objects
>
> > > > > > a question:
>
> > > > > > How to handle repeated fields? How can you describe them in the
> > > > > > fieldDescriptor?
>
> > > > > > On Jul 18, 5:20 pm, yoave  wrote:
> > > > > > > Hi all,
>
> > > > > > > I've got 2 questions:
>
> > > > > > > 1. how do I generate a Descriptor from a FileDescriptorProto in
> > Java?
> > > > > > >    In cpp, I'm using DescriptorPool class's 'BuildFile()'
> > > > > > > functionality.
>
> > > > > > > 2. how do I generate a Dynamic Message from a Descriptor in Java?
> > > > > > >    In cpp, I'm using DynamicMessageFactory class's
> > 'GetPrototype()'
> > > > > > > functionality.
>
> > > > > > > thanks
>
> > > > > > --
> > > > > > 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 
ht

Re: [protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-27 Thread Pherl Liu
Take a look at the buildFrom() method. You need to provide an array of
FileDescriptor as dependencies. If one of your message field is a complex
type, you should build that complex type first, and pass the built
FileDescriptor object to the buildFrom() in the dependencies array.

On Wed, Jul 27, 2011 at 7:36 AM, Giancarlo Frison wrote:

> if I call setTypeName(messageName), how protobuf match the name with
> related Descriptor?
> How can I map messageName and the descriptor of the type?
>
> On Jul 27, 3:56 pm, Robert  wrote:
> > Hi,
> >
> > you either call setType() for primitive types or setTypeName(String)
> > for referenced messages.
> > You pass in the name of the message.
> >
> > Kind regards,
> > Robert
> >
> > On 27 Jul., 10:35, Giancarlo Frison  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Thank you very much Pherl!
> >
> > > An another question. What about not-primitive fields, or message
> > > fields?
> >
> > > when I add fields I do:
> >
> > > DescriptorProtos.DescriptorProto.Builder desBuilder
> > > 
> > > DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
> > > DescriptorProtos.FieldDescriptorProto.newBuilder()
> > > .setName(fieldName).setNumber(i+
> > > +).setType(type).setLabel(label);
> > > desBuilder.addField(fd1Builder.build());
> >
> > > with message typed field I set type as
> > > 'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
> > > describe the field type?
> > > I mean, I suppose to describe the field with a inner
> > > 'DescriptorProtos.DescriptorProto.Builder', is it correct? How I can
> > > do to describe a complex type field?
> >
> > > Thanks!
> >
> > > On Jul 26, 8:21 pm, Pherl Liu  wrote:
> >
> > > > Not sure if I understand your question correctly. You can set the
> label in
> > > > FieldDescriptorProto:
> >
> > > > LABEL_OPTIONAL = 1;
> >
> > > > LABEL_REQUIRED  = 2;LABEL_REPEATED  = 3;
> >
> > > > On Tue, Jul 26, 2011 at 12:21 AM, Giancarlo Frison <
> gfri...@chelab.com>wrote:
> >
> > > > > There is this example that I'm approaching to re-implement
> > > > >
> http://flori.posterous.com/dynamically-creating-protocol-buffer-objects
> >
> > > > > a question:
> >
> > > > > How to handle repeated fields? How can you describe them in the
> > > > > fieldDescriptor?
> >
> > > > > On Jul 18, 5:20 pm, yoave  wrote:
> > > > > > Hi all,
> >
> > > > > > I've got 2 questions:
> >
> > > > > > 1. how do I generate a Descriptor from a FileDescriptorProto in
> Java?
> > > > > >In cpp, I'm using DescriptorPool class's 'BuildFile()'
> > > > > > functionality.
> >
> > > > > > 2. how do I generate a Dynamic Message from a Descriptor in Java?
> > > > > >In cpp, I'm using DynamicMessageFactory class's
> 'GetPrototype()'
> > > > > > functionality.
> >
> > > > > > thanks
> >
> > > > > --
> > > > > 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.



[protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-27 Thread Robert
You have to define the name when constructing the DescriptorProto.
I have done this myself lately but unfortunately I am currently not in
the office.
But I can send you an example tomorrow of you like.

Kind regards
Robert

On 27 Jul., 16:36, Giancarlo Frison  wrote:
> if I call setTypeName(messageName), how protobuf match the name with
> related Descriptor?
> How can I map messageName and the descriptor of the type?
>
> On Jul 27, 3:56 pm, Robert  wrote:
>
>
>
> > Hi,
>
> > you either call setType() for primitive types or setTypeName(String)
> > for referenced messages.
> > You pass in the name of the message.
>
> > Kind regards,
> > Robert
>
> > On 27 Jul., 10:35, Giancarlo Frison  wrote:
>
> > > Thank you very much Pherl!
>
> > > An another question. What about not-primitive fields, or message
> > > fields?
>
> > > when I add fields I do:
>
> > >     DescriptorProtos.DescriptorProto.Builder desBuilder
> > >     
> > >     DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
> > > DescriptorProtos.FieldDescriptorProto.newBuilder()
> > >         .setName(fieldName).setNumber(i+
> > > +).setType(type).setLabel(label);
> > >     desBuilder.addField(fd1Builder.build());
>
> > > with message typed field I set type as
> > > 'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
> > > describe the field type?
> > > I mean, I suppose to describe the field with a inner
> > > 'DescriptorProtos.DescriptorProto.Builder', is it correct? How I can
> > > do to describe a complex type field?
>
> > > Thanks!
>
> > > On Jul 26, 8:21 pm, Pherl Liu  wrote:
>
> > > > Not sure if I understand your question correctly. You can set the label 
> > > > in
> > > > FieldDescriptorProto:
>
> > > > LABEL_OPTIONAL = 1;
>
> > > > LABEL_REQUIRED      = 2;LABEL_REPEATED      = 3;
>
> > > > On Tue, Jul 26, 2011 at 12:21 AM, Giancarlo Frison 
> > > > wrote:
>
> > > > > There is this example that I'm approaching to re-implement
> > > > >http://flori.posterous.com/dynamically-creating-protocol-buffer-objects
>
> > > > > a question:
>
> > > > > How to handle repeated fields? How can you describe them in the
> > > > > fieldDescriptor?
>
> > > > > On Jul 18, 5:20 pm, yoave  wrote:
> > > > > > Hi all,
>
> > > > > > I've got 2 questions:
>
> > > > > > 1. how do I generate a Descriptor from a FileDescriptorProto in 
> > > > > > Java?
> > > > > >    In cpp, I'm using DescriptorPool class's 'BuildFile()'
> > > > > > functionality.
>
> > > > > > 2. how do I generate a Dynamic Message from a Descriptor in Java?
> > > > > >    In cpp, I'm using DynamicMessageFactory class's 'GetPrototype()'
> > > > > > functionality.
>
> > > > > > thanks
>
> > > > > --
> > > > > 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.



Re: [protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-27 Thread Jason Hsueh
The descriptor building libraries handle cross linking. The message type
name must be defined in either the same file, or be available through one of
the file's imports.

On Wed, Jul 27, 2011 at 7:36 AM, Giancarlo Frison wrote:

> if I call setTypeName(messageName), how protobuf match the name with
> related Descriptor?
> How can I map messageName and the descriptor of the type?
>
> On Jul 27, 3:56 pm, Robert  wrote:
> > Hi,
> >
> > you either call setType() for primitive types or setTypeName(String)
> > for referenced messages.
> > You pass in the name of the message.
> >
> > Kind regards,
> > Robert
> >
> > On 27 Jul., 10:35, Giancarlo Frison  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Thank you very much Pherl!
> >
> > > An another question. What about not-primitive fields, or message
> > > fields?
> >
> > > when I add fields I do:
> >
> > > DescriptorProtos.DescriptorProto.Builder desBuilder
> > > 
> > > DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
> > > DescriptorProtos.FieldDescriptorProto.newBuilder()
> > > .setName(fieldName).setNumber(i+
> > > +).setType(type).setLabel(label);
> > > desBuilder.addField(fd1Builder.build());
> >
> > > with message typed field I set type as
> > > 'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
> > > describe the field type?
> > > I mean, I suppose to describe the field with a inner
> > > 'DescriptorProtos.DescriptorProto.Builder', is it correct? How I can
> > > do to describe a complex type field?
> >
> > > Thanks!
> >
> > > On Jul 26, 8:21 pm, Pherl Liu  wrote:
> >
> > > > Not sure if I understand your question correctly. You can set the
> label in
> > > > FieldDescriptorProto:
> >
> > > > LABEL_OPTIONAL = 1;
> >
> > > > LABEL_REQUIRED  = 2;LABEL_REPEATED  = 3;
> >
> > > > On Tue, Jul 26, 2011 at 12:21 AM, Giancarlo Frison <
> gfri...@chelab.com>wrote:
> >
> > > > > There is this example that I'm approaching to re-implement
> > > > >
> http://flori.posterous.com/dynamically-creating-protocol-buffer-objects
> >
> > > > > a question:
> >
> > > > > How to handle repeated fields? How can you describe them in the
> > > > > fieldDescriptor?
> >
> > > > > On Jul 18, 5:20 pm, yoave  wrote:
> > > > > > Hi all,
> >
> > > > > > I've got 2 questions:
> >
> > > > > > 1. how do I generate a Descriptor from a FileDescriptorProto in
> Java?
> > > > > >In cpp, I'm using DescriptorPool class's 'BuildFile()'
> > > > > > functionality.
> >
> > > > > > 2. how do I generate a Dynamic Message from a Descriptor in Java?
> > > > > >In cpp, I'm using DynamicMessageFactory class's
> 'GetPrototype()'
> > > > > > functionality.
> >
> > > > > > thanks
> >
> > > > > --
> > > > > 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.



[protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-27 Thread Giancarlo Frison
if I call setTypeName(messageName), how protobuf match the name with
related Descriptor?
How can I map messageName and the descriptor of the type?

On Jul 27, 3:56 pm, Robert  wrote:
> Hi,
>
> you either call setType() for primitive types or setTypeName(String)
> for referenced messages.
> You pass in the name of the message.
>
> Kind regards,
> Robert
>
> On 27 Jul., 10:35, Giancarlo Frison  wrote:
>
>
>
>
>
>
>
> > Thank you very much Pherl!
>
> > An another question. What about not-primitive fields, or message
> > fields?
>
> > when I add fields I do:
>
> >     DescriptorProtos.DescriptorProto.Builder desBuilder
> >     
> >     DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
> > DescriptorProtos.FieldDescriptorProto.newBuilder()
> >         .setName(fieldName).setNumber(i+
> > +).setType(type).setLabel(label);
> >     desBuilder.addField(fd1Builder.build());
>
> > with message typed field I set type as
> > 'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
> > describe the field type?
> > I mean, I suppose to describe the field with a inner
> > 'DescriptorProtos.DescriptorProto.Builder', is it correct? How I can
> > do to describe a complex type field?
>
> > Thanks!
>
> > On Jul 26, 8:21 pm, Pherl Liu  wrote:
>
> > > Not sure if I understand your question correctly. You can set the label in
> > > FieldDescriptorProto:
>
> > > LABEL_OPTIONAL = 1;
>
> > > LABEL_REQUIRED      = 2;LABEL_REPEATED      = 3;
>
> > > On Tue, Jul 26, 2011 at 12:21 AM, Giancarlo Frison 
> > > wrote:
>
> > > > There is this example that I'm approaching to re-implement
> > > >http://flori.posterous.com/dynamically-creating-protocol-buffer-objects
>
> > > > a question:
>
> > > > How to handle repeated fields? How can you describe them in the
> > > > fieldDescriptor?
>
> > > > On Jul 18, 5:20 pm, yoave  wrote:
> > > > > Hi all,
>
> > > > > I've got 2 questions:
>
> > > > > 1. how do I generate a Descriptor from a FileDescriptorProto in Java?
> > > > >    In cpp, I'm using DescriptorPool class's 'BuildFile()'
> > > > > functionality.
>
> > > > > 2. how do I generate a Dynamic Message from a Descriptor in Java?
> > > > >    In cpp, I'm using DynamicMessageFactory class's 'GetPrototype()'
> > > > > functionality.
>
> > > > > thanks
>
> > > > --
> > > > 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.



[protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-27 Thread Robert
Hi,

you either call setType() for primitive types or setTypeName(String)
for referenced messages.
You pass in the name of the message.

Kind regards,
Robert

On 27 Jul., 10:35, Giancarlo Frison  wrote:
> Thank you very much Pherl!
>
> An another question. What about not-primitive fields, or message
> fields?
>
> when I add fields I do:
>
>     DescriptorProtos.DescriptorProto.Builder desBuilder
>     
>     DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
> DescriptorProtos.FieldDescriptorProto.newBuilder()
>         .setName(fieldName).setNumber(i+
> +).setType(type).setLabel(label);
>     desBuilder.addField(fd1Builder.build());
>
> with message typed field I set type as
> 'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
> describe the field type?
> I mean, I suppose to describe the field with a inner
> 'DescriptorProtos.DescriptorProto.Builder', is it correct? How I can
> do to describe a complex type field?
>
> Thanks!
>
> On Jul 26, 8:21 pm, Pherl Liu  wrote:
>
>
>
> > Not sure if I understand your question correctly. You can set the label in
> > FieldDescriptorProto:
>
> > LABEL_OPTIONAL = 1;
>
> > LABEL_REQUIRED      = 2;LABEL_REPEATED      = 3;
>
> > On Tue, Jul 26, 2011 at 12:21 AM, Giancarlo Frison 
> > wrote:
>
> > > There is this example that I'm approaching to re-implement
> > >http://flori.posterous.com/dynamically-creating-protocol-buffer-objects
>
> > > a question:
>
> > > How to handle repeated fields? How can you describe them in the
> > > fieldDescriptor?
>
> > > On Jul 18, 5:20 pm, yoave  wrote:
> > > > Hi all,
>
> > > > I've got 2 questions:
>
> > > > 1. how do I generate a Descriptor from a FileDescriptorProto in Java?
> > > >    In cpp, I'm using DescriptorPool class's 'BuildFile()'
> > > > functionality.
>
> > > > 2. how do I generate a Dynamic Message from a Descriptor in Java?
> > > >    In cpp, I'm using DynamicMessageFactory class's 'GetPrototype()'
> > > > functionality.
>
> > > > thanks
>
> > > --
> > > 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.



[protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-27 Thread Giancarlo Frison
Thank you very much Pherl!

An another question. What about not-primitive fields, or message
fields?

when I add fields I do:

DescriptorProtos.DescriptorProto.Builder desBuilder

DescriptorProtos.FieldDescriptorProto.Builder fd1Builder =
DescriptorProtos.FieldDescriptorProto.newBuilder()
.setName(fieldName).setNumber(i+
+).setType(type).setLabel(label);
desBuilder.addField(fd1Builder.build());

with message typed field I set type as
'DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE'. How do I
describe the field type?
I mean, I suppose to describe the field with a inner
'DescriptorProtos.DescriptorProto.Builder', is it correct? How I can
do to describe a complex type field?

Thanks!

On Jul 26, 8:21 pm, Pherl Liu  wrote:
> Not sure if I understand your question correctly. You can set the label in
> FieldDescriptorProto:
>
> LABEL_OPTIONAL = 1;
>
> LABEL_REQUIRED      = 2;LABEL_REPEATED      = 3;
>
> On Tue, Jul 26, 2011 at 12:21 AM, Giancarlo Frison wrote:
>
>
>
>
>
>
>
> > There is this example that I'm approaching to re-implement
> >http://flori.posterous.com/dynamically-creating-protocol-buffer-objects
>
> > a question:
>
> > How to handle repeated fields? How can you describe them in the
> > fieldDescriptor?
>
> > On Jul 18, 5:20 pm, yoave  wrote:
> > > Hi all,
>
> > > I've got 2 questions:
>
> > > 1. how do I generate a Descriptor from a FileDescriptorProto in Java?
> > >    In cpp, I'm using DescriptorPool class's 'BuildFile()'
> > > functionality.
>
> > > 2. how do I generate a Dynamic Message from a Descriptor in Java?
> > >    In cpp, I'm using DynamicMessageFactory class's 'GetPrototype()'
> > > functionality.
>
> > > thanks
>
> > --
> > 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.



Re: [protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-26 Thread Pherl Liu
Not sure if I understand your question correctly. You can set the label in
FieldDescriptorProto:

LABEL_OPTIONAL = 1;

LABEL_REQUIRED  = 2;LABEL_REPEATED  = 3;


On Tue, Jul 26, 2011 at 12:21 AM, Giancarlo Frison wrote:

> There is this example that I'm approaching to re-implement
> http://flori.posterous.com/dynamically-creating-protocol-buffer-objects
>
> a question:
>
> How to handle repeated fields? How can you describe them in the
> fieldDescriptor?
>
>
>
> On Jul 18, 5:20 pm, yoave  wrote:
> > Hi all,
> >
> > I've got 2 questions:
> >
> > 1. how do I generate a Descriptor from a FileDescriptorProto in Java?
> >In cpp, I'm using DescriptorPool class's 'BuildFile()'
> > functionality.
> >
> > 2. how do I generate a Dynamic Message from a Descriptor in Java?
> >In cpp, I'm using DynamicMessageFactory class's 'GetPrototype()'
> > functionality.
> >
> > thanks
>
> --
> 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.



[protobuf] Re: Java - DynamicMessage and FileDescriptorProto

2011-07-26 Thread Giancarlo Frison
There is this example that I'm approaching to re-implement
http://flori.posterous.com/dynamically-creating-protocol-buffer-objects

a question:

How to handle repeated fields? How can you describe them in the
fieldDescriptor?



On Jul 18, 5:20 pm, yoave  wrote:
> Hi all,
>
> I've got 2 questions:
>
> 1. how do I generate a Descriptor from a FileDescriptorProto in Java?
>    In cpp, I'm using DescriptorPool class's 'BuildFile()'
> functionality.
>
> 2. how do I generate a Dynamic Message from a Descriptor in Java?
>    In cpp, I'm using DynamicMessageFactory class's 'GetPrototype()'
> functionality.
>
> thanks

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