lib/xdr/contract/config_setting/contract_cost_param_entry.ex

defmodule StellarBase.XDR.ContractCostParamEntry do
  @moduledoc """
  Automatically generated by xdrgen
  DO NOT EDIT or your changes may be overwritten

  Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr

  Representation of Stellar `ContractCostParamEntry` type.
  """

  @behaviour XDR.Declaration

  alias StellarBase.XDR.{
    Int64,
    ExtensionPoint
  }

  @struct_spec XDR.Struct.new(
                 const_term: Int64,
                 linear_term: Int64,
                 ext: ExtensionPoint
               )

  @type const_term_type :: Int64.t()
  @type linear_term_type :: Int64.t()
  @type ext_type :: ExtensionPoint.t()

  @type t :: %__MODULE__{
          const_term: const_term_type(),
          linear_term: linear_term_type(),
          ext: ext_type()
        }

  defstruct [:const_term, :linear_term, :ext]

  @spec new(const_term :: const_term_type(), linear_term :: linear_term_type(), ext :: ext_type()) ::
          t()
  def new(
        %Int64{} = const_term,
        %Int64{} = linear_term,
        %ExtensionPoint{} = ext
      ),
      do: %__MODULE__{const_term: const_term, linear_term: linear_term, ext: ext}

  @impl true
  def encode_xdr(%__MODULE__{const_term: const_term, linear_term: linear_term, ext: ext}) do
    [const_term: const_term, linear_term: linear_term, ext: ext]
    |> XDR.Struct.new()
    |> XDR.Struct.encode_xdr()
  end

  @impl true
  def encode_xdr!(%__MODULE__{const_term: const_term, linear_term: linear_term, ext: ext}) do
    [const_term: const_term, linear_term: linear_term, ext: ext]
    |> XDR.Struct.new()
    |> XDR.Struct.encode_xdr!()
  end

  @impl true
  def decode_xdr(bytes, struct \\ @struct_spec)

  def decode_xdr(bytes, struct) do
    case XDR.Struct.decode_xdr(bytes, struct) do
      {:ok,
       {%XDR.Struct{components: [const_term: const_term, linear_term: linear_term, ext: ext]},
        rest}} ->
        {:ok, {new(const_term, linear_term, ext), rest}}

      error ->
        error
    end
  end

  @impl true
  def decode_xdr!(bytes, struct \\ @struct_spec)

  def decode_xdr!(bytes, struct) do
    {%XDR.Struct{components: [const_term: const_term, linear_term: linear_term, ext: ext]}, rest} =
      XDR.Struct.decode_xdr!(bytes, struct)

    {new(const_term, linear_term, ext), rest}
  end
end