[protobuf] Does proto3 allow recursion?

2016-03-21 Thread Zachary Deretsky
Is recursion handled, for example:

message Node {
string value = 1;
Node parent = 2;
message Child {
 string key = 1;
 Node child = 2;
}
repeated Child children = 3;
}


or

message Node {
string value = 1;
Node parent = 2;
map children = 3;
}




-- 
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] Dynamic/run-time decoding

2016-03-21 Thread Mike Trienis
Hi,

Do you know if it's possible do dynamic decoding at run-time using the 
Python API? 

   - https://developers.google.com/protocol-buffers/docs/reference/python/
   
Indeed there is a descriptor.FileDescriptor, however I'm not sure what the 
other classes correspond to?

Thanks, Mike. 

On Tuesday, August 12, 2014 at 10:36:13 AM UTC-7, Feng Xiao wrote:
>
> Protobuf supports creating message types dynamically at runtime and use 
> them for parsing/serialization/etc.
>
> First you need to build up a DescriptorPool 
> 
>  
> that contains all types that you may want to use. There are two approaches 
> to construct this pool. One is to call DescriptorPool::BuildFile() directly 
> with parsed proto files. For example:
>   // Convert .proto files into parsed FileDescriptorProto
>   bool ParseProtoFile(string filename, FileDescriptorProto* result) {
> FileInputStream stream(filename);
> google::protobuf::io::Tokenizer tokenizer(&stream);
> google::protobuf::compiler::Parser parser;
> return parser.Parse(&tokenizer, result);
>   }
>   // Build the descriptor pool
>   DescriptorPool pool;
>   for (string filename : proto_files) {
> FileDescriptorProto proto;
> ParseProtoFile(filename, &proto);
> pool.BuildFile(proto);
>   }
>
> After you have the pool, you can query for a type by its name. For 
> example, DescriptorPool::FindMessageTypeByName().
>
> Then to actually parse/serialize/use message types in the pool, you need 
> to construct message objects around them. DynamicMessage 
> 
>  
> is used for that:
>   // Suppose you want to parse a message type with a specific type name.
>   Descriptor* descriptor = 
> pool.FindMessageTypeByName(message_type_to_parse);
>   DynamicMessageFactory factory;
>   unique_ptr message = factory.GetPrototype(descriptor)->New();
>   // Use the message object for parsing/etc.
>   message->ParseFromString(input_data);
>   // Access a specific field in the message
>   FieldDescriptor* field = descriptor->FindFieldByName(field_to_read);
>   switch (field->type()) {
> case TYPE_INT32: message->GetReflection()->GetInt32(*message, field); 
> break;
> ...
>   }
>
> On Mon, Aug 11, 2014 at 9:31 PM, Jan Kyjovský  > wrote:
>
>> Hi,
>>
>> I have very specific problem. I have data and proto file available and my 
>> application should take both and based on external configuration determine 
>> how to interpret data (many different types/messages in proto). Yet that 
>> can be determine only during run. My question is if there is any support 
>> for that, I mean that I will be able to parse proto and decode data based 
>> on content of interpret intermediate structures.
>>
>> I have been trying to analyze this possibility directly from codes but 
>> not with much success. I would be glad for any guidance.
>>
>> -- 
>> 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 http://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.


[protobuf] Re: Dynamic/run-time decoding

2016-03-21 Thread Mike Trienis
Hello,

I would very much like to know if this is possible with the Python API?

   - https://developers.google.com/protocol-buffers/docs/reference/python/ 
   
In other words, if I have a .proto schema file, do I have to use *protoc* 
to compile a python module in order to decode the protobuf message?

Any help would be appreciated, Mike. 


On Monday, August 11, 2014 at 9:31:23 PM UTC-7, Jan Kyjovský wrote:
>
> Hi,
>
> I have very specific problem. I have data and proto file available and my 
> application should take both and based on external configuration determine 
> how to interpret data (many different types/messages in proto). Yet that 
> can be determine only during run. My question is if there is any support 
> for that, I mean that I will be able to parse proto and decode data based 
> on content of interpret intermediate structures.
>
> I have been trying to analyze this possibility directly from codes but not 
> with much success. I would be glad for any guidance.
>

-- 
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.