///|
/// Byte order inferred from the four MO magic bytes.
/// Example: `file.header.endianness`.
#derive(Eq, @debug.Debug)
pub enum Endianness {
Little
Big
}
///|
/// Validated revision, entry count and table coordinates in bytes from the file start.
/// Example: `file.header.num_strings`.
#derive(Eq, @debug.Debug)
pub struct MoHeader {
endianness : Endianness
major_revision : UInt32
minor_revision : UInt32
num_strings : UInt32
orig_tab_offset : UInt32
trans_tab_offset : UInt32
hash_tab_size : UInt32
hash_tab_offset : UInt32
}
///|
/// Binary layout, key ordering or encoding failure. Indexed variants identify the offending row.
/// Example: `@mo.parse_mo(bytes) catch { _ => return }`.
#derive(Eq, @debug.Debug)
pub suberror MoError {
TruncatedHeader(actual_len~ : Int32)
InvalidMagic(magic~ : UInt32)
UnsupportedRevision(major~ : UInt32, minor~ : UInt32)
InvalidTableRange(
table~ : String,
offset~ : UInt64,
byte_len~ : UInt64,
file_len~ : Int32,
)
OffsetOutOfBounds(
table~ : String,
index~ : Int32,
offset~ : UInt64,
length~ : UInt64,
file_len~ : Int32,
)
MissingNulTerminator(
table~ : String,
index~ : Int32,
expected_nul_at~ : UInt64,
)
UnsortedOriginalTable(index~ : Int32)
DuplicateOriginalKey(index~ : Int32)
MalformedPluralOriginal(index~ : Int32, nul_count~ : Int32)
UnsupportedCharset(declared~ : String)
InvalidUtf8(table~ : String, index~ : Int32, byte_offset~ : Int32)
}
///|
/// Write the diagnostic representation of Endianness to a logger.
/// Example: `value.to_string()`.
pub impl Show for Endianness with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}
///|
/// Write the diagnostic representation of MoHeader to a logger.
/// Example: `value.to_string()`.
pub impl Show for MoHeader with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}
///|
/// Write the diagnostic representation of MoError to a logger.
/// Example: `value.to_string()`.
pub impl Show for MoError with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}