Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a way to use the provided Schema when using "the serde way" #70

Open
martin-g opened this issue Dec 4, 2024 · 0 comments
Open

Comments

@martin-g
Copy link
Member

martin-g commented Dec 4, 2024

See

avro-rs/avro/src/schema.rs

Lines 6446 to 6482 in d6a1e4f

#[test]
fn avro_rs_53_uuid_with_fixed() -> TestResult {
#[derive(Debug, Serialize, Deserialize)]
struct Comment {
id: crate::Uuid,
}
impl AvroSchema for Comment {
fn get_schema() -> Schema {
Schema::parse_str(
r#"{
"type" : "record",
"name" : "Comment",
"fields" : [ {
"name" : "id",
"type" : {
"type" : "fixed",
"size" : 16,
"logicalType" : "uuid",
"name": "FixedUUID"
}
} ]
}"#,
)
.expect("Invalid Comment Avro schema")
}
}
let payload = Comment {
id: "de2df598-9948-4988-b00a-a41c0e287398".parse()?,
};
let mut buffer = Vec::new();
SpecificSingleObjectWriter::<Comment>::with_capacity(10)?
.write_ref(&payload, &mut buffer)?;
Ok(())
}

Here the test uses


 SpecificSingleObjectWriter::<Comment>::with_capacity(10)?
            .write_ref(&Comment {id: "de2df598-9948-4988-b00a-a41c0e287398".parse()?}, &mut buffer)?;

The Avro Schema is available via Comment::get_schema() but it is not used at

avro-rs/avro/src/writer.rs

Lines 551 to 555 in d6a1e4f

pub fn write_ref<W: Write>(&mut self, data: &T, writer: &mut W) -> AvroResult<usize> {
let mut serializer = Serializer::default();
let v = data.serialize(&mut serializer)?;
self.inner.write_value_ref(&v, writer)
}
because Serde does not work with schemas.

We need to find a way to make use of the schema because now the id struct field is serialized/encoded as a types::Value::String instead of Uuid or even Fixed(16), as defined in the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant