Skip to main content

Module wire

Module wire 

Source
Expand description

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

Solana account data buffers have alignment 1. Casting a *const u8 to *const u64 causes undefined behavior when the pointer is not 8-byte aligned. Every framework that does zero-copy must solve this.

Quasar solves it with PodU64([u8; 8]) – wrapping arithmetic by default and implicit conversion. Hopper takes a different approach:

  • Explicit endianness: Types are named LeU64 (“little-endian u64”), making the wire representation unambiguous at every call site.
  • Checked arithmetic by default: +, -, * return Option via checked_add etc. This is safer than wrapping overflow silently (Quasar’s default) and matches Rust’s principled stance on UB.
  • const fn constructors: LeU64::new(42) works in const context, enabling compile-time constants for discriminators, seeds, etc.
  • Projectable: All wire types implement Projectable, so you can use project::<LeU64>(account, offset, None) to read them directly from account data without alignment issues.

These types are the foundation for safe zero-copy account structs. Any #[repr(C)] struct composed entirely of wire types + [u8; N] arrays is alignment-1-safe and can be projected from account data.

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.