我正在使用protobuf,我正在从以下proto文件生成JAVA类 .

syntax = "proto3";
enum Greeting {
    NONE = 0;
    MR = 1;
    MRS = 2;
    MISS = 3;
}

message Hello {
    Greeting greeting = 1;
    string name = 2;
}

message Bye {
    string name = 1;
}

option java_multiple_files = true;

现在我需要为生成的文件添加一些代码,我发现可以使用自定义插件(https://developers.google.com/protocol-buffers/docs/reference/java-generated#plugins) . 我正在尝试用Java生成该插件,就像这样 .

public class Test {
   PluginProtos.CodeGeneratorResponse.getDefaultInstance();
   /* Code to get generated files from java_out and use the insertion points */
   codeGeneratorResponse.writeTo(System.out);
}

然后我跑了

protoc --java_out=./classes --plugin=protoc-gen-demo=my-plugin --demo_out=. example.proto

问题是,在我的 Test.java main方法上,我不知道如何访问由选项 --java_out 创建的文件,以便我可以使用它们的插入点 . 目前,默认实例的 CodeGeneratorResponse 为空(无文件) .

有谁知道如何从--java_out获取 CodeGeneratorResponse 以便我可以向生成的类添加更多代码?

提前致谢 .