Skip to main content

Module wire

Module wire 

Source
Expand description

Alignment-safe wire types for zero-copy account data.

Account data APIs expose byte buffers without guaranteeing native-integer alignment. Forming a u64 reference at an unaligned address is undefined behavior. Hopper’s wire integers store little-endian bytes at alignment 1:

  • Explicit endianness: Types are named LeU64 (“little-endian u64”), making the wire representation explicit at call sites.
  • Explicit arithmetic semantics: the checked_*, saturating_*, and wrapping_* inherent methods spell out overflow behavior at the call site. The +/-/* operators mirror Rust’s native integers (panic on overflow in debug, wrap in release). Prefer the explicit methods for on-chain balance math.
  • const fn constructors: LeU64::new(42) works in const context, enabling compile-time constants for discriminators, seeds, etc.
  • Pod + Projectable: All wire types satisfy both the substrate crate::Pod overlay contract and Projectable, so lens::read_field_pod::<LeU64> and project::<LeU64> both work directly on account data without alignment issues.

A #[repr(C)] struct composed entirely of these wire types and alignment-1 byte arrays can satisfy Hopper’s zero-copy overlay contract.

Structs§

LeBool
Boolean wire type. Alignment 1.
LeI16
16-bit signed little-endian integer. Alignment 1.
LeI32
32-bit signed little-endian integer. Alignment 1.
LeI64
64-bit signed little-endian integer. Alignment 1.
LeU16
16-bit unsigned little-endian integer. Alignment 1.
LeU32
32-bit unsigned little-endian integer. Alignment 1.
LeU64
64-bit unsigned little-endian integer. Alignment 1.
LeU128
128-bit unsigned little-endian integer. Alignment 1.