[protobuf] Re: Dynamically determine the type of a message

2010-02-11 Thread Alessandro Bellina
Every message has a descriptor object associated. Look in the c++ API
reference (http://code.google.com/apis/protocolbuffers/docs/reference/
cpp/index.html) for it. Once you get the descriptor, you can get a
string type by calling name().

On Feb 10, 5:02 pm, fokenrute fokenr...@gmail.com wrote:
 Hi, I'm developing a C++ application and I use Protocol Buffers for
 network communications.
 Somewhere in my app, I receive messages which can be of different
 types and I'm searching for a mean to dynamically determine the type
 of these messages (which are stored in a buffer). I read something
 about the reflexion interface, but I don't konw how to use it to do
 what i want.
 Thanks in advance for your replies.

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



[protobuf] how to get RepeatedField object

2010-02-11 Thread Romain Francois

Hello,

How can I get hold of a RepeatedField object to manage a repeated field 
in C++.


In RProtoBuf, we do a lot of :

for( int i=0; isize; i++){
INTEGER(res)[i] = (int) ref-GetRepeatedInt32( *message, fieldDesc, i ) ;
}

where essentially the INTEGER macro gives a pointer to the beginning of 
the int array we are filling.


I'd like to replace this using e.g std::copy

RepeatedField field ;
std::copy( field.begin(), field.end(), INTEGER(res) ) ;

but I can't find how to actually get hold of a RepeatedField object.

Is it possible ?

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/NrTG : Rcpp 0.7.5
|- http://tr.im/MPYc : RProtoBuf: protocol buffers for R
`- http://tr.im/KfKn : Rcpp 0.7.2

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



Re: [protobuf] how to get RepeatedField object

2010-02-11 Thread Jason Hsueh
No, there isn't a way to get the RepeatedField from the reflection
interface. You can only do so via the generated interface.

On Thu, Feb 11, 2010 at 5:57 AM, Romain Francois 
romain.francois.r.enthusi...@gmail.com wrote:

 Hello,

 How can I get hold of a RepeatedField object to manage a repeated field in
 C++.

 In RProtoBuf, we do a lot of :

 for( int i=0; isize; i++){
 INTEGER(res)[i] = (int) ref-GetRepeatedInt32( *message, fieldDesc, i ) ;
 }

 where essentially the INTEGER macro gives a pointer to the beginning of the
 int array we are filling.

 I'd like to replace this using e.g std::copy

 RepeatedField field ;
 std::copy( field.begin(), field.end(), INTEGER(res) ) ;

 but I can't find how to actually get hold of a RepeatedField object.

 Is it possible ?

 Romain

 --
 Romain Francois
 Professional R Enthusiast
 +33(0) 6 28 91 30 30
 http://romainfrancois.blog.free.fr
 |- http://tr.im/NrTG : Rcpp 0.7.5
 |- http://tr.im/MPYc : RProtoBuf: protocol buffers for R
 `- http://tr.im/KfKn : Rcpp 0.7.2

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



Re: Re: [protobuf] Re: Dynamically determine the type of a message

2010-02-11 Thread alexrichardson

...

I think union types are the best choice for a small number of possible  
messages. However, if you really need to support *any* type of message,  
you could consider adding a header message of a known type that  
includes the fully-qualified message name as returned by  
message-GetDescriptor()-full_name(), or some other unique message  
type indicator.



Good luck,



Evan
--



Evan Jones


Union types in combination with 'extensions' seems like the right solution  
for this problem in almost all cases, whether the number of message types  
is large or small.


Using a separate header message adds lots of complications as you then need  
to write additional code to instantiate the 'payload' message type etc... I  
was using a header message a while back, and migrated to union types with  
great success. Granted, I do still have a fairly small number of message  
types, but I am not aware of any issues which would arise from scaling to a  
very large set of messages. Are there known issues which arise from a union  
type with a large number of extensions?


Alex

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



Re: [protobuf] Re: Dynamically determine the type of a message

2010-02-11 Thread Evan Jones

On Feb 11, 2010, at 15:44 , alexrichard...@gmail.com wrote:
Are there known issues which arise from a union type with a large  
number of extensions?


The problem that concerns me is that I need to have unique extension  
ids. This seems difficult when using Protocol Buffers as an RPC  
system, unless I'm thinking about this in the wrong way? I haven't  
actually thought about this very hard.


Evan

--
Evan Jones
http://evanjones.ca/

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