Can't help you with the parsing, but as far as building the object dynamically given a set of fields and their types -- I recently wrote a converter for taking Thrift objects and turning them into dynamic protocol buffer messages. If you can parse a .proto file at runtime to determine what fields need to be created in what order, you should be able to do something very similar (even somewhat simpler as you won't have to fight Thrift's API).
The various builders involved get a bit tricky. See if the code's helpful: https://github.com/kevinweil/elephant-bird/blob/master/src/java/com/twitter/elephantbird/util/ThriftToDynamicProto.java It currently only works with flat messages, but it'd be pretty straightforward to add support for nesting I think. D On Thu, Aug 25, 2011 at 11:42 AM, Benjamin Wright <[email protected]>wrote: > Unfortunately there is no java equivalent to protoc - it's a long standing > feature request. I can't blame them though - it's a lot more work to keep > two compilers in sync with each other. For now the best you can do is: > > 1) pre-compile the FileDescriptorSet representation of a proto file and use > those to initialize > 2) invoke protoc at run time from java (not as hard as it sounds)... > > here's some snippets glued together... protoc, gen_src, and protoFile are > all File objects. And notably, you can install proco in the PATH, you can > provide the path to it to the app, or you can even bundle it inside a jar. > > final String command = protoc.getPath() + " -o" + > gen_src.getName() > + " " + protoFile.getName(); > > final Process process; > try { > process = Runtime.getRuntime().exec(command, null, > workingDir); > } catch (IOException e) { > } > > int result; > try { > result = process.waitFor(); > } catch (InterruptedException e) { > continue; > } > if (result == 0) { > // Success! > > final FileInputStream input = new FileInputStream(gen_src); > fds = FileDescriptorSet.parseFrom(input); > input.close(); > > > > } > > > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/protobuf/-/piKV9a9TVPMJ. > > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
