Why can't you use the *.pb.h files? Note that you only have to include
the one that defines the extension. You can have all extensions
defined in plugin.proto and then only include options.pb.h. The only gotcha
is that you have to link plugin.pb.o with all the binaries that use
any message that has the extended options, even if those options are
only used for code generation.

On Wed, Nov 27, 2013 at 1:46 PM, Giuseppe Iellamo <pepp...@gmail.com> wrote:
> Hi all,
>
> I'm trying to develop a plugin in order to autogenerate code that is
> specific to my application.
> While a maybe simpler strategy is to make my code use the files generated by
> the c++ plugin I'm trying to write the plugin from scratch.
>
> So as explained in the documentation I've added to my package
>
> import "google/protobuf/descriptor.proto";
>
> extend google.protobuf.FieldOptions {
>     optional int32 testext = 50000;
> }
>
> ...
>
> message replyT {
>    enum ackT {
>       ok = 0;uninterpreted_option_size
>       failed = 1;
>    }
>
>    required ackT ack = 1 [ (testext) = 42 ];
> }
>
> now the question is how do I access to "readonly options" ?
>
> I've been able to dump 50000  42 using
>
> //***********************
> class TestGenerator: public CodeGenerator {
>
>     int i;
> public:
>     TestGenerator(const string& name) {};
>     virtual ~TestGenerator() {};
>     virtual bool Generate(const FileDescriptor* file,
>                           const string& parameter,
>                           GeneratorContext* context,
>                           string* error) const
>     {
>          ........................
>           std::cerr
> <<"\t\t"<<file->message_type(i)->field(j)->options().DebugString()<<std::endl;
>           .................
> //***********************
>
> assuming (i and j are correct)
>
> but apart of this I haven't been able after exploring the documentation how
> to test if a field has the extension testext enabled  (even by using 50000)
> and the value assigned.
>
> The Language guide suggests
> but the GetExtension method uses a type that is only generated insied the
> *.pb.h so I can't use it in may generator.
>
> string value = MyMessage::descriptor()->options().GetExtension(my_option);
>
>
>
>
>
>
> --
> 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 http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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 http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to