pub trait FieldDecoder: Sized {
type Buffer: AsMut<[u8]> + AsRef<[u8]>;
// Required methods
fn empty_buffer() -> Self::Buffer;
fn decode(
buf: Self::Buffer,
bytes_written: usize,
) -> Result<Self, DecodeError>;
}Expand description
Decodes a typed value from the raw bytes a host function wrote.
Required Associated Types§
Required Methods§
Sourcefn empty_buffer() -> Self::Buffer
fn empty_buffer() -> Self::Buffer
Returns a zero-initialized buffer of this type’s Buffer size.
Sourcefn decode(buf: Self::Buffer, bytes_written: usize) -> Result<Self, DecodeError>
fn decode(buf: Self::Buffer, bytes_written: usize) -> Result<Self, DecodeError>
Decodes Self from the full Buffer (as written by the host, then zero-padded to the
buffer’s size), given bytes_written — the number of bytes the host actually wrote.
bytes_written carries the length that a &[u8] slice would otherwise bundle inside its
fat pointer — passing the whole buffer plus bytes_written lets fixed-layout types (e.g.
Amount) read the padded buffer in place, with no re-slice or re-copy.
Most fixed-size types require the host to have written exactly Buffer’s length and can
then be built with a plain From<Buffer> — for those, implement this as
decode_exact(*buf, bytes_written) (see [decode_exact]). Types with different semantics
— e.g. Amount, where a shorter write is legitimate (XRP is 8 bytes, MPT 33, of a 48-byte
buffer) and the variant is determined by the leading flag bits rather than the byte count
— write a bespoke body instead.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl FieldDecoder for i32
impl FieldDecoder for i32
Source§impl FieldDecoder for u8
impl FieldDecoder for u8
Source§impl FieldDecoder for u16
impl FieldDecoder for u16
Source§impl FieldDecoder for u32
impl FieldDecoder for u32
Source§impl FieldDecoder for u64
impl FieldDecoder for u64
Implementors§
Source§impl FieldDecoder for AccountID
FieldDecoder for XRPL account identifiers: decodes a 20-byte buffer into an AccountID,
failing if the host wrote a different number of bytes.
impl FieldDecoder for AccountID
FieldDecoder for XRPL account identifiers: decodes a 20-byte buffer into an AccountID,
failing if the host wrote a different number of bytes.
Source§impl FieldDecoder for Amount
FieldDecoder for XRPL amount values. The host writes a variable number of bytes into the
fixed AMOUNT_SIZE buffer — 8 for XRP, 33 for MPT, 48 for IOU — with the remainder left as
empty_buffer()’s zero-padding, which is exactly the shape Amount::from_bytes wants, so it
reads the buffer in place with no re-slice or re-copy.
impl FieldDecoder for Amount
FieldDecoder for XRPL amount values. The host writes a variable number of bytes into the
fixed AMOUNT_SIZE buffer — 8 for XRP, 33 for MPT, 48 for IOU — with the remainder left as
empty_buffer()’s zero-padding, which is exactly the shape Amount::from_bytes wants, so it
reads the buffer in place with no re-slice or re-copy.
Source§impl FieldDecoder for Currency
FieldDecoder for XRPL currency codes: decodes a 20-byte buffer into a Currency, failing if
the host wrote a different number of bytes.
impl FieldDecoder for Currency
FieldDecoder for XRPL currency codes: decodes a 20-byte buffer into a Currency, failing if
the host wrote a different number of bytes.
Source§impl FieldDecoder for Issue
FieldDecoder for XRPL issues. The host writes a variable number of bytes into the fixed
40-byte buffer — 20 for XRP, 24 for MPT, 40 for IOU — and the variant is detected from
bytes_written (see Issue::from_buffer); a count that matches none of those is a decode
error.
impl FieldDecoder for Issue
FieldDecoder for XRPL issues. The host writes a variable number of bytes into the fixed
40-byte buffer — 20 for XRP, 24 for MPT, 40 for IOU — and the variant is detected from
bytes_written (see Issue::from_buffer); a count that matches none of those is a decode
error.
Source§impl FieldDecoder for Number
FieldDecoder for XRPL STNumber fields: decodes the 12-byte serialized value, failing if the
host wrote a different number of bytes.
impl FieldDecoder for Number
FieldDecoder for XRPL STNumber fields: decodes the 12-byte serialized value, failing if the
host wrote a different number of bytes.
The bytes are taken as-is rather than routed back through float_from_stnumber: the host’s float
representation is the STNumber serialization (rippled’s WASM host builds it with
STNumber::add), so a value read off a transaction or ledger entry is already a canonical
host-produced Number.
Source§impl FieldDecoder for TransactionType
FieldDecoder for XRPL transaction types: decodes a 2-byte buffer via the existing
(infallible) i16 mapping, failing only if the host wrote a different number of bytes.
impl FieldDecoder for TransactionType
FieldDecoder for XRPL transaction types: decodes a 2-byte buffer via the existing
(infallible) i16 mapping, failing only if the host wrote a different number of bytes.
Source§impl<const N: usize> FieldDecoder for Blob<N>
FieldDecoder for any Blob<N>: copies whatever bytes the host wrote (at most N) into a
Blob<N>, recording the actual length. Unlike fixed-size types, this never fails — blobs are
variable-length by design.
impl<const N: usize> FieldDecoder for Blob<N>
FieldDecoder for any Blob<N>: copies whatever bytes the host wrote (at most N) into a
Blob<N>, recording the actual length. Unlike fixed-size types, this never fails — blobs are
variable-length by design.