File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ defmodule Protobuf.Encoder do
8
8
9
9
@ spec encode_to_iodata ( struct ( ) ) :: iodata ( )
10
10
def encode_to_iodata ( % mod { } = struct ) do
11
- encode_with_message_props ( struct , mod . __message_props__ ( ) )
11
+ struct
12
+ |> transform_module ( mod )
13
+ |> do_encode_to_iodata ( )
12
14
end
13
15
14
16
@ spec encode ( struct ( ) ) :: binary ( )
@@ -19,6 +21,10 @@ defmodule Protobuf.Encoder do
19
21
|> IO . iodata_to_binary ( )
20
22
end
21
23
24
+ defp do_encode_to_iodata ( % mod { } = struct ) do
25
+ encode_with_message_props ( struct , mod . __message_props__ ( ) )
26
+ end
27
+
22
28
defp encode_with_message_props (
23
29
struct ,
24
30
% MessageProps { syntax: syntax , field_props: field_props , ordered_tags: ordered_tags } =
@@ -148,15 +154,15 @@ defmodule Protobuf.Encoder do
148
154
defp encode_from_type ( mod , msg ) do
149
155
case msg do
150
156
% { __struct__: ^ mod } ->
151
- encode_to_iodata ( msg )
157
+ do_encode_to_iodata ( msg )
152
158
153
159
% other_mod { } = struct ->
154
160
raise Protobuf.EncodeError ,
155
161
message:
156
162
"struct #{ inspect ( other_mod ) } can't be encoded as #{ inspect ( mod ) } : #{ inspect ( struct ) } "
157
163
158
164
_ ->
159
- encode_to_iodata ( struct ( mod , msg ) )
165
+ do_encode_to_iodata ( struct ( mod , msg ) )
160
166
end
161
167
end
162
168
You can’t perform that action at this time.
0 commit comments