Greetings Feng Is there a JAVA example for your answer and possible a usage case? Thanks Can
On Friday, August 5, 2016 at 11:23:30 AM UTC-7, Feng Xiao wrote: > > > > On Thu, Aug 4, 2016 at 5:47 AM, Philipp Weissenbacher < > [email protected] <javascript:>> wrote: > >> Hi all, >> >> We are currently implementing a testing library. One goal is to allow the >> client to test sending and receiving ProtoBuf messages. >> For this, we need a generic way to create them, without requiring the >> client to supply the generated proxy classes. >> This means MyType.getDefaultInstance() (as suggested here >> <https://groups.google.com/forum/#!searchin/protobuf/generic%7Csort:relevance/protobuf/w3enqjfLQ4k/fRtI_WjlwxcJ>) >> >> would not work. >> >> So, is there a generic way to create ProtoBuf messages (e.g. from .proto >> files) at runtime? >> > If you are using C++, you can use the Importer class: > > https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/importer.h#L148 > > to parse .proto files to FileDescriptor and then use DynamicMessage to > create message instances: > > https://github.com/google/protobuf/blob/master/src/google/protobuf/dynamic_message.h#L118 > > After that you can parse/serialize and manipulate the message instances > using the reflection API: > > https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message#Reflection > > > >> >> BTW, we're using Scala/Java and protobuf2. >> >> Sincerely, >> Philipp >> >> -- >> 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 [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/protobuf. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
