-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated SCVal and SCValType structs, and created optionals
- Loading branch information
1 parent
99d7b78
commit 11efceb
Showing
32 changed files
with
534 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
defmodule StellarBase.XDR.OptionalSCVec do | ||
@moduledoc """ | ||
Representation of Stellar `OptionalSCVec` type. | ||
""" | ||
|
||
alias StellarBase.XDR.SCVec | ||
|
||
@behaviour XDR.Declaration | ||
|
||
@optional_spec XDR.Optional.new(SCVec) | ||
|
||
@type sc_vec :: SCVec.t() | nil | ||
|
||
@type t :: %__MODULE__{sc_vec: sc_vec()} | ||
|
||
defstruct [:sc_vec] | ||
|
||
@spec new(sc_vec :: sc_vec()) :: t() | ||
def new(sc_vec \\ nil), do: %__MODULE__{sc_vec: sc_vec} | ||
|
||
@impl true | ||
def encode_xdr(%__MODULE__{sc_vec: sc_vec}) do | ||
sc_vec | ||
|> XDR.Optional.new() | ||
|> XDR.Optional.encode_xdr() | ||
end | ||
|
||
@impl true | ||
def encode_xdr!(%__MODULE__{sc_vec: sc_vec}) do | ||
sc_vec | ||
|> XDR.Optional.new() | ||
|> XDR.Optional.encode_xdr!() | ||
end | ||
|
||
@impl true | ||
def decode_xdr(bytes, optional_spec \\ @optional_spec) | ||
|
||
def decode_xdr(bytes, optional_spec) do | ||
case XDR.Optional.decode_xdr(bytes, optional_spec) do | ||
{:ok, {%XDR.Optional{type: sc_vec}, rest}} -> | ||
{:ok, {new(sc_vec), rest}} | ||
|
||
{:ok, {nil, rest}} -> | ||
{:ok, {new(), rest}} | ||
|
||
error -> | ||
error | ||
end | ||
end | ||
|
||
@impl true | ||
def decode_xdr!(bytes, optional_spec \\ @optional_spec) | ||
|
||
def decode_xdr!(bytes, optional_spec) do | ||
case XDR.Optional.decode_xdr!(bytes, optional_spec) do | ||
{%XDR.Optional{type: sc_vec}, rest} -> {new(sc_vec), rest} | ||
{nil, rest} -> {new(), rest} | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.