added CHANGELOG.md
 
@@ -0,0 +1,169 @@
1
+ # Changelog
2
+
3
+ ## v0.13.0
4
+
5
+ ### Enhancements
6
+
7
+ * Do not allow encoding structs as a different struct
8
+ * Support OTP 27
9
+
10
+ ### Bug fixes
11
+
12
+ * Add optional keys to `Protobuf.decode/2` typespecs
13
+ * Include `elixirpb` files in Hex package
14
+ * Fix JSON encoding of proto3 optional non-nil defaults
15
+
16
+ ## v0.12.0
17
+
18
+ ### Enhancements
19
+
20
+ * Add `include_docs=true` protoc option to skip generating files with
21
+ `@moduledoc false`.
22
+ * Add support for the `google.protobuf.Any` type.
23
+ * Raise `Protobuf.EncodeError` instead of `Protobuf.TypeEncodeError` on
24
+ encode errors.
25
+ * Improve raised error for bad wire types.
26
+ * Raise when encoding/decoding invalid UTF-8 strings.
27
+
28
+ ### Bug fixes
29
+
30
+ * Fix typespecs for proto3 optional fields.
31
+ * Fix generated code for map fields outside of packages.
32
+ * Fix JSON encoding map validation.
33
+ * Remove `Protobuf.Wire.Varint` from public API.
34
+ * Fix conflicting PbExtension modules.
35
+ * Raise when trying to JSON encode `google.protobuf.Value`
36
+ values `NaN` or `Infinity`.
37
+ * Support `.` in FieldMask when decoding JSON.
38
+
39
+ ### Deprecations
40
+
41
+ * Deprecate the `new(!)/0,1` callbacks, create structs with `%Foo{}`
42
+ or `struct(!)/1,2` instead.
43
+
44
+ ## v0.11.0
45
+
46
+ ### Enhancements
47
+
48
+ * Improve formatting in generated code.
49
+ * Fix JSON encoding of field masks.
50
+ * Fix return value of `Protobuf.JSON.RFC3339.encode/2`.
51
+ * Improve error message when encoding oneoff.
52
+ * Add support for proto3 optional field.
53
+
54
+ ### Bug fixes
55
+
56
+ * Fix encoding root structs with transform module.
57
+ * Fix a bug with negative durations in JSON.
58
+ * Fix enum default value for structs where module is not available.
59
+ * Support transform module in JSON encoder.
60
+
61
+ ## v0.10.0
62
+
63
+ ### Enhancements
64
+
65
+ * Add `Protobuf.get_unknown_varints/1`, returns fields that could not be
66
+ decoded.
67
+ * Support JSON mapping for proto2 schemas.
68
+ * No longer warn when decoding unknown enum values.
69
+ * Validate options in `Protobuf.JSON.encode/2`.
70
+ * Raise `Protobuf.DecodeError` instead of `CaseClauseError` when trying to
71
+ decode an unknown wire type.
72
+ * Raise `Protobuf.DecodeError` instead of `MatchError` when trying to
73
+ decode invalid delimeted types.
74
+ * Include protoc-gen-elixir plugin version in generated files.
75
+
76
+ ### Bug fixes
77
+
78
+ * Encode fields in the order they are defined in the schema.
79
+ * Encode the value of oneof fields even when it's the default value.
80
+ * Camelization fixes in generated code using the `module_prefix` and
81
+ `package_prefix` options.
82
+ * Add `nil` to oneof typespec union.
83
+ * Skip calling `Type.new/1` for structs with transform modules.
84
+
85
+ ### Deprecations
86
+
87
+ * Warn if `@type t` is defined inside a module that calls `use Protobuf`. To
88
+ fix this warning the files can be regenerated with the latest version of
89
+ protobuf.
90
+
91
+ ### Breaking changes
92
+
93
+ * Raise an error if only `@type t` or `defstruct` is defined inside a module
94
+ that calls `use Protobuf`.
95
+
96
+ ## v0.9.0
97
+
98
+ ### Enhancements
99
+
100
+ Most of the enhancements in this release concern JSON support.
101
+
102
+ * JSON support for Google types. The library now supports JSON mapping of
103
+ `Google.Protobuf.*` types such as timestamps, durations, type wrappers, and
104
+ so on. In order to use this correctly, you need to manually generate the
105
+ Protobuf Elixir files from the `.proto` files provided by Google since they
106
+ are not shipped with this library.
107
+ * Accept integer numbers for float fields when decoding JSON.
108
+ * Add `Protobuf.encode_to_iodata/1`.
109
+ * Add the `one_file_per_module` CLI option when using the `protoc-gen-elixir`
110
+ plugin.
111
+ * Use type-aware defaults in struct definitions for Protobuf messages. This
112
+ means that now doing `%MyMessage{}` should be equivalent to
113
+ `MyMessage.new()`.
114
+ * Don't generate the `transformer_module/0` callback in generated Protobuf
115
+ modules if the `transformer_module` CLI option is not used.
116
+
117
+ ### Bug fixes
118
+
119
+ * Fix enum aliasing in JSON mapping.
120
+ * Fix encoding of default values when using transformer modules.
121
+ * Raise a `Protobuf.DecodeError` when decoding if fields with number `0` are
122
+ encountered.
123
+ * Fix bugs when decoding big varints, integers, and so on (by casting).
124
+ * Cast enum integers to int32 when they overflow when decoding.
125
+ * Skip encoding for fields if they match their user-defined default in proto2.
126
+ * Fix decoding and encoding of packed repeated fields.
127
+ * Don't pack fields that use the `[packed = false]` option explicitly in
128
+ proto3.
129
+
130
+ ## v0.8.0
131
+
132
+ ### Enhancements
133
+
134
+ * [JSON](https://developers.google.com/protocol-buffers/docs/proto3#json)
135
+ encoding and decoding support.
136
+ * [Extensions](https://developers.google.com/protocol-buffers/docs/proto#extensions)
137
+ support.
138
+ * [Enum alias](https://developers.google.com/protocol-buffers/docs/proto3#enum)
139
+ (`allow_alias`) support.
140
+ * Faster and more memory-efficient encoding and decoding algorithms.
141
+ * More accurate typespecs for repeated fields and enums.
142
+ * Add `package_prefix` command-line option to control namespacing on generated
143
+ code.
144
+ * Add `transform_module` command-line option with hooks for custom pre-encode
145
+ and post-decode logic.
146
+
147
+ ### Bug fixes
148
+
149
+ * Fix decoding of proto2 payloads containing legacy `group` fields. Instead of
150
+ crashing the decoder, those fields are now skipped.
151
+ * Fix compilation warnings on recent versions of Elixir.
152
+ * Fix `new!` to raise `ArgumentError` when given struct and module don't match.
153
+
154
+ ### Breaking changes
155
+
156
+ * Dropped support to OTP 21.1 and lower.
157
+
158
+ ## v0.7.1 (2020-01-07)
159
+
160
+ ### Enhancements
161
+
162
+ * Add typespec generation for enum fields.
163
+ * Add `new!/1` function to generated modules with strict field validation.
164
+ * Raise `Protobuf.DecodeError` when unable to decode binary input.
165
+ * Add `--version` command-line flag.
166
+
167
+ ## v0.7.0 (2019-12-19)
168
+
169
+ ## v0.6.3 (2019-08-19)
changed README.md
 
@@ -167,7 +167,7 @@ $ protoc --elixir_out=./lib --elixir_opt=include_docs=true *.proto
167
167
### gRPC Support
168
168
169
169
If you write [services](https://developers.google.com/protocol-buffers/docs/proto#services) in
170
- protobuf, you can generate [gRPC](https://github.com/tony612/grpc-elixir) code by passing
170
+ protobuf, you can generate [gRPC](https://github.com/elixir-grpc/grpc) code by passing
171
171
`plugins=grpc` in `--elixir_out`:
172
172
173
173
```
changed hex_metadata.config
 
@@ -1,12 +1,17 @@
1
- {<<"app">>,<<"protobuf">>}.
2
- {<<"build_tools">>,[<<"mix">>]}.
1
+ {<<"links">>,
2
+ [{<<"GitHub">>,<<"https://github.com/elixir-protobuf/protobuf">>}]}.
3
+ {<<"name">>,<<"protobuf">>}.
4
+ {<<"version">>,<<"0.13.0">>}.
3
5
{<<"description">>,<<"A pure Elixir implementation of Google Protobuf.">>}.
4
6
{<<"elixir">>,<<"~> 1.6">>}.
7
+ {<<"app">>,<<"protobuf">>}.
8
+ {<<"licenses">>,[<<"MIT">>]}.
5
9
{<<"files">>,
6
- [<<"mix.exs">>,<<"README.md">>,<<"lib/google">>,<<"lib/google/protobuf">>,
7
- <<"lib/google/protobuf/descriptor.pb.ex">>,
10
+ [<<"lib">>,<<"lib/elixirpb.pb.ex">>,<<"lib/google">>,
11
+ <<"lib/google/protobuf">>,<<"lib/google/protobuf/descriptor.pb.ex">>,
8
12
<<"lib/google/protobuf/compiler">>,
9
- <<"lib/google/protobuf/compiler/plugin.pb.ex">>,<<"lib/protobuf">>,
13
+ <<"lib/google/protobuf/compiler/plugin.pb.ex">>,<<"lib/protobuf.ex">>,
14
+ <<"lib/elixirpb">>,<<"lib/elixirpb/pb_extension.pb.ex">>,<<"lib/protobuf">>,
10
15
<<"lib/protobuf/message_props.ex">>,<<"lib/protobuf/extension">>,
11
16
<<"lib/protobuf/extension/props.ex">>,<<"lib/protobuf/wire">>,
12
17
<<"lib/protobuf/wire/zigzag.ex">>,<<"lib/protobuf/wire/types.ex">>,
 
@@ -29,20 +34,16 @@
29
34
<<"lib/protobuf/transform_module.ex">>,<<"lib/protobuf/extension.ex">>,
30
35
<<"lib/protobuf/dsl">>,<<"lib/protobuf/dsl/typespecs.ex">>,
31
36
<<"lib/protobuf/dsl/enum.ex">>,<<"lib/protobuf/transform_module">>,
32
- <<"lib/protobuf/transform_module/infer_fields_from_enum.ex">>,
33
- <<"lib/elixirpb.pb.ex">>,<<"lib/protobuf.ex">>,<<"src">>,
34
- <<"src/elixirpb.proto">>,<<"LICENSE">>,<<"priv/templates">>,
35
- <<"priv/templates/message.ex.eex">>,<<"priv/templates/service.ex.eex">>,
36
- <<"priv/templates/extension.ex.eex">>,<<"priv/templates/enum.ex.eex">>,
37
- <<".formatter.exs">>]}.
38
- {<<"licenses">>,[<<"MIT">>]}.
39
- {<<"links">>,
40
- [{<<"GitHub">>,<<"https://github.com/elixir-protobuf/protobuf">>}]}.
41
- {<<"name">>,<<"protobuf">>}.
37
+ <<"lib/protobuf/transform_module/infer_fields_from_enum.ex">>,<<"priv">>,
38
+ <<"priv/templates">>,<<"priv/templates/message.ex.eex">>,
39
+ <<"priv/templates/service.ex.eex">>,<<"priv/templates/extension.ex.eex">>,
40
+ <<"priv/templates/enum.ex.eex">>,<<".formatter.exs">>,<<"mix.exs">>,
41
+ <<"README.md">>,<<"LICENSE">>,<<"CHANGELOG.md">>,<<"src">>,
42
+ <<"src/elixirpb.proto">>]}.
42
43
{<<"requirements">>,
43
- [[{<<"app">>,<<"jason">>},
44
- {<<"name">>,<<"jason">>},
44
+ [[{<<"name">>,<<"jason">>},
45
+ {<<"app">>,<<"jason">>},
45
46
{<<"optional">>,true},
46
- {<<"repository">>,<<"hexpm">>},
47
- {<<"requirement">>,<<"~> 1.2">>}]]}.
48
- {<<"version">>,<<"0.12.0">>}.
47
+ {<<"requirement">>,<<"~> 1.2">>},
48
+ {<<"repository">>,<<"hexpm">>}]]}.
49
+ {<<"build_tools">>,[<<"mix">>]}.
changed lib/elixirpb.pb.ex
 
@@ -1,7 +1,7 @@
1
1
defmodule Elixirpb.FileOptions do
2
2
@moduledoc false
3
3
4
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
4
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
5
5
6
6
field :module_prefix, 1, optional: true, type: :string
7
7
end
added lib/elixirpb/pb_extension.pb.ex
 
@@ -0,0 +1,6 @@
1
+ defmodule Elixirpb.PbExtension do
2
+ @moduledoc false
3
+ use Protobuf, protoc_gen_elixir_version: "0.13.0"
4
+
5
+ extend Google.Protobuf.FileOptions, :file, 1047, optional: true, type: Elixirpb.FileOptions
6
+ end
changed lib/google/protobuf/compiler/plugin.pb.ex
 
@@ -1,7 +1,7 @@
1
1
defmodule Google.Protobuf.Compiler.CodeGeneratorResponse.Feature do
2
2
@moduledoc false
3
3
4
- use Protobuf, enum: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
4
+ use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
5
5
6
6
field :FEATURE_NONE, 0
7
7
field :FEATURE_PROTO3_OPTIONAL, 1
 
@@ -10,7 +10,7 @@ end
10
10
defmodule Google.Protobuf.Compiler.Version do
11
11
@moduledoc false
12
12
13
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
13
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
14
14
15
15
field :major, 1, optional: true, type: :int32
16
16
field :minor, 2, optional: true, type: :int32
 
@@ -21,7 +21,7 @@ end
21
21
defmodule Google.Protobuf.Compiler.CodeGeneratorRequest do
22
22
@moduledoc false
23
23
24
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
24
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
25
25
26
26
field :file_to_generate, 1, repeated: true, type: :string
27
27
field :parameter, 2, optional: true, type: :string
 
@@ -32,7 +32,7 @@ end
32
32
defmodule Google.Protobuf.Compiler.CodeGeneratorResponse.File do
33
33
@moduledoc false
34
34
35
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
35
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
36
36
37
37
field :name, 1, optional: true, type: :string
38
38
field :insertion_point, 2, optional: true, type: :string
 
@@ -43,7 +43,7 @@ end
43
43
defmodule Google.Protobuf.Compiler.CodeGeneratorResponse do
44
44
@moduledoc false
45
45
46
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
46
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
47
47
48
48
field :error, 1, optional: true, type: :string
49
49
field :supported_features, 2, optional: true, type: :uint64
changed lib/google/protobuf/descriptor.pb.ex
 
@@ -1,7 +1,7 @@
1
1
defmodule Google.Protobuf.FieldDescriptorProto.Type do
2
2
@moduledoc false
3
3
4
- use Protobuf, enum: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
4
+ use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
5
5
6
6
field :TYPE_DOUBLE, 1
7
7
field :TYPE_FLOAT, 2
 
@@ -26,7 +26,7 @@ end
26
26
defmodule Google.Protobuf.FieldDescriptorProto.Label do
27
27
@moduledoc false
28
28
29
- use Protobuf, enum: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
29
+ use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
30
30
31
31
field :LABEL_OPTIONAL, 1
32
32
field :LABEL_REQUIRED, 2
 
@@ -36,7 +36,7 @@ end
36
36
defmodule Google.Protobuf.FileOptions.OptimizeMode do
37
37
@moduledoc false
38
38
39
- use Protobuf, enum: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
39
+ use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
40
40
41
41
field :SPEED, 1
42
42
field :CODE_SIZE, 2
 
@@ -46,7 +46,7 @@ end
46
46
defmodule Google.Protobuf.FieldOptions.CType do
47
47
@moduledoc false
48
48
49
- use Protobuf, enum: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
49
+ use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
50
50
51
51
field :STRING, 0
52
52
field :CORD, 1
 
@@ -56,7 +56,7 @@ end
56
56
defmodule Google.Protobuf.FieldOptions.JSType do
57
57
@moduledoc false
58
58
59
- use Protobuf, enum: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
59
+ use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
60
60
61
61
field :JS_NORMAL, 0
62
62
field :JS_STRING, 1
 
@@ -66,7 +66,7 @@ end
66
66
defmodule Google.Protobuf.MethodOptions.IdempotencyLevel do
67
67
@moduledoc false
68
68
69
- use Protobuf, enum: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
69
+ use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
70
70
71
71
field :IDEMPOTENCY_UNKNOWN, 0
72
72
field :NO_SIDE_EFFECTS, 1
 
@@ -76,7 +76,7 @@ end
76
76
defmodule Google.Protobuf.GeneratedCodeInfo.Annotation.Semantic do
77
77
@moduledoc false
78
78
79
- use Protobuf, enum: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
79
+ use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
80
80
81
81
field :NONE, 0
82
82
field :SET, 1
 
@@ -86,7 +86,7 @@ end
86
86
defmodule Google.Protobuf.FileDescriptorSet do
87
87
@moduledoc false
88
88
89
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
89
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
90
90
91
91
field :file, 1, repeated: true, type: Google.Protobuf.FileDescriptorProto
92
92
end
 
@@ -94,7 +94,7 @@ end
94
94
defmodule Google.Protobuf.FileDescriptorProto do
95
95
@moduledoc false
96
96
97
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
97
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
98
98
99
99
field :name, 1, optional: true, type: :string
100
100
field :package, 2, optional: true, type: :string
 
@@ -114,7 +114,7 @@ end
114
114
defmodule Google.Protobuf.DescriptorProto.ExtensionRange do
115
115
@moduledoc false
116
116
117
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
117
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
118
118
119
119
field :start, 1, optional: true, type: :int32
120
120
field :end, 2, optional: true, type: :int32
 
@@ -124,7 +124,7 @@ end
124
124
defmodule Google.Protobuf.DescriptorProto.ReservedRange do
125
125
@moduledoc false
126
126
127
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
127
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
128
128
129
129
field :start, 1, optional: true, type: :int32
130
130
field :end, 2, optional: true, type: :int32
 
@@ -133,7 +133,7 @@ end
133
133
defmodule Google.Protobuf.DescriptorProto do
134
134
@moduledoc false
135
135
136
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
136
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
137
137
138
138
field :name, 1, optional: true, type: :string
139
139
field :field, 2, repeated: true, type: Google.Protobuf.FieldDescriptorProto
 
@@ -150,7 +150,7 @@ end
150
150
defmodule Google.Protobuf.ExtensionRangeOptions do
151
151
@moduledoc false
152
152
153
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
153
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
154
154
155
155
field :uninterpreted_option, 999, repeated: true, type: Google.Protobuf.UninterpretedOption
156
156
 
@@ -160,7 +160,7 @@ end
160
160
defmodule Google.Protobuf.FieldDescriptorProto do
161
161
@moduledoc false
162
162
163
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
163
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
164
164
165
165
field :name, 1, optional: true, type: :string
166
166
field :number, 3, optional: true, type: :int32
 
@@ -178,7 +178,7 @@ end
178
178
defmodule Google.Protobuf.OneofDescriptorProto do
179
179
@moduledoc false
180
180
181
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
181
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
182
182
183
183
field :name, 1, optional: true, type: :string
184
184
field :options, 2, optional: true, type: Google.Protobuf.OneofOptions
 
@@ -187,7 +187,7 @@ end
187
187
defmodule Google.Protobuf.EnumDescriptorProto.EnumReservedRange do
188
188
@moduledoc false
189
189
190
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
190
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
191
191
192
192
field :start, 1, optional: true, type: :int32
193
193
field :end, 2, optional: true, type: :int32
 
@@ -196,7 +196,7 @@ end
196
196
defmodule Google.Protobuf.EnumDescriptorProto do
197
197
@moduledoc false
198
198
199
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
199
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
200
200
201
201
field :name, 1, optional: true, type: :string
202
202
field :value, 2, repeated: true, type: Google.Protobuf.EnumValueDescriptorProto
 
@@ -212,7 +212,7 @@ end
212
212
defmodule Google.Protobuf.EnumValueDescriptorProto do
213
213
@moduledoc false
214
214
215
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
215
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
216
216
217
217
field :name, 1, optional: true, type: :string
218
218
field :number, 2, optional: true, type: :int32
 
@@ -222,7 +222,7 @@ end
222
222
defmodule Google.Protobuf.ServiceDescriptorProto do
223
223
@moduledoc false
224
224
225
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
225
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
226
226
227
227
field :name, 1, optional: true, type: :string
228
228
field :method, 2, repeated: true, type: Google.Protobuf.MethodDescriptorProto
 
@@ -232,7 +232,7 @@ end
232
232
defmodule Google.Protobuf.MethodDescriptorProto do
233
233
@moduledoc false
234
234
235
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
235
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
236
236
237
237
field :name, 1, optional: true, type: :string
238
238
field :input_type, 2, optional: true, type: :string
 
@@ -245,7 +245,7 @@ end
245
245
defmodule Google.Protobuf.FileOptions do
246
246
@moduledoc false
247
247
248
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
248
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
249
249
250
250
field :java_package, 1, optional: true, type: :string
251
251
field :java_outer_classname, 8, optional: true, type: :string
 
@@ -281,7 +281,7 @@ end
281
281
defmodule Google.Protobuf.MessageOptions do
282
282
@moduledoc false
283
283
284
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
284
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
285
285
286
286
field :message_set_wire_format, 1, optional: true, type: :bool, default: false
287
287
field :no_standard_descriptor_accessor, 2, optional: true, type: :bool, default: false
 
@@ -296,7 +296,7 @@ end
296
296
defmodule Google.Protobuf.FieldOptions do
297
297
@moduledoc false
298
298
299
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
299
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
300
300
301
301
field :ctype, 1,
302
302
optional: true,
 
@@ -325,7 +325,7 @@ end
325
325
defmodule Google.Protobuf.OneofOptions do
326
326
@moduledoc false
327
327
328
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
328
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
329
329
330
330
field :uninterpreted_option, 999, repeated: true, type: Google.Protobuf.UninterpretedOption
331
331
 
@@ -335,7 +335,7 @@ end
335
335
defmodule Google.Protobuf.EnumOptions do
336
336
@moduledoc false
337
337
338
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
338
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
339
339
340
340
field :allow_alias, 2, optional: true, type: :bool
341
341
field :deprecated, 3, optional: true, type: :bool, default: false
 
@@ -348,7 +348,7 @@ end
348
348
defmodule Google.Protobuf.EnumValueOptions do
349
349
@moduledoc false
350
350
351
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
351
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
352
352
353
353
field :deprecated, 1, optional: true, type: :bool, default: false
354
354
field :uninterpreted_option, 999, repeated: true, type: Google.Protobuf.UninterpretedOption
 
@@ -359,7 +359,7 @@ end
359
359
defmodule Google.Protobuf.ServiceOptions do
360
360
@moduledoc false
361
361
362
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
362
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
363
363
364
364
field :deprecated, 33, optional: true, type: :bool, default: false
365
365
field :uninterpreted_option, 999, repeated: true, type: Google.Protobuf.UninterpretedOption
 
@@ -370,7 +370,7 @@ end
370
370
defmodule Google.Protobuf.MethodOptions do
371
371
@moduledoc false
372
372
373
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
373
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
374
374
375
375
field :deprecated, 33, optional: true, type: :bool, default: false
376
376
 
@@ -388,7 +388,7 @@ end
388
388
defmodule Google.Protobuf.UninterpretedOption.NamePart do
389
389
@moduledoc false
390
390
391
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
391
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
392
392
393
393
field :name_part, 1, required: true, type: :string
394
394
field :is_extension, 2, required: true, type: :bool
 
@@ -397,7 +397,7 @@ end
397
397
defmodule Google.Protobuf.UninterpretedOption do
398
398
@moduledoc false
399
399
400
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
400
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
401
401
402
402
field :name, 2, repeated: true, type: Google.Protobuf.UninterpretedOption.NamePart
403
403
field :identifier_value, 3, optional: true, type: :string
 
@@ -411,7 +411,7 @@ end
411
411
defmodule Google.Protobuf.SourceCodeInfo.Location do
412
412
@moduledoc false
413
413
414
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
414
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
415
415
416
416
field :path, 1, repeated: true, type: :int32, packed: true, deprecated: false
417
417
field :span, 2, repeated: true, type: :int32, packed: true, deprecated: false
 
@@ -423,7 +423,7 @@ end
423
423
defmodule Google.Protobuf.SourceCodeInfo do
424
424
@moduledoc false
425
425
426
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
426
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
427
427
428
428
field :location, 1, repeated: true, type: Google.Protobuf.SourceCodeInfo.Location
429
429
end
 
@@ -431,7 +431,7 @@ end
431
431
defmodule Google.Protobuf.GeneratedCodeInfo.Annotation do
432
432
@moduledoc false
433
433
434
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
434
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
435
435
436
436
field :path, 1, repeated: true, type: :int32, packed: true, deprecated: false
437
437
field :source_file, 2, optional: true, type: :string
 
@@ -447,7 +447,7 @@ end
447
447
defmodule Google.Protobuf.GeneratedCodeInfo do
448
448
@moduledoc false
449
449
450
- use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto2
450
+ use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
451
451
452
452
field :annotation, 1, repeated: true, type: Google.Protobuf.GeneratedCodeInfo.Annotation
453
453
end
changed lib/protobuf.ex
 
@@ -175,7 +175,11 @@ defmodule Protobuf do
175
175
#=> ** (Protobuf.DecodeError) ...
176
176
177
177
"""
178
- @spec decode(binary(), message) :: %{required(:__struct__) => message} when message: module()
178
+ @spec decode(binary(), message) :: %{
179
+ required(:__struct__) => message,
180
+ optional(atom()) => any()
181
+ }
182
+ when message: module()
179
183
defdelegate decode(data, module), to: Protobuf.Decoder
180
184
181
185
@doc """
changed lib/protobuf/encoder.ex
 
@@ -83,7 +83,7 @@ defmodule Protobuf.Encoder do
83
83
84
84
defp skip_field?(:proto3, nil, _prop), do: true
85
85
defp skip_field?(:proto3, 0, %FieldProps{oneof: nil}), do: true
86
- defp skip_field?(:proto3, 0.0, %FieldProps{oneof: nil}), do: true
86
+ defp skip_field?(:proto3, +0.0, %FieldProps{oneof: nil}), do: true
87
87
defp skip_field?(:proto3, "", %FieldProps{oneof: nil}), do: true
88
88
defp skip_field?(:proto3, false, %FieldProps{oneof: nil}), do: true
89
89
defp skip_field?(_syntax, _val, _prop), do: false
 
@@ -143,9 +143,16 @@ defmodule Protobuf.Encoder do
143
143
144
144
defp encode_from_type(mod, msg) do
145
145
case msg do
146
- %{__struct__: ^mod} -> encode_to_iodata(msg)
147
- %_{} -> encode_to_iodata(struct(mod, Map.from_struct(msg)))
148
- _ -> encode_to_iodata(struct(mod, msg))
146
+ %{__struct__: ^mod} ->
147
+ encode_to_iodata(msg)
148
+
149
+ %other_mod{} = struct ->
150
+ raise Protobuf.EncodeError,
151
+ message:
152
+ "struct #{inspect(other_mod)} can't be encoded as #{inspect(mod)}: #{inspect(struct)}"
153
+
154
+ _ ->
155
+ encode_to_iodata(struct(mod, msg))
149
156
end
150
157
end
changed lib/protobuf/json/encode.ex
 
@@ -162,11 +162,19 @@ defmodule Protobuf.JSON.Encode do
162
162
defp encode_regular_fields(struct, %{field_props: field_props}, opts) do
163
163
for {_field_num, %{name_atom: name, oneof: nil} = prop} <- field_props,
164
164
%{^name => value} = struct,
165
- opts[:emit_unpopulated] || !default?(prop, value) do
165
+ emit?(prop, value) || opts[:emit_unpopulated] do
166
166
encode_field(prop, value, opts)
167
167
end
168
168
end
169
169
170
+ defp emit?(_prop, nil) do
171
+ false
172
+ end
173
+
174
+ defp emit?(prop, value) do
175
+ if default?(prop, value), do: prop.proto3_optional?, else: true
176
+ end
177
+
170
178
defp encode_oneof_fields(struct, message_props, opts) do
171
179
%{field_tags: field_tags, field_props: field_props, oneof: oneofs} = message_props
172
180
 
@@ -301,7 +309,13 @@ defmodule Protobuf.JSON.Encode do
301
309
defp maybe_repeat(%{repeated?: false}, val, fun), do: fun.(val)
302
310
defp maybe_repeat(%{repeated?: true}, val, fun), do: Enum.map(val, fun)
303
311
304
- defp default?(_prop, value) when value in [nil, 0, false, [], "", 0.0, %{}], do: true
312
+ defp default?(_prop, +0.0), do: true
313
+ defp default?(_prop, nil), do: true
314
+ defp default?(_prop, 0), do: true
315
+ defp default?(_prop, false), do: true
316
+ defp default?(_prop, []), do: true
317
+ defp default?(_prop, ""), do: true
318
+ defp default?(_prop, %{} = map) when map_size(map) == 0, do: true
305
319
defp default?(%{type: {:enum, enum}}, key) when is_atom(key), do: enum.value(key) == 0
306
320
defp default?(_prop, _value), do: false
changed mix.exs
 
@@ -2,7 +2,7 @@ defmodule Protobuf.Mixfile do
2
2
use Mix.Project
3
3
4
4
@source_url "https://github.com/elixir-protobuf/protobuf"
5
- @version "0.12.0"
5
+ @version "0.13.0"
6
6
@description "A pure Elixir implementation of Google Protobuf."
7
7
8
8
def project do
 
@@ -73,17 +73,6 @@ defmodule Protobuf.Mixfile do
73
73
[
74
74
maintainers: ["Bing Han", "Andrea Leopardi"],
75
75
licenses: ["MIT"],
76
- files: ~w(
77
- mix.exs
78
- README.md
79
- lib/google
80
- lib/protobuf
81
- lib/*.ex
82
- src
83
- LICENSE
84
- priv/templates
85
- .formatter.exs
86
- ),
87
76
links: %{"GitHub" => @source_url}
88
77
]
89
78
end