Hi All,

I have a simple .proto file

syntax = "proto3";

package helloworld.v1;

option java_package = "helloworld.v1";
option java_multiple_files = true;

import "google/api/annotations.proto";

service HelloWorldService {
    rpc sayHello (SayHelloRequest) returns (SayHelloResponse) {
option (google.api.http) = {
post: "/v1/example/echo"
body: "*"
};
}
}

message SayHelloRequest {
    string favourite_thing = 1;
}

message SayHelloResponse {
    string reply = 1;
}

I am generating a proto descriptor set from it using the proto compiler.

After that I am trying to read the proto descriptor programatically in the 
java code like this
FileDescriptorSet Hello = FileDescriptorSet.parseFrom(new 
FileInputStream(new File("D:\\temp\\descriptor\\Hello.pb")));
FileDescriptorSet Annotations = FileDescriptorSet.parseFrom(new 
FileInputStream(new File("D:\\temp\\descriptor\\annotations.pb")));
FileDescriptorSet Http = FileDescriptorSet.parseFrom(new 
FileInputStream(new File("D:\\temp\\descriptor\\http.pb")));
FileDescriptorSet Descriptor = FileDescriptorSet.parseFrom(new 
FileInputStream(new File("D:\\temp\\descriptor\\descriptor.pb")));

FileDescriptor httpD = FileDescriptor.buildFrom(Http.getFile(0), new 
FileDescriptor[] {}, true);
FileDescriptor descriptorD = 
FileDescriptor.buildFrom(Descriptor.getFile(0), new FileDescriptor[] {}, 
true);
FileDescriptor annotationsD = 
FileDescriptor.buildFrom(Annotations.getFile(0), new FileDescriptor[] 
{httpD, descriptorD});

ExtensionRegistry registry = ExtensionRegistry.newInstance();
FieldDescriptor httpFD = annotationsD.findExtensionByName("http");
Message httpRuleM = 
DynamicMessage.newBuilder(httpD.findMessageTypeByName("HttpRule")).build();
registry.add(httpFD, httpRuleM);

FileDescriptor helloD = FileDescriptor.buildFrom(Hello.getFile(0), new 
FileDescriptor[] {annotationsD});
FileDescriptor.internalUpdateFileDescriptor(helloD, registry);
helloD.findServiceByName("HelloWorldService").findMethodByName("sayHello").getOptions();

The api call in the last line puts the "http" in the unknown field, and the 
reason is because its a custom option and not registered. But as you can 
see I am doing that.

Can someone please guide me on what am I doing wrong?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to