Skip to main content

Crate xdr_common

Crate xdr_common 

Source
Expand description

Common types for XDR (External Data Representation) encoding and decoding.

This crate provides length-constrained collection types for XDR serialization:

  • VecM - Generic vector with maximum length constraint
  • BytesM - Byte vector with maximum length constraint
  • StringM - String (as bytes) with maximum length constraint

§Features

  • alloc - Enables heap allocation support (required for most functionality)
  • std - Enables standard library support (implies alloc)
  • serde - Enables serde serialization/deserialization (implies alloc)
  • schemars - Enables JSON Schema generation via schemars (implies alloc)

§no_std Support

This crate is no_std by default. Enable the alloc feature for heap-allocated collections, or std for full standard library support.

§Examples

ⓘ
use xdr_common::{VecM, BytesM, StringM};

// Create a vector with max length of 10
let v: VecM<u32, 10> = vec![1, 2, 3].try_into()?;

// Create a byte array with max length of 100
let b: BytesM<100> = b"hello".as_slice().try_into()?;

// Create a string with max length of 50
let s: StringM<50> = "world".try_into()?;

Modules§

serde_hexserde
Serde adapter for fixed-size byte arrays encoded as hexadecimal strings.

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_BYTESalloc
The maximum number of bytes a decoder will preallocate for a variable-length collection before reading its elements.

Traits§

StaticIfNoAllocalloc
Helper trait bound on VecM elements that requires 'static only in no-alloc builds.

Functions§

box_as_refalloc
Borrows the value behind a Box in a const context.

Type Aliases§

Box
A pointer type that uniquely owns a heap allocation of type T.
Vec
A contiguous growable array type.