Skip to main content

Module string_table

Module string_table 

Source
Expand description

String table for AION v2 file format

This module implements the null-terminated UTF-8 string table as specified in RFC-0002 Section 5.5. The string table is used to store variable-length text data such as commit messages, audit details, and metadata.

§Format

The string table is a concatenation of null-terminated UTF-8 strings with no padding between entries:

"Genesis version\0Added fraud detection\0Updated rules\0"

§Rules (RFC-0002)

  1. All strings are UTF-8 encoded
  2. Each string terminated with single null byte (0x00)
  3. No padding between strings
  4. Offsets point to first character (not null terminator)
  5. Lengths do NOT include null terminator

§Building String Tables

Use StringTableBuilder to construct string tables during serialization:

use aion_context::string_table::StringTableBuilder;

let mut builder = StringTableBuilder::new();

// Add strings and get their (offset, length)
let (offset1, len1) = builder.add("Genesis version");
let (offset2, len2) = builder.add("Added fraud detection");

// Build final byte array
let bytes = builder.build();

assert_eq!(offset1, 0);
assert_eq!(len1, 15);
assert_eq!(offset2, 16); // "Genesis version\0" = 16 bytes
assert_eq!(len2, 21);

§Parsing String Tables

Use StringTable for zero-copy parsing during deserialization:

use aion_context::string_table::StringTable;

let data = b"Genesis version\0Added fraud detection\0";
let table = StringTable::new(data).unwrap();

// Extract strings by offset/length
let s1 = table.get(0, 15).unwrap();
assert_eq!(s1, "Genesis version");

let s2 = table.get(16, 21).unwrap();
assert_eq!(s2, "Added fraud detection");

§UTF-8 Validation

All strings are validated as UTF-8:

  • During construction (when added to builder)
  • During parsing (when table is created)
  • During extraction (when strings are retrieved)

Invalid UTF-8 sequences return AionError::InvalidUtf8.

Structs§

StringTable
String table for zero-copy parsing of string data
StringTableBuilder
String table builder for constructing string tables during serialization