Re: [protobuf] Creating ProtoBuf Messages without the generated proxy classes

2016-08-08 Thread Can Baran
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 <
> philipp.we...@gmail.com > 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 
>> )
>>  
>> 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 protobuf+u...@googlegroups.com .
>> To post to this group, send email to prot...@googlegroups.com 
>> .
>> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Creating ProtoBuf Messages without the generated proxy classes

2016-08-07 Thread Philipp Weissenbacher
Thanks for your repsonse Feng!

 We've ended up doing exactly that in Scala, actually.

Regards,
Philipp

Op vrijdag 5 augustus 2016 20:23:30 UTC+2 schreef Feng Xiao:
>
>
>
> On Thu, Aug 4, 2016 at 5:47 AM, Philipp Weissenbacher <
> philipp.we...@gmail.com > 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 
>> )
>>  
>> 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 protobuf+u...@googlegroups.com .
>> To post to this group, send email to prot...@googlegroups.com 
>> .
>> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Creating ProtoBuf Messages without the generated proxy classes

2016-08-05 Thread 'Feng Xiao' via Protocol Buffers
On Thu, Aug 4, 2016 at 5:47 AM, Philipp Weissenbacher <
philipp.weissenbac...@gmail.com> 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
> )
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.