endian
The endian module provides support functions for converting the byte encoding ("endianness") of integers. The following abbreviations are used throughout the module:
- be - big endian; most significant byte first
- le - little endian; least significant byte first
- h - the endianness of the host system
- n - the endianness of the network (big endian)
Index
Types
type endian = struct {
getu16: *fn(buf: []u8) u16,
putu16: *fn(buf: []u8, in: u16) void,
getu32: *fn(buf: []u8) u32,
putu32: *fn(buf: []u8, in: u32) void,
getu64: *fn(buf: []u8) u64,
putu64: *fn(buf: []u8, in: u64) void,
};
Globals
const big: endian;
const host: *endian;
const little: endian;
Functions
fn begetu16(buf: []u8) u16;
fn begetu32(buf: []u8) u32;
fn begetu64(buf: []u8) u64;
fn beputu16(buf: []u8, in: u16) void;
fn beputu32(buf: []u8, in: u32) void;
fn beputu64(buf: []u8, in: u64) void;
fn htonu16(in: u16) u16;
fn htonu32(in: u32) u32;
fn htonu64(in: u64) u64;
fn legetu16(buf: []u8) u16;
fn legetu32(buf: []u8) u32;
fn legetu64(buf: []u8) u64;
fn leputu16(buf: []u8, in: u16) void;
fn leputu32(buf: []u8, in: u32) void;
fn leputu64(buf: []u8, in: u64) void;
fn ntohu16(in: u16) u16;
fn ntohu32(in: u32) u32;
fn ntohu64(in: u64) u64;
Types
type endian
type endian = struct {
getu16: *fn(buf: []u8) u16,
putu16: *fn(buf: []u8, in: u16) void,
getu32: *fn(buf: []u8) u32,
putu32: *fn(buf: []u8, in: u32) void,
getu64: *fn(buf: []u8) u64,
putu64: *fn(buf: []u8, in: u64) void,
};
The set of functions used for endian-aware encoding.
Globals
let big
const big: endian;
Big endian; MSB first.
let host
const host: *endian;
The endian functions which map to the host architecture.
let little
const little: endian;
Little endian; LSB first.
Functions
fn begetu16
fn begetu16(buf: []u8) u16;
Reads a u16 from a buffer in big-endian order.
fn begetu32
fn begetu32(buf: []u8) u32;
Reads a u32 from a buffer in big-endian order.
fn begetu64
fn begetu64(buf: []u8) u64;
Reads a u64 from a buffer in big-endian order.
fn beputu16
fn beputu16(buf: []u8, in: u16) void;
Writes a u16 into a buffer in big-endian order.
fn beputu32
fn beputu32(buf: []u8, in: u32) void;
Writes a u32 into a buffer in big-endian order.
fn beputu64
fn beputu64(buf: []u8, in: u64) void;
Writes a u64 into a buffer in big-endian order.
fn htonu16
fn htonu16(in: u16) u16;
Converts a u16 from host order to network order.
fn htonu32
fn htonu32(in: u32) u32;
Converts a u32 from host order to network order.
fn htonu64
fn htonu64(in: u64) u64;
Converts a u64 from host order to network order.
fn legetu16
fn legetu16(buf: []u8) u16;
Reads a u16 from a buffer in little-endian order.
fn legetu32
fn legetu32(buf: []u8) u32;
Reads a u32 from a buffer in little-endian order.
fn legetu64
fn legetu64(buf: []u8) u64;
Reads a u64 from a buffer in little-endian order.
fn leputu16
fn leputu16(buf: []u8, in: u16) void;
Writes a u16 into a buffer in little-endian order.
fn leputu32
fn leputu32(buf: []u8, in: u32) void;
Writes a u32 into a buffer in little-endian order.
fn leputu64
fn leputu64(buf: []u8, in: u64) void;
Writes a u64 into a buffer in little-endian order.
fn ntohu16
fn ntohu16(in: u16) u16;
Converts a u16 from network order to host order.
fn ntohu32
fn ntohu32(in: u32) u32;
Converts a u32 from network order to host order.
fn ntohu64
fn ntohu64(in: u64) u64;
Converts a u64 from network order to host order.