Distributing messages via extension

79 views
Skip to first unread message

Neil Gendzwill

unread,
Nov 15, 2011, 1:05:35 PM11/15/11
to prot...@googlegroups.com
New to protobuf but my google-fu is failing me here.  I would like to write a receiver that parses a base message, then distributes it to registered receivers who know how to parse the extensions. I don't want the receiver to know about the extensions, other than the range defined in the base .proto.  From reading the docs, you can define extensions to a message in separate .proto files.  But it seems like the receiver would need to know about all the extensions via an ExtensionRegistry.  This is to be used along with Netty - another user is dealing with a similar thing shown here

Is there a way around this?  A code example, ideally in Java?

Thanks,

Neil

Jason Hsueh

unread,
Nov 15, 2011, 2:45:44 PM11/15/11
to prot...@googlegroups.com
You only need to register the extensions that you want to use. Unknown extensions will get preserved as unknown fields (at least in the C++ and Java implementations; python does not support unknown fields), and when you reserialize the message those will be included. The registered receivers will need to have ExtensionRegistry's to parse the extensions they care about. Netty would need to provide a hook for them to provide the ExtensionRegistry.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/T1nsLkwJyIEJ.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.

Neil Gendzwill

unread,
Nov 15, 2011, 3:07:55 PM11/15/11
to prot...@googlegroups.com
Thanks for your prompt reply!

If I understand you correctly: I provide an ExtensionRegistry to Netty's decoder that has no entries, just to avoid the null exception.   I then reserialize the message and pass it to the appropriate handler, who decodes it using their own ExtensionRegistry that knows about any applicable extensions.  I presume that an extension can also have extensions?

Jason Hsueh

unread,
Nov 15, 2011, 4:55:42 PM11/15/11
to prot...@googlegroups.com
I don't know what Netty's API requirements are. In the google protobuf library, the ExtensionRegistry is optional; not providing one is the same as providing one with no extensions. But that should be about right; you only need to ensure that the handlers provide an ExtensionRegistry with what they want.

Only message types can be extended. If you are asking if a message type that's used as an extension can also have extensions, then yes, e.g.:

message Foo {
  extensions 1 to max;
}

message Bar {
  extensions 1 to max;
}
extend Foo {
  optional Bar bar = 1;
}

extend Bar {
  optional int32 int32_field = 1;
}

The ExtensionRegistry would need to contain the defintions for all extensions in the entire message structure that you want to use.

On Tue, Nov 15, 2011 at 12:07 PM, Neil Gendzwill <ngend...@yahoo.com> wrote:
Thanks for your prompt reply!

If I understand you correctly: I provide an ExtensionRegistry to Netty's decoder that has no entries, just to avoid the null exception.   I then reserialize the message and pass it to the appropriate handler, who decodes it using their own ExtensionRegistry that knows about any applicable extensions.  I presume that an extension can also have extensions?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/vIb_SDaycrwJ.
Reply all
Reply to author
Forward
0 new messages