Skip to content

Commit c12e546

Browse files
add extype field extension
1 parent c8e0a52 commit c12e546

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/brex_elixirpb.pb.ex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
defmodule Brex.Elixirpb.FieldOptions do
2+
@moduledoc false
3+
use Protobuf, syntax: :proto2
4+
5+
@type t :: %__MODULE__{
6+
extype: String.t()
7+
}
8+
defstruct [:extype]
9+
10+
field :extype, 1, optional: true, type: :string
11+
end
12+
13+
defmodule Brex.Elixirpb.PbExtension do
14+
@moduledoc false
15+
use Protobuf, syntax: :proto2
16+
17+
extend Google.Protobuf.FieldOptions, :field, 65007,
18+
optional: true,
19+
type: Brex.Elixirpb.FieldOptions
20+
end

src/brex_elixirpb.proto

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
syntax = "proto2";
2+
3+
package brex.elixirpb;
4+
import "google/protobuf/descriptor.proto";
5+
6+
// Defines an extension to specify the elixir type generated for the given field.
7+
8+
// For example,
9+
// google.protobuf.StringValue my_string = 1 [(brex.elixirpb.field).extype="String.t"];
10+
11+
// To compile
12+
//protoc --plugin=/Users/lizard/Projects/Work/git/brex/protobuf-elixir/protoc-gen-elixir --proto_path=lib --elixir_out=lib brex_elixirpb.proto
13+
14+
message FieldOptions {
15+
// Specify an elixir type to generate for this field. This will override usual type.
16+
optional string extype = 1;
17+
}
18+
19+
extend google.protobuf.FieldOptions {
20+
// Note: number to change
21+
optional FieldOptions field = 65007;
22+
}

0 commit comments

Comments
 (0)