Hi,
I'm having trouble getting the following code to work. Using
protoc.exe, I generated a file with the descriptor data using the --
descriptor_set_out file. I've written some Java code to read the
file, and try to instantiate a default instance of one of the objects
in the descriptor, so that I write it out to an XML file using the
protobuf-format-java library.
Here's my code. The variable "descriptorData" contains the binary
content of the descriptor file, without any modifications:
DescriptorProtos.FileDescriptorSet fdSet =
FileDescriptorSet.newBuilder().mergeFrom(descriptorData).build();
FileDescriptorProto fdp = fdSet.getFile(0);
List<DescriptorProto> messageTypes = fdp.getMessageTypeList();
for(DescriptorProto type : messageTypes)
{
System.out.println("Type is: " + type.getName());
FileDescriptor fd =
type.getDescriptorForType().getFile();
DynamicMessage dm =
DynamicMessage.getDefaultInstance(type.getDescriptorForType());
System.out.println(XmlFormat.printToString(dm));
}
I've tried numerous combinations of the above code, but each time I
get the following output:
Type is: Type1
<DescriptorProto></DescriptorProto>
Type is: Type2
<DescriptorProto></DescriptorProto>
Type is: Type3
<DescriptorProto></DescriptorProto>
Type is: Type4
<DescriptorProto></DescriptorProto>
Type is: Type5
<DescriptorProto></DescriptorProto>
Type is: Type6
<DescriptorProto></DescriptorProto>
The proto file has Type1, Type2, Type3, etc, defined as messages. The
fact that type.getName() does return the type names from my proto
file, leads me to believe I'm heading in the right direction.
However, the DynamicMessage type that is created (and serialized to
XML) seems to indicate that I'm not passing the right descriptor
instance in to create the object.
Any thoughts?
Thanks,
Kevin
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.