View Source Protobuf.Extension (protobuf v0.12.0)
Extensions let you set extra fields for previously defined messages(even for messages in other packages) without changing the original message.
To load extensions you should call Protobuf.load_extensions/0
when your application starts:
def start(_type, _args) do
Protobuf.load_extensions()
Supervisor.start_link([], strategy: :one_for_one)
end
examples
Examples
# protoc should be used to generate the code instead of writing by hand.
defmodule Foo do
use Protobuf, syntax: :proto2
extensions([{100, 101}, {1000, 536_870_912}])
end
# This module is generated for all "extend" calls in one file.
# This module is needed in `*_extension` function because the field name is scoped
# in the proto file.
defmodule Ext.PbExtension do
use Protobuf, syntax: :proto2
extend Foo, :my_custom, 1047, optional: true, type: :string
end
foo = %Foo{}
Foo.put_extension(foo, Ext.PbExtension, :my_custom, "Custom field")
Foo.get_extension(foo, Ext.PbExtension, :my_custom)
Link to this section Summary
Functions
The actual function for get_extension
Returns the maximum extension number.
The actual function for put_extension
Link to this section Functions
The actual function for get_extension
@spec max() :: pos_integer()
Returns the maximum extension number.
examples
Examples
iex> Protobuf.Extension.max()
536870912
The actual function for put_extension