forked from apache/avro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AVRO-3631: Add serde serialize_with functions
Those should be used for hinting the serialization process how to serialize a byte array to Value::(Bytes|Fixed) Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
- Loading branch information
Showing
6 changed files
with
186 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use apache_avro::to_value; | ||
use apache_avro::types::Value; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[test] | ||
fn avro_3631_visibility_of_avro_serialize_bytes_type() { | ||
use apache_avro::{avro_serialize_bytes, avro_serialize_fixed}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct TestStructFixedField<'a> { | ||
// will be serialized as Value::Bytes | ||
#[serde(serialize_with = "avro_serialize_bytes")] | ||
bytes_field: &'a [u8], | ||
|
||
// will be serialized as Value::Fixed | ||
#[serde(serialize_with = "avro_serialize_fixed")] | ||
fixed_field: [u8; 6], | ||
} | ||
|
||
let test = TestStructFixedField { | ||
bytes_field: &[2, 22, 222], | ||
fixed_field: [1; 6], | ||
}; | ||
|
||
let expected = Value::Record(vec![ | ||
( | ||
"bytes_field".to_owned(), | ||
Value::Bytes(Vec::from(test.bytes_field.clone())), | ||
), | ||
( | ||
"fixed_field".to_owned(), | ||
Value::Fixed(6, Vec::from(test.fixed_field.clone())), | ||
), | ||
]); | ||
|
||
assert_eq!(expected, to_value(test).unwrap()); | ||
} |