add ltk_inibin: INIBIN v1/v2 parser and writer with bucket API#121
add ltk_inibin: INIBIN v1/v2 parser and writer with bucket API#121FrogCsLoL wants to merge 3 commits intoLeagueToolkit:mainfrom
Conversation
Adds ltk_inibin crate for parsing and writing inibin files (.inibin, .troybin, .cfgbin — all the same format). Modeled after the C# reference implementation with a bucket representation: - InibinFile: IndexMap<InibinFlags, InibinSet> — sets grouped by type - InibinSet: IndexMap<u32, InibinValue> — hash-keyed typed bucket - InibinValue: granular typed enum (I32, F32, Bool, String, Vec2/3/4, etc) - Public API: get/get_from/contains/add_value/remove/iter - Reader: v1 + v2 binary support - Writer: v2 binary serialization - No hash resolution — that is a separate concern Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cc3d18c to
e8410ca
Compare
| UnknownVersion(u8), | ||
|
|
||
| #[error("Cannot write v1 (old format) entries to binary — convert to v2 storage types first")] | ||
| V1WriteNotSupported, |
There was a problem hiding this comment.
This is an obsolete error as we don't really care about v1 writing. We should write "v2" by default.
| } | ||
|
|
||
| /// Write an [`InibinFile`] to binary v2 format. | ||
| pub fn write<W: std::io::Write>(w: &mut W, file: &InibinFile) -> Result<(), InibinError> { |
There was a problem hiding this comment.
This function should be implemented directly on top of an Inibin struct.
Additionally it would be good to rename InibinFile to just Inibin for brewity.
There was a problem hiding this comment.
All structs should have the Inibin prefix removed, besides the actual Inibin struct
| #[derive(Debug, Clone)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct InibinFile { | ||
| version: u8, |
There was a problem hiding this comment.
We don't really care about the version of the source file when representing it in memory.
|
Can you please remove Claude as a contributor in the git commits for the PR |
|
I'll work on some changes to this branch as well so we can merge it earlier. |
|
There is also gonna be an issue of how to represent the values in a sane way from a public API. The API we can provide will be something similar to the current meta/ritobin crates more or less. |
|
We also need to add the SDBM hash into the existing |
|
|
||
| // ── V1 reader ─────────────────────────────────────────────────────────── | ||
|
|
||
| fn sanitize_str(s: &str) -> InibinValue { |
There was a problem hiding this comment.
this should probably just be a FromStr impl on InibinValue
|
|
||
| let mut properties = IndexMap::with_capacity(num); | ||
| for &key in &keys { | ||
| let value = match flags { |
There was a problem hiding this comment.
can this be extracted to a method like from_reader on InibinValue?
|
|
||
| fn read_strings<R: Read>(r: &mut R, strings_length: usize) -> Result<InibinSet, InibinError> { | ||
| let num = r.read_u16::<LE>()? as usize; | ||
| let mut keys = Vec::with_capacity(num); |
There was a problem hiding this comment.
can you change these to iterators as well
| } | ||
|
|
||
| /// Read an inibin binary from a byte slice. | ||
| pub fn from_slice(data: &[u8]) -> Result<InibinFile, InibinError> { |
There was a problem hiding this comment.
this should be a from_reader method on InibinFile, with an additional from_slice helper method
| } | ||
|
|
||
| /// Get a reference to a set by type. | ||
| pub fn set(&self, flags: InibinFlags) -> Option<&InibinSet> { |
There was a problem hiding this comment.
@Crauzer thoughts on renaming Sets to Sections, set makes methods like these confusing
There was a problem hiding this comment.
Yeah that seems like a good idea
| /// | ||
| /// Sets with [`InibinFlags::OldFormat`] are skipped — v1 is read-only. | ||
| /// Returns [`InibinError::V1WriteNotSupported`] if all sets are old format. | ||
| pub fn write<W: Write>(w: &mut W, file: &InibinFile) -> Result<(), InibinError> { |
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| #[repr(u8)] | ||
| pub enum InibinFlags { |
There was a problem hiding this comment.
this seems like it should be named ValueKind instead, Flags implies bitflags
Co-authored-by: Alan Panayotov <alanpanayotov@gmail.com>
Co-authored-by: Alan Panayotov <alanpanayotov@gmail.com>
Summary
ltk_inibincrate for parsing and writing inibin files (.inibin,.troybin,.cfgbin— identical format)Changes from previous PR (#120)
Reworked per review feedback: