Expand description
§XDRS (XDR Serialization)
This crate provides:
-
Traits
ReadXDRandWriteXDR, for converting between Rust values and the XDR data model. -
Trait
EncodesAs, for declaring that a type encodes to the same bytes as some XDR type, so it can be passed where that type is expected. -
Types
ChunkedBytesandChunkedVec, which encode data held in separate chunks like oneBytesMorVecM, without first copying the chunks together. -
Traits
ReaderandWriter, for converting between the XDR data model and some serialization format. -
Trait
WriterUnchecked, an infallible, unsafe counterpart toWriterwith no runtime checks, for code-size-sensitive targets.
The library is no_std, but a few extra things can be
enabled with feature alloc.
§Features
This crate supports several optional features:
§Deserialization options
permissive: When reading CXS data, don’t reject (as is the default) integers using non-minimal-size encoding. Also, when reading TXS data, do not reject non-zero padding bytes. This includes the upper two bytes of a 4-byte wire integer decoded asi16oru16, which are treated as padding; in permissive mode these bytes are allowed to be non-zero and the value is truncated to 16 bits.
§Allocation
-
alloc: Enables allocation-based interfaces:Vec<u8>andVec<T>implementations ofReadXDRandWriteXDRStringimplementations ofReadXDRandWriteXDRBufWritertypes incxsandtxsmodules for growable buffersencode()functions that return ownedVec<u8>
xdr_commonowned types requirealloc. Without theallocfeature,BytesM<MAX>,StringM<MAX>, andVecM<T, MAX>compile but theirReadXDRimplementations panic unconditionally at runtime. Do not call the decode APIs for these types in a no-alloc build.
§Extended types
int128: Enables convenient extensions to the XDR specification: support fori128andu128. These types are encoded as two 64-bit integers (high bits and low bits).
§Optional dependencies
-
derive: Enables derive macros from thexdr-derivecrate: -
repr(requiresalloc): Enables thexdr-reprcrate for XDR specification representation. Provides types and traits for describing XDR type definitions. -
heapless: Enables support for types from theheaplesspackage. -
ns(impliesrepr): Enables namespace support inxdr-reprfor C++-like scoping of XDR definitions.
Re-exports§
pub use serialize::reader::ReadError;pub use serialize::reader::ReadResult;pub use serialize::writer::WriteError;pub use serialize::writer::WriteResult;pub use xdr_repr;reprpub use chunked::*;pub use discrim::*;pub use encodes_as::*;pub use read_xdr::*;pub use write_xdr::*;pub use serialize::reader::*;pub use serialize::writer::*;pub use serialize::writer_unchecked::*;
Modules§
- chunked
- Variable-length data held as separate chunks.
- cxs
- CXS (Compact XDR Serialization)
- discrim
- The
XDRDiscriminanttrait, for types that act as XDR union discriminants. - encodes_
as - Declaring that one type serializes like another.
- read_
xdr - Reading XDR data into Rust types.
- serde_
hex serde - Serde adapter for fixed-size byte arrays encoded as hexadecimal strings.
- serialize
- An interface for serializing XDR primitives, which certain formats may implement. The formats must:
- txs
- TXS (Traditional XDR Serialization) implementation.
- write_
xdr - Writing Rust values as XDR data.
Structs§
- BytesM
- A byte vector with a maximum length constraint.
- StringM
- A string type that stores arbitrary bytes with a maximum length constraint.
- VecM
- A vector with a maximum length constraint.
Enums§
- Error
- Errors that can occur when working with XDR types.
Constants§
- MAX_
PREALLOC_ BYTES alloc - The maximum number of bytes a decoder will preallocate for a variable-length collection before reading its elements.
Traits§
- Static
IfNo Alloc alloc - Helper trait bound on
VecMelements that requires'staticonly in no-allocbuilds.
Functions§
- box_
as_ ref alloc - Borrows the value behind a
Boxin aconstcontext.
Type Aliases§
- Box
alloc - A pointer type that uniquely owns a heap allocation of type
T. - Vec
alloc - A contiguous growable array type.
Derive Macros§
- Const
WriteXDR derive - Derives const-compatible XDR encoding methods for compile-time use.
- ConstXDR
Size derive - Derives worst-case XDR size bounds as
cxs::ConstMaxSizeandtxs::ConstMaxSizetrait implementations. - ReadXDR
derive - Derives the
ReadXDRtrait for a struct or enum. - WriteXDR
derive - Derives the
WriteXDRtrait for a struct or enum. - XDR
deriveandrepr - Derives the
XDRandHasTypeDeftraits.