Documentation
¶
Overview ¶
Package sailfish provides fast, unsigned, fixed-scale decimal values for trading and financial protocols.
A value is stored as one scaled integer:
value = units / 10^scale
The package supports uint8, uint16, uint32, uint64, and uint256.Int units. Fractional scale and backend capacity are selected independently. Its hot parse, text/CBOR append, strict CBOR decode, compare, and arithmetic paths are allocation-free when caller-owned output buffers have enough capacity.
Index ¶
- Constants
- func Compare[VA Venue[UA], UA Unit, VB Venue[UB], UB Unit](a Decimal[VA, UA], b Decimal[VB, UB]) int
- type AmountUint8
- type AmountUint16
- type AmountUint32
- type AmountUint64
- type AmountUint256
- type Codec
- func (c Codec[V, U]) AppendCBOR(dst []byte, d Decimal[V, U]) []byte
- func (c Codec[V, U]) AppendJSON(dst []byte, d Decimal[V, U]) []byte
- func (c Codec[V, U]) AppendTo(dst []byte, d Decimal[V, U]) []byte
- func (c Codec[V, U]) CBORLen(d Decimal[V, U]) int
- func (c Codec[V, U]) Canonical(d Decimal[V, U]) Decimal[V, U]
- func (c Codec[V, U]) FromUnits(units U) Decimal[V, U]
- func (c Codec[V, U]) Len(d Decimal[V, U]) int
- func (c Codec[V, U]) MaxIntegerDigits() int
- func (c Codec[V, U]) Parse(s string) (Decimal[V, U], error)
- func (c Codec[V, U]) ParseBytes(b []byte) (Decimal[V, U], error)
- func (c Codec[V, U]) ParseCBOR(raw []byte) (Decimal[V, U], error)
- func (c Codec[V, U]) ParseCBORFirst(raw []byte) (Decimal[V, U], []byte, error)
- func (c Codec[V, U]) ParseCompact(s string) (Decimal[V, U], error)
- func (c Codec[V, U]) Scale() Notion
- func (c Codec[V, U]) String(d Decimal[V, U]) string
- type Decimal
- func (d Decimal[V, U]) Add(other Decimal[V, U]) (Decimal[V, U], error)
- func (d *Decimal[V, U]) AddAssign(other Decimal[V, U]) (overflow bool)
- func (d Decimal[V, U]) AddOverflow(other Decimal[V, U]) (Decimal[V, U], bool)
- func (d Decimal[V, U]) AppendCBOR(dst []byte) []byte
- func (d Decimal[V, U]) AppendJSON(dst []byte) []byte
- func (d Decimal[V, U]) AppendText(dst []byte) ([]byte, error)
- func (d Decimal[V, U]) AppendTo(dst []byte) []byte
- func (d Decimal[V, U]) CBORLen() int
- func (d Decimal[V, U]) Canonical() Decimal[V, U]
- func (d Decimal[V, U]) Cmp(other Decimal[V, U]) int
- func (d Decimal[V, U]) Compare(other Decimal[V, U]) int
- func (d Decimal[V, U]) Equal(other Decimal[V, U]) bool
- func (d Decimal[V, U]) HasRepresentation() bool
- func (d Decimal[V, U]) IsZero() bool
- func (d Decimal[V, U]) Len() int
- func (d Decimal[V, U]) Less(other Decimal[V, U]) bool
- func (d Decimal[V, U]) MarshalCBOR() ([]byte, error)
- func (d Decimal[V, U]) MarshalJSON() ([]byte, error)
- func (d Decimal[V, U]) MarshalText() ([]byte, error)
- func (d *Decimal[V, U]) SetUnits(units U)
- func (d Decimal[V, U]) String() string
- func (d Decimal[V, U]) Sub(other Decimal[V, U]) (Decimal[V, U], error)
- func (d *Decimal[V, U]) SubAssign(other Decimal[V, U]) (underflow bool)
- func (d Decimal[V, U]) SubUnderflow(other Decimal[V, U]) (Decimal[V, U], bool)
- func (d Decimal[V, U]) Units() U
- func (d *Decimal[V, U]) UnmarshalCBOR(raw []byte) error
- func (d *Decimal[V, U]) UnmarshalJSON(data []byte) error
- func (d *Decimal[V, U]) UnmarshalText(text []byte) error
- type Error
- type Fraction0
- type Fraction1
- type Fraction2
- type Fraction3
- type Fraction4
- type Fraction5
- type Fraction6
- type Fraction7
- type Fraction8
- type Fraction9
- type Fraction10
- type Fraction11
- type Fraction12
- type Fraction13
- type Fraction14
- type Fraction15
- type Fraction16
- type Fraction17
- type Fraction18
- type Fraction19
- type Fraction20
- type NativeUnit
- type Notion
- type PriceUint8
- type PriceUint16
- type PriceUint32
- type PriceUint64
- type PriceUint256
- type Uint8Units
- type Uint16Units
- type Uint32Units
- type Uint64Units
- type Uint256Codec
- func (c Uint256Codec) AppendCBOR(dst []byte, units uint256.Int) []byte
- func (c Uint256Codec) AppendTo(dst []byte, units uint256.Int) []byte
- func (c Uint256Codec) CBORLen(units uint256.Int) int
- func (c Uint256Codec) Len(units uint256.Int) int
- func (c Uint256Codec) MaxIntegerDigits() int
- func (c Uint256Codec) Parse(input string) (uint256.Int, Error)
- func (c Uint256Codec) ParseBytes(input []byte) (uint256.Int, Error)
- func (c Uint256Codec) ParseBytesInto(input []byte, dst *uint256.Int) Error
- func (c Uint256Codec) ParseCBOR(raw []byte) (uint256.Int, Error)
- func (c Uint256Codec) ParseCBORFirst(raw []byte) (uint256.Int, []byte, Error)
- func (c Uint256Codec) ParseCBORFirstInto(raw []byte, dst *uint256.Int) ([]byte, Error)
- func (c Uint256Codec) ParseCBORInto(raw []byte, dst *uint256.Int) Error
- func (c Uint256Codec) ParseInto(input string, dst *uint256.Int) Error
- func (c Uint256Codec) Scale() Notion
- type Uint256Units
- type Unit
- type Venue
- type VenueScale
Examples ¶
Constants ¶
const MaxCBORSize = 35
MaxCBORSize is the maximum preferred CBOR encoding size of one Decimal. It is tag 2, a one-byte length argument, and a 32-byte uint256 magnitude.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AmountUint8 ¶
type AmountUint8[S VenueScale] struct { Uint8Units }
AmountUint8 through AmountUint256 are the amount-kind equivalents. Price and amount formats remain distinct types even with equal scale and backend.
func (AmountUint8[S]) NotionScale ¶
func (AmountUint8[S]) NotionScale() Notion
type AmountUint16 ¶
type AmountUint16[S VenueScale] struct { Uint16Units }
func (AmountUint16[S]) NotionScale ¶
func (AmountUint16[S]) NotionScale() Notion
type AmountUint32 ¶
type AmountUint32[S VenueScale] struct { Uint32Units }
func (AmountUint32[S]) NotionScale ¶
func (AmountUint32[S]) NotionScale() Notion
type AmountUint64 ¶
type AmountUint64[S VenueScale] struct { Uint64Units }
func (AmountUint64[S]) NotionScale ¶
func (AmountUint64[S]) NotionScale() Notion
type AmountUint256 ¶
type AmountUint256[S VenueScale] struct { Uint256Units }
func (AmountUint256[S]) NotionScale ¶
func (AmountUint256[S]) NotionScale() Notion
type Codec ¶
Codec validates a venue once and carries its scale through repeated parse/format operations. It is the preferred hot-loop API. Its zero value is usable and derives scale from the compile-time venue; NewCodec validates and caches that scale for the hot path.
The one-byte scalePlusOne encoding reserves zero for zero-value derivation.
Example (ManualPositionalCBOR) ¶
package main
import (
"fmt"
"github.com/JekaMas/sailfish"
"github.com/holiman/uint256"
)
type examplePriceFormat = sailfish.PriceUint64[sailfish.Fraction5]
type exampleAmountFormat = sailfish.AmountUint256[sailfish.Fraction18]
func main() {
priceCodec, err := sailfish.NewCodec[examplePriceFormat]()
if err != nil {
fmt.Println(err)
return
}
amountCodec, err := sailfish.NewCodec[exampleAmountFormat]()
if err != nil {
fmt.Println(err)
return
}
price := priceCodec.FromUnits(12_331_232)
var amountUnits uint256.Int
amountUnits.SetUint64(1_250_000_000_000_000_000)
amount := amountCodec.FromUnits(amountUnits)
record := make([]byte, 0, 1+2*sailfish.MaxCBORSize)
record = append(record, 0x82) // fixed two-field CBOR array
record = priceCodec.AppendCBOR(record, price)
record = amountCodec.AppendCBOR(record, amount)
raw := record[1:]
decodedPrice, raw, err := priceCodec.ParseCBORFirst(raw)
if err != nil {
fmt.Println(err)
return
}
decodedAmount, raw, err := amountCodec.ParseCBORFirst(raw)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(decodedPrice.String())
fmt.Println(decodedAmount.String())
fmt.Println(len(raw))
}
Output: 123.31232 1.250000000000000000 0
Example (Price) ¶
package main
import (
"fmt"
"github.com/JekaMas/sailfish"
)
type examplePriceFormat = sailfish.PriceUint64[sailfish.Fraction5]
func main() {
codec, err := sailfish.NewCodec[examplePriceFormat]()
if err != nil {
fmt.Println(err)
return
}
price, err := codec.Parse("123.31232")
if err != nil {
fmt.Println(err)
return
}
next, err := price.Add(codec.FromUnits(1))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(next.String())
fmt.Println(next.Units())
}
Output: 123.31233 12331233
func (Codec[V, U]) AppendCBOR ¶
AppendCBOR appends preferred deterministic CBOR after validating the codec.
func (Codec[V, U]) CBORLen ¶
CBORLen returns the exact preferred CBOR size after validating the codec.
func (Codec[V, U]) MaxIntegerDigits ¶
MaxIntegerDigits reports how many decimal digits can occur before the point in this backend's maximum value at the configured scale. It describes capacity independently from fractional scale; it does not imply that every value with that many digits fits the binary backend.
func (Codec[V, U]) ParseBytes ¶
ParseBytes parses b directly and never retains it.
func (Codec[V, U]) ParseCBOR ¶
ParseCBOR decodes preferred deterministic CBOR without retaining raw input.
func (Codec[V, U]) ParseCBORFirst ¶
ParseCBORFirst decodes one preferred deterministic CBOR decimal from the start of raw and returns the unconsumed suffix. It is the typed hot-path decoder for decimal fields inside manually encoded positional arrays. ParseCBOR remains the strict whole-item API.
func (Codec[V, U]) ParseCompact ¶
ParseCompact never retains s.
type Decimal ¶
Decimal is an unsigned fixed-scale decimal stored as one scaled integer.
Numeric value = units / 10^venue-scale.
representation is optional immutable wire text. Numeric mutation clears the string header; it never edits string bytes. Clearing the header allocates nothing, and strings previously returned by String remain valid.
Example (Serialization) ¶
package main
import (
"fmt"
"github.com/JekaMas/sailfish"
"github.com/fxamacker/cbor/v2"
json "github.com/goccy/go-json"
"github.com/holiman/uint256"
)
type examplePriceFormat = sailfish.PriceUint64[sailfish.Fraction5]
type examplePrice = sailfish.Decimal[examplePriceFormat, uint64]
type exampleAmountFormat = sailfish.AmountUint256[sailfish.Fraction18]
type exampleAmount = sailfish.Decimal[exampleAmountFormat, uint256.Int]
type exampleQuote struct {
_ struct{} `cbor:",toarray"`
Price examplePrice
Amount exampleAmount
}
func main() {
priceCodec, err := sailfish.NewCodec[examplePriceFormat]()
if err != nil {
fmt.Println(err)
return
}
amountCodec, err := sailfish.NewCodec[exampleAmountFormat]()
if err != nil {
fmt.Println(err)
return
}
price, err := priceCodec.Parse("123.31232")
if err != nil {
fmt.Println(err)
return
}
amount, err := amountCodec.Parse("1.250000000000000000")
if err != nil {
fmt.Println(err)
return
}
quote := exampleQuote{Price: price, Amount: amount}
jsonRaw, err := json.Marshal(quote.Price)
if err != nil {
fmt.Println(err)
return
}
enc, err := cbor.CanonicalEncOptions().EncMode()
if err != nil {
fmt.Println(err)
return
}
cborRaw, err := enc.Marshal(quote)
if err != nil {
fmt.Println(err)
return
}
dec, err := cbor.DecOptions{}.DecMode()
if err != nil {
fmt.Println(err)
return
}
var decoded exampleQuote
if err := dec.Unmarshal(cborRaw, &decoded); err != nil {
fmt.Println(err)
return
}
fmt.Println(string(jsonRaw))
fmt.Println(decoded.Price.String())
fmt.Println(decoded.Amount.String())
}
Output: "123.31232" 123.31232 1.250000000000000000
func New ¶
New parses s. It retains s only when s is already canonical fixed-scale text. Parsing is strict: no whitespace, signs, exponent notation, or excess fractional digits are accepted.
func NewCompact ¶
NewCompact parses s without retaining its backing storage.
func NewFromUnits ¶
NewFromUnits constructs a decimal from already-scaled units.
Example ¶
package main
import (
"fmt"
"github.com/JekaMas/sailfish"
)
func main() {
type AmountFormat = sailfish.AmountUint32[sailfish.Fraction6]
amount, err := sailfish.NewFromUnits[AmountFormat](uint32(1_234_567))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amount.String())
}
Output: 1.234567
func (*Decimal[V, U]) AddAssign ¶
AddAssign leaves d unchanged on overflow. A value-changing success clears cached text without allocation; adding zero preserves it.
func (Decimal[V, U]) AddOverflow ¶
AddOverflow returns the wrapped sum and reports unit overflow.
func (Decimal[V, U]) AppendCBOR ¶
AppendCBOR appends the preferred deterministic CBOR encoding. It allocates only when dst has insufficient capacity. When Decimal is a field in a cbor:",toarray" struct, the result is a scalar array element rather than a redundant nested one-element array.
func (Decimal[V, U]) AppendJSON ¶
AppendJSON appends a quoted JSON decimal string. Decimal text contains only ASCII digits and a decimal point, so no escaping pass is needed.
func (Decimal[V, U]) AppendText ¶
AppendText implements the append-style text encoding contract available in current Go versions without requiring a newly owned result slice.
func (Decimal[V, U]) AppendTo ¶
AppendTo appends canonical fixed-scale text. It allocates only when dst has insufficient capacity.
func (Decimal[V, U]) CBORLen ¶
CBORLen returns the exact size of the preferred CBOR encoding. Decimal is encoded as its scaled unsigned integer. Scale and retained source text are type/cache metadata and are intentionally absent from the wire format.
func (Decimal[V, U]) Canonical ¶
Canonical returns a copy retaining canonical text. It never mutates shared state and is safe to use concurrently with readers of the original value.
func (Decimal[V, U]) HasRepresentation ¶
HasRepresentation reports whether canonical wire text is currently retained.
func (Decimal[V, U]) MarshalCBOR ¶
MarshalCBOR implements the fxamacker/cbor Marshaler contract. The returned owned slice necessarily allocates once; use AppendCBOR on hot paths.
func (Decimal[V, U]) MarshalJSON ¶
func (Decimal[V, U]) MarshalText ¶
func (*Decimal[V, U]) SetUnits ¶
func (d *Decimal[V, U]) SetUnits(units U)
SetUnits replaces the scaled integer. A value-changing update invalidates cached text without allocation; setting the same value preserves it.
func (Decimal[V, U]) String ¶
String returns retained text when available. Otherwise it creates exactly one result string allocation and does not mutate d.
func (*Decimal[V, U]) SubAssign ¶
SubAssign leaves d unchanged on underflow. A value-changing success clears cached text without allocation; subtracting zero preserves it.
func (Decimal[V, U]) SubUnderflow ¶
SubUnderflow returns the wrapped difference and reports unit underflow.
func (Decimal[V, U]) Units ¶
func (d Decimal[V, U]) Units() U
Units returns the scaled integer by value. uint256.Int is an inline four-limb value, so the returned value owns its storage without allocation.
func (*Decimal[V, U]) UnmarshalCBOR ¶
UnmarshalCBOR implements the fxamacker/cbor Unmarshaler contract. It accepts only RFC 8949 preferred deterministic unsigned encodings and leaves d unchanged on failure. Successful decode clears retained text because CBOR carries numeric units only.
func (*Decimal[V, U]) UnmarshalJSON ¶
UnmarshalJSON parses ordinary quoted decimals directly without a separate escape scan. go-json handles escaped strings and non-string JSON syntax.
func (*Decimal[V, U]) UnmarshalText ¶
type Error ¶
type Error string
Error is an allocation-free, comparable package error.
Exported errors are typed string constants. They work with errors.Is when returned directly or wrapped with fmt.Errorf and %w.
const ( ErrSyntax Error = "sailfish: invalid syntax" ErrRange Error = "sailfish: value does not fit unit type" ErrPrecision Error = "sailfish: too many fractional digits" ErrScale Error = "sailfish: scale is unsupported by unit type" ErrOverflow Error = "sailfish: addition overflow" ErrUnderflow Error = "sailfish: subtraction underflow" ErrNilDestination Error = "sailfish: nil destination" ErrCBORSyntax Error = "sailfish: invalid CBOR" ErrCBORNonDeterministic Error = "sailfish: non-deterministic CBOR" )
type Fraction0 ¶
type Fraction0 struct{}
Fraction0 through Fraction20 are zero-sized fractional-scale policies. Scale is independent from the scaled-integer backend: callers choose both the number of digits after the point and the required numeric capacity.
func (Fraction0) NotionScale ¶
type Fraction10 ¶
type Fraction10 struct{}
func (Fraction10) NotionScale ¶
func (Fraction10) NotionScale() Notion
type Fraction11 ¶
type Fraction11 struct{}
func (Fraction11) NotionScale ¶
func (Fraction11) NotionScale() Notion
type Fraction12 ¶
type Fraction12 struct{}
func (Fraction12) NotionScale ¶
func (Fraction12) NotionScale() Notion
type Fraction13 ¶
type Fraction13 struct{}
func (Fraction13) NotionScale ¶
func (Fraction13) NotionScale() Notion
type Fraction14 ¶
type Fraction14 struct{}
func (Fraction14) NotionScale ¶
func (Fraction14) NotionScale() Notion
type Fraction15 ¶
type Fraction15 struct{}
func (Fraction15) NotionScale ¶
func (Fraction15) NotionScale() Notion
type Fraction16 ¶
type Fraction16 struct{}
func (Fraction16) NotionScale ¶
func (Fraction16) NotionScale() Notion
type Fraction17 ¶
type Fraction17 struct{}
func (Fraction17) NotionScale ¶
func (Fraction17) NotionScale() Notion
type Fraction18 ¶
type Fraction18 struct{}
func (Fraction18) NotionScale ¶
func (Fraction18) NotionScale() Notion
type Fraction19 ¶
type Fraction19 struct{}
func (Fraction19) NotionScale ¶
func (Fraction19) NotionScale() Notion
type Fraction20 ¶
type Fraction20 struct{}
func (Fraction20) NotionScale ¶
func (Fraction20) NotionScale() Notion
type NativeUnit ¶
type NativeUnit interface {
comparable
uint8 | uint16 | uint32 | uint64
}
NativeUnit is the subset backed by Go's native unsigned integer types.
type PriceUint8 ¶
type PriceUint8[S VenueScale] struct { Uint8Units }
PriceUint8 through PriceUint256 combine price identity and a fractional scale with an explicit scaled-integer backend. Backend width controls range; it is not inferred from fractional scale.
func (PriceUint8[S]) NotionScale ¶
func (PriceUint8[S]) NotionScale() Notion
type PriceUint16 ¶
type PriceUint16[S VenueScale] struct { Uint16Units }
func (PriceUint16[S]) NotionScale ¶
func (PriceUint16[S]) NotionScale() Notion
type PriceUint32 ¶
type PriceUint32[S VenueScale] struct { Uint32Units }
func (PriceUint32[S]) NotionScale ¶
func (PriceUint32[S]) NotionScale() Notion
type PriceUint64 ¶
type PriceUint64[S VenueScale] struct { Uint64Units }
func (PriceUint64[S]) NotionScale ¶
func (PriceUint64[S]) NotionScale() Notion
type PriceUint256 ¶
type PriceUint256[S VenueScale] struct { Uint256Units }
func (PriceUint256[S]) NotionScale ¶
func (PriceUint256[S]) NotionScale() Notion
type Uint8Units ¶
type Uint8Units struct{}
Uint8Units, Uint16Units, and Uint32Units are zero-sized unit providers. Embed one in a custom venue, or use the PriceUint* and AmountUint* formats.
type Uint16Units ¶
type Uint16Units struct{}
type Uint32Units ¶
type Uint32Units struct{}
type Uint64Units ¶
type Uint64Units struct{}
Uint64Units is a zero-sized unit provider. Embed it in a venue type.
type Uint256Codec ¶
type Uint256Codec struct {
// contains filtered or unexported fields
}
Uint256Codec is the runtime-scale hot-path codec for scaled uint256 units.
Use Codec with a Venue when compile-time venue identity is required. Use Uint256Codec at boundaries where trusted metadata resolves the scale at runtime, such as CEX symbol decoding. Its methods avoid generic venue dispatch and return Error directly so successful and rejected parses remain allocation-free.
The zero value is a valid scale-0 codec. Scale is stored directly in one byte so repeated boundary operations do not decode constructor metadata.
Example ¶
package main
import (
"fmt"
"github.com/JekaMas/sailfish"
"github.com/holiman/uint256"
)
func main() {
codec, err := sailfish.NewUint256Codec(18)
if err != nil {
fmt.Println(err)
return
}
var units uint256.Int
if parseErr := codec.ParseInto("1.250000000000000000", &units); parseErr != "" {
fmt.Println(parseErr)
return
}
fmt.Println(string(codec.AppendTo(nil, units)))
}
Output: 1.250000000000000000
func NewUint256Codec ¶
func NewUint256Codec(scale Notion) (Uint256Codec, error)
NewUint256Codec validates scale once for repeated uint256 operations.
func (Uint256Codec) AppendCBOR ¶
func (c Uint256Codec) AppendCBOR(dst []byte, units uint256.Int) []byte
AppendCBOR appends the preferred deterministic CBOR encoding for units. It allocates only when dst has insufficient capacity.
func (Uint256Codec) AppendTo ¶
func (c Uint256Codec) AppendTo(dst []byte, units uint256.Int) []byte
AppendTo appends canonical fixed-scale text for units. It allocates only when dst has insufficient capacity.
func (Uint256Codec) CBORLen ¶
func (c Uint256Codec) CBORLen(units uint256.Int) int
CBORLen returns the exact preferred deterministic CBOR size for units.
func (Uint256Codec) Len ¶
func (c Uint256Codec) Len(units uint256.Int) int
Len returns the exact canonical text length for units.
func (Uint256Codec) MaxIntegerDigits ¶
func (c Uint256Codec) MaxIntegerDigits() int
MaxIntegerDigits reports the maximum integer-part digit count at this scale.
func (Uint256Codec) Parse ¶
func (c Uint256Codec) Parse(input string) (uint256.Int, Error)
Parse parses a strict non-negative decimal string into scaled units.
func (Uint256Codec) ParseBytes ¶
func (c Uint256Codec) ParseBytes(input []byte) (uint256.Int, Error)
ParseBytes parses input without converting it to a string.
func (Uint256Codec) ParseBytesInto ¶
func (c Uint256Codec) ParseBytesInto(input []byte, dst *uint256.Int) Error
ParseBytesInto parses input into dst without converting it to a string. It leaves dst unchanged on failure.
func (Uint256Codec) ParseCBOR ¶
func (c Uint256Codec) ParseCBOR(raw []byte) (uint256.Int, Error)
ParseCBOR decodes preferred deterministic CBOR into scaled units.
func (Uint256Codec) ParseCBORFirst ¶
ParseCBORFirst decodes one preferred deterministic CBOR uint256 from the start of raw and returns the unconsumed suffix. It is intended for manual positional-array decoders that keep aggregate decoding allocation-free.
func (Uint256Codec) ParseCBORFirstInto ¶
ParseCBORFirstInto decodes one preferred deterministic CBOR uint256 into dst and returns the unconsumed suffix. It leaves dst unchanged on failure.
func (Uint256Codec) ParseCBORInto ¶
func (c Uint256Codec) ParseCBORInto(raw []byte, dst *uint256.Int) Error
ParseCBORInto decodes preferred deterministic CBOR into dst. It leaves dst unchanged on failure.
func (Uint256Codec) ParseInto ¶
func (c Uint256Codec) ParseInto(input string, dst *uint256.Int) Error
ParseInto parses input into dst. It leaves dst unchanged on failure.
func (Uint256Codec) Scale ¶
func (c Uint256Codec) Scale() Notion
Scale returns the configured number of fractional decimal digits.
type Uint256Units ¶
type Uint256Units struct{}
Uint256Units is a zero-sized unit provider. Embed it in a venue type.
type Venue ¶
type Venue[U Unit] interface { VenueScale // contains filtered or unexported methods }
Venue binds a fixed scale to one unit backend.
A custom venue is normally a zero-sized type. Prefer PriceUint* and AmountUint* when their semantic distinction applies:
type QuoteFraction5 struct{ sailfish.Uint64Units }
func (QuoteFraction5) NotionScale() sailfish.Notion { return 5 }
type VenueScale ¶
type VenueScale interface {
NotionScale() Notion
}
VenueScale supplies a fixed decimal scale. Implement it on a zero-sized value type with a value receiver.