@@ -59,11 +59,11 @@ defmodule Protobuf.JSON.Decode do
5959
6060 case Integer . parse ( string ) do
6161 { seconds , "s" } when seconds in @ duration_seconds_range ->
62- mod . new! ( seconds: seconds )
62+ struct! ( mod , seconds: seconds )
6363
6464 { seconds , "." <> nanos_with_s } when seconds in @ duration_seconds_range ->
6565 case Utils . parse_nanoseconds ( nanos_with_s ) do
66- { nanos , "s" } -> mod . new! ( seconds: seconds , nanos: nanos * sign )
66+ { nanos , "s" } -> struct! ( mod , seconds: seconds , nanos: nanos * sign )
6767 :error -> throw ( { :bad_duration , string , nanos_with_s } )
6868 end
6969
@@ -74,80 +74,80 @@ defmodule Protobuf.JSON.Decode do
7474
7575 def from_json_data ( string , Google.Protobuf.Timestamp = mod ) when is_binary ( string ) do
7676 case Protobuf.JSON.RFC3339 . decode ( string ) do
77- { :ok , seconds , nanos } -> mod . new! ( seconds: seconds , nanos: nanos )
77+ { :ok , seconds , nanos } -> struct! ( mod , seconds: seconds , nanos: nanos )
7878 { :error , reason } -> throw ( { :bad_timestamp , string , reason } )
7979 end
8080 end
8181
8282 def from_json_data ( map , Google.Protobuf.Empty = mod ) when map == % { } do
83- mod . new! ( [ ] )
83+ struct! ( mod )
8484 end
8585
8686 def from_json_data ( int , Google.Protobuf.Int32Value = mod ) ,
87- do: mod . new! ( value: decode_scalar ( :int32 , :unknown_name , int ) )
87+ do: struct! ( mod , value: decode_scalar ( :int32 , :unknown_name , int ) )
8888
8989 def from_json_data ( int , Google.Protobuf.UInt32Value = mod ) ,
90- do: mod . new! ( value: decode_scalar ( :uint32 , :unknown_name , int ) )
90+ do: struct! ( mod , value: decode_scalar ( :uint32 , :unknown_name , int ) )
9191
9292 def from_json_data ( int , Google.Protobuf.UInt64Value = mod ) ,
93- do: mod . new! ( value: decode_scalar ( :uint64 , :unknown_name , int ) )
93+ do: struct! ( mod , value: decode_scalar ( :uint64 , :unknown_name , int ) )
9494
9595 def from_json_data ( int , Google.Protobuf.Int64Value = mod ) ,
96- do: mod . new! ( value: decode_scalar ( :int64 , :unknown_name , int ) )
96+ do: struct! ( mod , value: decode_scalar ( :int64 , :unknown_name , int ) )
9797
9898 def from_json_data ( number , mod )
9999 when mod in [
100100 Google.Protobuf.FloatValue ,
101101 Google.Protobuf.DoubleValue
102102 ] and ( is_float ( number ) or is_integer ( number ) ) do
103- mod . new! ( value: number * 1.0 )
103+ struct! ( mod , value: number * 1.0 )
104104 end
105105
106106 def from_json_data ( bool , Google.Protobuf.BoolValue = mod ) when is_boolean ( bool ) do
107- mod . new! ( value: decode_scalar ( :bool , :unknown_field , bool ) )
107+ struct! ( mod , value: decode_scalar ( :bool , :unknown_field , bool ) )
108108 end
109109
110110 def from_json_data ( string , Google.Protobuf.StringValue = mod ) when is_binary ( string ) do
111- mod . new! ( value: decode_scalar ( :string , :unknown_field , string ) )
111+ struct! ( mod , value: decode_scalar ( :string , :unknown_field , string ) )
112112 end
113113
114114 def from_json_data ( bytes , Google.Protobuf.BytesValue = mod ) when is_binary ( bytes ) do
115- mod . new! ( value: decode_scalar ( :bytes , :unknown_field , bytes ) )
115+ struct! ( mod , value: decode_scalar ( :bytes , :unknown_field , bytes ) )
116116 end
117117
118118 def from_json_data ( list , Google.Protobuf.ListValue = mod ) when is_list ( list ) do
119- mod . new! ( values: Enum . map ( list , & from_json_data ( & 1 , Google.Protobuf.Value ) ) )
119+ struct! ( mod , values: Enum . map ( list , & from_json_data ( & 1 , Google.Protobuf.Value ) ) )
120120 end
121121
122122 def from_json_data ( struct , Google.Protobuf.Struct = mod ) when is_map ( struct ) do
123123 fields =
124124 Map . new ( struct , fn { key , val } -> { key , from_json_data ( val , Google.Protobuf.Value ) } end )
125125
126- mod . new! ( fields: fields )
126+ struct! ( mod , fields: fields )
127127 end
128128
129129 def from_json_data ( term , Google.Protobuf.Value = mod ) do
130130 cond do
131131 is_nil ( term ) ->
132- mod . new! ( kind: { :null_value , :NULL_VALUE } )
132+ struct! ( mod , kind: { :null_value , :NULL_VALUE } )
133133
134134 is_binary ( term ) ->
135- mod . new! ( kind: { :string_value , term } )
135+ struct! ( mod , kind: { :string_value , term } )
136136
137137 is_integer ( term ) ->
138- mod . new! ( kind: { :number_value , term * 1.0 } )
138+ struct! ( mod , kind: { :number_value , term * 1.0 } )
139139
140140 is_float ( term ) ->
141- mod . new! ( kind: { :number_value , term } )
141+ struct! ( mod , kind: { :number_value , term } )
142142
143143 is_boolean ( term ) ->
144- mod . new! ( kind: { :bool_value , term } )
144+ struct! ( mod , kind: { :bool_value , term } )
145145
146146 is_list ( term ) ->
147- mod . new! ( kind: { :list_value , from_json_data ( term , Google.Protobuf.ListValue ) } )
147+ struct! ( mod , kind: { :list_value , from_json_data ( term , Google.Protobuf.ListValue ) } )
148148
149149 is_map ( term ) ->
150- mod . new! ( kind: { :struct_value , from_json_data ( term , Google.Protobuf.Struct ) } )
150+ struct! ( mod , kind: { :struct_value , from_json_data ( term , Google.Protobuf.Struct ) } )
151151
152152 true ->
153153 throw ( { :bad_message , term , mod } )
@@ -158,8 +158,8 @@ defmodule Protobuf.JSON.Decode do
158158 paths = String . split ( data , "," )
159159
160160 cond do
161- data == "" -> mod . new! ( paths: [ ] )
162- paths = Enum . map ( paths , & convert_field_mask_to_underscore / 1 ) -> mod . new! ( paths: paths )
161+ data == "" -> struct! ( mod , paths: [ ] )
162+ paths = Enum . map ( paths , & convert_field_mask_to_underscore / 1 ) -> struct! ( mod , paths: paths )
163163 true -> throw ( { :bad_field_mask , data } )
164164 end
165165 end
@@ -187,7 +187,7 @@ defmodule Protobuf.JSON.Decode do
187187 |> message_mod . encode ( )
188188 end
189189
190- mod . new! ( type_url: type_url , value: encoded )
190+ struct! ( mod , type_url: type_url , value: encoded )
191191 end
192192
193193 def from_json_data ( data , module ) when is_map ( data ) and is_atom ( module ) do
0 commit comments