RustToMetal opened a new pull request, #4306: URL: https://github.com/apache/iggy/pull/4306
The wire protocol checksums every batch with XXH3-64 and routes keyed messages to partitions with XXH32, so the SDK needs both hashes before it can encode a single send request. Both are implemented natively in Swift rather than bound to a C library, and both are pinned to the Rust crates the server uses through a golden fixture generated from them. Second of nine stacked PRs for the Swift SDK; builds on #4190. ## Which issue does this PR address? Relates to #4001 ## Rationale A hash that differs from the server's by a single bit corrupts every batch checksum or sends keyed messages to the wrong partition, and neither failure shows up in a unit test that only compares the Swift code against itself. The fixture makes the Rust crates the reference: the Swift tests read hash outputs, the full error-code table, and request and response bytes that were produced by the workspace crates and compare byte for byte. ## What changed? `XXH3.swift` and `XXH32.swift` implement the two hashes over `ArraySlice<UInt8>` with the same seeds and secret the `twox-hash` crate uses, so the batch checksum and the partitioning key match the server. `Tools/golden-vectors` is a standalone Rust binary (not a workspace member, its `Cargo.lock` is ignored) that depends on the workspace crates by path and dumps `Tests/IggyTests/Fixtures/golden.json`: 318 XXH3-64 and 318 XXH32 vectors over a range of input lengths, the 240-entry error table, the protocol version, and 117 request and response vectors that the protocol PR consumes next. Hash and error tables are keyed maps so each entry is one line and a regenerated fixture diffs cleanly. `GoldenFixture` loads the fixture as a test resource, `HashTests` compares every vector, and `ErrorCodeTests` gains the check that the Swift table matches the dumped one, alongside the hard-coded table test from the first PR. The `IggyErrorCode` header comment now points at the generator, and `.typos.toml` excludes the fixture since its hex payloads trip the spell checker. ## Local Execution - Passed: `swift build -Xswiftc -warnings-as-errors`, `swift test` (17 tests), `swift format lint --strict`, hawkeye license check, fixture regenerated with `cargo run --manifest-path foreign/swift/Tools/golden-vectors/Cargo.toml` and identical to the committed one - Pre-commit: `prek run --from-ref upstream/master --to-ref HEAD` passed (license headers, version consistency, trailing whitespace and newline, binary artifacts, typos, taplo, cargo fmt, cargo sort) ## AI Usage 1. **Which tools?** Claude Code (Claude). 2. **Scope of usage?** The hash implementations, the generator, and the tests were drafted with it from the `twox-hash` crate and `core/binary_protocol` as the reference, reviewed and directed by me. 3. **How did you verify the generated code works correctly?** Every hash vector, error code, and wire vector in the fixture comes from the Rust crates and the Swift tests compare against them byte for byte. The full chain was also run end to end against a real `iggy-server`, plain and over TLS. 4. **Can you explain every line of the code if asked?** Yes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
