Skip to main content

Module binary

Module binary 

Source
Expand description

Shared binary utilities and lightweight format codec traits. Shared binary helpers and lightweight codec traits.

This module is the low-level utility layer used across format modules for:

  • checked primitive reads (u16, u32, u64, f32, fourcc),
  • bounds validation for offset/size pairs,
  • narrow encode/decode traits used for composition.

§Layering Overview

format module (erf/rim/gff/tlk/twoda)
  -> format-specific error mapping
  -> binary::{read_*, write_*, check_*}
  -> raw byte slice / writer

Enums§

BinaryLayoutError
Shared binary layout/read error used by low-level format helpers.

Traits§

DecodeBinary
Minimal decode trait for binary format value types.
EncodeBinary
Minimal encode trait for binary format value types.

Functions§

check_range_in_bounds
Validates that [offset, offset + size) is within total_len.
check_slice_in_bounds
Validates that [offset, offset + size) is within bytes.
checked_to_usize
Converts a 32-bit offset/count value to usize with overflow checking.
expect_any_fourcc
Validates that a parsed fourcc matches one of expected.
expect_fourcc
Validates that a parsed fourcc exactly matches expected.
matches_resource_key
Returns true when two resource keys match by type and ASCII case-insensitive resource name.
read_c_string
Reads a variable-length null-terminated string from a byte buffer.
read_f32
Reads little-endian f32 at offset.
read_fixed_c_string
Reads a null-terminated string from a fixed-size field in a byte buffer.
read_fourcc
Reads a 4-byte tag at offset.
read_i32
Reads little-endian i32 at offset.
read_u8
Reads a single byte at offset.
read_u16
Reads little-endian u16 at offset.
read_u32
Reads little-endian u32 at offset.
read_u64
Reads little-endian u64 at offset.
write_cp1252
Encodes text as Windows-1252 and writes it to writer.
write_f32
Writes little-endian f32.
write_fixed_c_string
Writes a null-terminated string into a fixed-size field, zero-padded.
write_fourcc
Writes a 4-byte tag.
write_i32
Writes little-endian i32.
write_u8
Writes a single byte.
write_u16
Writes little-endian u16.
write_u32
Writes little-endian u32.
write_u64
Writes little-endian u64.