Skip to content

Optional example

Juan Hurtado edited this page May 16, 2020 · 2 revisions
defmodule XDR.OptionalString do
  @behaviour XDR.Declaration

  defstruct type: nil

  def new(type), do: %XDR.OptionalString{type: type}

  defdelegate encode_xdr(type), to: XDR.Optional
  defdelegate encode_xdr!(type), to: XDR.Optional

  def decode_xdr(bytes, struct \\ %{type: XDR.String})
  def decode_xdr(bytes, struct), do: XDR.Optional.decode_xdr(bytes, struct)

  def decode_xdr!(bytes, struct \\ %{type: XDR.String})
  def decode_xdr!(bytes, struct), do: XDR.Optional.decode_xdr!(bytes, struct)
end
Clone this wiki locally