Thanks! Any chance for a C++ code snippet? Even an un-tested one would get me going in the right direction.
On Tue, Dec 1, 2009 at 1:34 PM, Kenton Varda <ken...@google.com> wrote: > To parse protos at runtime you will either need to use C++, or you will > need to invoke protoc as a subprocess and have it output a FileDecsriptorSet > which you can use in Java or other languages. I'll assume C++. > > Be sure to get familiar with the API documentation here: > > http://code.google.com/apis/protocolbuffers/docs/reference/cpp/index.html#google.protobuf > > There are basically two steps here: > > (1) Parse the files to produce descriptors. Descriptors (a family of > classes defined in descriptor.h) are data structures representing parsed > .proto files. For this step, you want to use the Importer class found in > importer.h. Assuming your proto files are located on-disk, you'll want to > give it a DiskSourceTree -- but you can provide your own SourceTree > implementation if your files are located somewhere else. > > (2) Use descriptors to construct DynamicMessages. DynamicMessage is an > implementation of the Message interface which mimics a type given by a > descriptor. Actually, the DynamicMessage class itself is private -- the > class you will use is DynamicMessageFactory, defined in dynamic_message.h. > This is just a simple factory which takes a Descriptor and returns a > default instance of that class. You can then call New() on that default > instance to construct a mutable instance. The message can be modified via > the Reflection interface as defined in message.h. > > This may sound complicated but it actually comes down to only a few lines > of code. > > On Tue, Dec 1, 2009 at 10:27 AM, David McClurg <dave.mccl...@gmail.com>wrote: > >> I'm trying to rebuild a message editor for a game engine using >> protocol buffers. Currently we are using an XML template to describe >> the message type and XML to store the message. I like the protocol >> buffer language ( .proto files ) as well as the memory and performance >> advantages over XML. >> >> The tricky part is the message editor. The message editor tool needs >> to... >> 1) parse all .proto files for the game >> 2) present the user with a input form for a selected message type >> 3) build a protocol message >> 4) save the message to disk for the game to load. >> >> The property editor doesn't know about any message types at compile >> time. The game knows about all message types at compile time. For >> the message editor, message types need to be dynamically generated >> from .proto files. For the game, messages are read from disk and used >> to construct game objects and populate the world. >> >> From other discussions, I've read this is possible but not obvious >> with protocol buffers. >> >> Could you please explain in specific terms how to parse a bunch >> of .proto files from disk into message types at runtime? How do I >> parse .proto files on-the-fly? >> >> Thanks, >> David >> >> -- >> >> You received this message because you are subscribed to the Google Groups >> "Protocol Buffers" group. >> To post to this group, send email to proto...@googlegroups.com. >> To unsubscribe from this group, send email to >> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com> >> . >> 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 proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.