Skip to content

Commit 335e74e

Browse files
authored
fix: Don't write avro.codec if codec is Null (#356)
1 parent c6cbe79 commit 335e74e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

avro/src/writer.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ impl<'a, W: Write> Writer<'a, W> {
439439

440440
let mut metadata = HashMap::with_capacity(2);
441441
metadata.insert("avro.schema", Value::Bytes(schema_bytes));
442-
metadata.insert("avro.codec", self.codec.into());
442+
if self.codec != Codec::Null {
443+
metadata.insert("avro.codec", self.codec.into());
444+
}
443445
match self.codec {
444446
#[cfg(feature = "bzip")]
445447
Codec::Bzip2(settings) => {
@@ -865,7 +867,7 @@ mod tests {
865867
let mut writer = Writer::new(&schema, Vec::new())?;
866868
writer.flush()?;
867869
let result = writer.into_inner()?;
868-
assert_eq!(result.len(), 163);
870+
assert_eq!(result.len(), 147);
869871

870872
// Unless the user indicates via the builder that the header has already been written
871873
let mut writer = Writer::builder()
@@ -1341,7 +1343,7 @@ mod tests {
13411343
writer.flush()?;
13421344
let result = writer.into_inner()?;
13431345

1344-
assert_eq!(result.len(), 260);
1346+
assert_eq!(result.len(), 244);
13451347

13461348
Ok(())
13471349
}
@@ -1617,7 +1619,7 @@ mod tests {
16171619

16181620
let bytes = writer.append_ser(conf)?;
16191621

1620-
assert_eq!(198, bytes);
1622+
assert_eq!(182, bytes);
16211623

16221624
Ok(())
16231625
}
@@ -1707,7 +1709,7 @@ mod tests {
17071709

17081710
assert_eq!(
17091711
shared_buffer.len(),
1710-
167,
1712+
151,
17111713
"the test buffer was not fully written to after Writer::flush was called"
17121714
);
17131715

avro/tests/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ fn test_record_schema_with_cyclic_references() -> TestResult {
816816
panic!("An error occurred while writing datum: {err:?}")
817817
}
818818
let bytes = writer.into_inner()?;
819-
assert_eq!(316, bytes.len());
819+
assert_eq!(300, bytes.len());
820820

821821
match Reader::new(&mut bytes.as_slice()) {
822822
Ok(mut reader) => match reader.next() {

0 commit comments

Comments
 (0)