Repository navigation
Small fixes - #336
Small fixes#336
Conversation
… match This makes it a compiler error if we forget to compare a type. `rustfmt` has been disabled for this function as it does a poor job of formatting this code.
|
|
||
| fn encode_variable<W: Write>(mut z: u64, mut writer: W) -> AvroResult<usize> { | ||
| fn encode_variable<W: Write>(n: i64, mut writer: W) -> AvroResult<usize> { | ||
| let mut z = (((n << 1) ^ (n >> 63)) as u64).to_le(); |
There was a problem hiding this comment.
This is to be complaint with a double is written as 8 bytes. The double is converted into a 64-bit integer using a method equivalent to Java’s [doubleToRawLongBits](https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#doubleToRawLongBits-double-) and then encoded in little-endian format. from the specification, right ?
There was a problem hiding this comment.
No, encode_variable is purely used for zigzag encoding int and long types.
The bit twiddling is to do the zigzag, while the remainder of the function is for doing the varint encoding.
I've moved the bit twiddling back to zig_i64, and documented why they are two different functions
791fcb5 to
39f5b69
Compare
Changes suggested by `martin-g`
39f5b69 to
ea6eb72
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR contains several small improvements and fixes encountered while working on async support, including documentation additions, code refactoring, and bug fixes in schema comparison logic.
- Added documentation comments to varint encoding/decoding functions
- Refactored schema equality comparison from macros to exhaustive match statements
- Fixed bugs in schema comparison (Decimal inner schema, Array/Map recursion, Record field names)
- Improved API flexibility with generic iterators
- Fixed documentation comments for schema structs
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| avro/src/util.rs | Added documentation for varint encoding functions and refactored variable naming. Contains critical bugs with endianness conversion. |
| avro/src/schema_equality.rs | Refactored from macro-based to match-based comparison, fixing several comparison bugs (Decimal inner, Array/Map recursion, field names) and removing unreachable error logging. |
| avro/src/schema.rs | Fixed copy-paste errors in documentation comments and improved function signature to use generic iterators. |
| avro/src/reader.rs | Updated function call to work with new generic iterator signature. |
| avro/src/encode.rs | Added documentation for the encode_bytes function. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Ensure the number is little endian for the varint encoding (no-op on LE systems) | ||
| zigzagged = zigzagged.to_le(); |
There was a problem hiding this comment.
The addition of to_le() here is incorrect and will break varint encoding on big-endian systems.
Varint encoding is endian-independent - it encodes numbers by extracting 7-bit chunks from least to most significant, which works correctly regardless of the system's endianness. The original code was correct.
On a big-endian system, calling to_le() would byte-swap the value before encoding, producing incorrect output. On little-endian systems, it's a no-op but adds unnecessary operations.
Recommendation: Remove the to_le() call and the associated comment on line 112.
| // Ensure the number is little endian for the varint encoding (no-op on LE systems) | |
| zigzagged = zigzagged.to_le(); |
There was a problem hiding this comment.
I don't think this is correct. Encoding a varint on BE and then decoding that on LE should give the same result (but the specification doesn't actually specify which endianness to use).
| } | ||
|
|
||
| Ok(i) | ||
| Ok(u64::from_le(i)) |
There was a problem hiding this comment.
The addition of from_le() here is incorrect and will break varint decoding on big-endian systems.
The varint decoding algorithm already correctly reconstructs the value by shifting and ORing 7-bit chunks, which is endian-independent. Calling from_le() assumes the result is in little-endian format, which it isn't - it's just the correctly reconstructed value.
On a big-endian system, this would byte-swap the correctly decoded value, producing incorrect results. On little-endian systems, it's a no-op but adds unnecessary operations.
Recommendation: Remove the from_le() call and keep it as Ok(i).
| Ok(u64::from_le(i)) | |
| Ok(i) |
These are some small things I ran into when working on async support.