[protobuf] Re: Dynamically determine the type of a message
What about something like this message UnknownMessage { enum MessageType { MESSAGE_TYPE_A = 1; MESSAGE_TYPE_B = 2; MESSAGE_TYPE_C = 3; } required MessageTypemsgType = 1; required bytesmsgPayload = 2; } On Wednesday, February 10, 2010 6:02:35 PM UTC-5, fokenrute 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 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 http://groups.google.com/group/protobuf?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[protobuf] Re: Dynamically determine the type of a message
On Feb 11, 5:44 pm, alexrichard...@gmail.com wrote: 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. I am trying to solve a similar problem. Can anybody point me to a small and (hopefully) working example of this technique (union types + extensions)? Thanks and best regards. -- 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] Re: Dynamically determine the type of a message
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.
Re: Re: [protobuf] Re: Dynamically determine the type of a message
... 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
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.
[protobuf] Re: Dynamically determine the type of a message
See the techniques section on Union Types: http://code.google.com/apis/protocolbuffers/docs/techniques.html#union I read the link you pointed to me, and it appears that Union Types are not generic enough to suit my needs. Self Describing Messages seems more like what I need, but they appears to be to heavy to use; I just need something that takes a buffer (char[] which contains bytes of the message) as an input and return the message type. Is there something similar or am I trying to use protoccol buffers the wrong way? -- 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] Re: Dynamically determine the type of a message
That's not possible. Serialized messages do not identify their own type. Ok, so, I will likely opt for Enum Types. Thanks for answering. -- 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.