This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 6629327 Fixes #181 - Do not error if there is nothing to read (#182)
6629327 is described below
commit 66293274d9bada4463715b7ddc4b07da131aaf47
Author: Martin Grigorov <[email protected]>
AuthorDate: Tue Apr 15 17:20:55 2025 +0300
Fixes #181 - Do not error if there is nothing to read (#182)
---
avro/src/reader.rs | 2 +-
avro/tests/schema.rs | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/avro/src/reader.rs b/avro/src/reader.rs
index dd6d681..0830035 100644
--- a/avro/src/reader.rs
+++ b/avro/src/reader.rs
@@ -199,7 +199,7 @@ impl<'r, R: Read> Block<'r, R> {
None => item,
};
- if b_original == block_bytes.len() {
+ if b_original != 0 && b_original == block_bytes.len() {
// from_avro_datum did not consume any bytes, so return an error
to avoid an infinite loop
return Err(Error::ReadBlock);
}
diff --git a/avro/tests/schema.rs b/avro/tests/schema.rs
index 0c90615..c4a06c6 100644
--- a/avro/tests/schema.rs
+++ b/avro/tests/schema.rs
@@ -2353,3 +2353,19 @@ fn
avro_rs_66_test_independent_canonical_form_missing_ref() -> TestResult {
));
Ok(())
}
+
+#[test]
+fn avro_rs_181_single_null_record() -> TestResult {
+ let mut buff = Cursor::new(Vec::new());
+ let schema = Schema::parse_str(r#""null""#)?;
+ let mut writer = Writer::new(&schema, &mut buff);
+ writer.append(serde_json::Value::Null)?;
+ writer.into_inner()?;
+ buff.set_position(0);
+
+ for val in Reader::new(buff)? {
+ assert_eq!(Value::Null, val?);
+ }
+
+ Ok(())
+}