javaprotocol-buffersprotocproto3

Dynamic parsing of .proto text file at runtime to generate descriptors


I am currently working on Google Protocol Buffers and need to generate dynamic messages. I already have my .proto files defined as shown below.

message TSInbound
{
  string id = 1;
  map<string,string> state = 2;
  map<string,string> reading =3;
}

AFAIK,I can use File Descriptor Set to create dynamic messsages. But, that would involve using the compiler to generate the desc files. I would like to generate Descriptor without compiling the .proto files. Is there a way for dynamic creation of message using custom defined .proto files and not using protoc ?


Solution

  • I think you are asking: "Is there a way to dynamically parse text .proto files at runtime to get descriptors."

    The .proto parser is written in C++. It is available as the library libprotoc.so. You could, in theory, write a JNI wrapper around this to do parsing at runtime. However, there is no (official) pure-Java parser for .proto files.