Hi, I'm trying to extend the base method options to include http options like so:
// Copyright 2016 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. syntax = "proto2"; import "google/protobuf/descriptor.proto"; message Http { // A list of HTTP configuration rules that apply to individual API methods. // // **NOTE:** All service configuration rules follow "last one wins" order. repeated HttpRule rules = 1; } message HttpRule { // Selects methods to which this rule applies. // // Refer to [selector][google.api.DocumentationRule.selector] for syntax details. optional string selector = 1; // Determines the URL pattern is matched by this rules. This pattern can be // used with any of the {get|put|post|delete|patch} methods. A custom method // can be defined using the 'custom' field. oneof pattern { // Used for listing and getting information about resources. string get = 2; // Used for updating a resource. string put = 3; // Used for creating a resource. string post = 4; // Used for deleting a resource. string delete = 5; // Used for updating a resource. string patch = 6; // Custom pattern is used for defining custom verbs. CustomHttpPattern custom = 8; } // The name of the request field whose value is mapped to the HTTP body, or // `*` for mapping all fields not captured by the path pattern to the HTTP // body. NOTE: the referred field must not be a repeated field and must be // present at the top-level of response message type. optional string body = 7; // Additional HTTP bindings for the selector. Nested bindings must // not contain an `additional_bindings` field themselves (that is, // the nesting may only be one level deep). repeated HttpRule additional_bindings = 11; } // A custom pattern is used for defining custom HTTP verb. message CustomHttpPattern { // The name of this custom HTTP verb. optional string kind = 1; // The path matched by this custom verb. optional string path = 2; } extend google.protobuf.MethodOptions { // See `HttpRule`. optional HttpRule http = 72295728; } I then run protoc over http.proto and update src/Makefile.am libprotobuf_la_SOURCES to include http.pb.cc. I have another application that uses this extension to auto-generate new code like the following: #include <google/protobuf/descriptor.h> #include <google/protobuf/http.pb.h> void AtlCodeGenerator::GenerateHttpProxyArrayEntry(const HttpRule &http_rule , io::Printer* printer) { printer->Indent(); printer->Print("{\n"); printer->Indent(); printer->Print(vars_, ".service_descriptor = &$lcfullname$_descriptor,\n"); printer->Print(vars_, ".input_msg_descriptor = &$inputname$_descriptor,\n"); printer->Print(vars_, ".output_msg_descriptor = &$outputname$_descriptor,\n"); printer->Print(vars_, ".api_ptr = &$lcfullname$_api_$method$,\n"); vars_["body"] = http_rule.body(); if (http_rule.has_get()) { vars_["url"] = http_rule.get(); printer->Print(vars_, ".url_string = \"$url$\",\n"); printer->Print(".http_verb = CMSG_HTTP_GET,\n"); printer->Print(vars_, ".body_string = \"$body$\",\n"); } else if (http_rule.has_put()) { vars_["url"] = http_rule.put(); printer->Print(vars_, ".url_string = \"$url$\",\n"); printer->Print(".http_verb = CMSG_HTTP_PUT,\n"); printer->Print(vars_, ".body_string = \"$body$\",\n"); } else if (http_rule.has_post ()) { vars_["url"] = http_rule.post(); printer->Print(vars_, ".url_string = \"$url$\",\n"); printer->Print(".http_verb = CMSG_HTTP_POST,\n"); printer->Print(vars_, ".body_string = \"$body$\",\n"); } else if (http_rule.has_delete_()) { vars_["url"] = http_rule.delete_(); printer->Print(vars_, ".url_string = \"$url$\",\n"); printer->Print(".http_verb = CMSG_HTTP_DELETE,\n"); printer->Print(vars_, ".body_string = \"$body$\",\n"); } else if (http_rule.has_patch()) { vars_["url"] = http_rule.patch(); printer->Print(vars_, ".url_string = \"$url$\",\n"); printer->Print(".http_verb = CMSG_HTTP_PATCH,\n"); printer->Print(vars_, ".body_string = \"$body$\",\n"); } else { assert (false && "Error: a valid HTTP verb must be specified"); } printer->Outdent(); printer->Print("},\n"); printer->Outdent(); } void AtlCodeGenerator::GenerateHttpProxyArrayEntriesPerMethod(const MethodDescriptor &method, io::Printer* printer) { string lcname = CamelToLower(method.name()); vars_["method"] = lcname; vars_["inputname"] = FullNameToLower(method.input_type()->full_name()); vars_["outputname"] = FullNameToLower(method.output_type()->full_name ()); if (method.options().HasExtension(http)) { HttpRule http_rule = method.options().GetExtension(http); GenerateHttpProxyArrayEntry(http_rule, printer); // Generate an entry for each additional binding for (int i = 0; i < http_rule.additional_bindings_size(); i++) { GenerateHttpProxyArrayEntry(http_rule.additional_bindings(i), printer); } } } This code compiles fine, however when it comes to link the application I get the linker errors: host,cmsg: protoc_cmsg-c_atl_generator.o: In function `google::protobuf::compiler::c::AtlCodeGenerator::GenerateHttpProxyArrayEntriesPerMethod(google::protobuf::MethodDescriptor const&, google::protobuf::io::Printer*)': host,cmsg: c_atl_generator.cc:(.text+0x1385): undefined reference to `http' host,cmsg: c_atl_generator.cc:(.text+0x13a9): undefined reference to `http' host,cmsg: c_atl_generator.cc:(.text+0x13c6): undefined reference to `HttpRule::HttpRule(HttpRule const&)' host,cmsg: c_atl_generator.cc:(.text+0x144b): undefined reference to ` HttpRule::~HttpRule()' host,cmsg: c_atl_generator.cc:(.text+0x14ec): undefined reference to `HttpRule::~HttpRule()' host,cmsg: collect2: error: ld returned 1 exit status host,cmsg: Makefile:459: recipe for target 'protoc-cmsg' failed I can clearly see the following in http.pb.h so am unsure what my problem is: class HttpRule : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:HttpRule) */ { public: HttpRule(); virtual ~HttpRule(); HttpRule(const HttpRule& from); Any help would be greatly appreciated. -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
