defimpl ProtoDef.Gen.Elixir.Protocol, for: ProtoDef.Type.Option do @data_var ProtoDef.Type.data_var @input_var ProtoDef.Type.input_var def decoder(descr, ctx) do item_ast = ProtoDef.Gen.Elixir.Protocol.decoder(descr.type, ctx) quote do with do <> = unquote(@data_var) if has_field == 1 do unquote(item_ast) else {nil, unquote(@data_var)} end end end end def encoder(descr, ctx) do item_ast = ProtoDef.Gen.Elixir.Protocol.encoder(descr.type, ctx) quote do with do has_field = if unquote(@input_var), do: 1, else: 0 if has_field == 1 do [<>, unquote(item_ast)] else <> end end end end end