[
https://issues.apache.org/jira/browse/AVRO-3631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17610586#comment-17610586
]
Rik Heijdens commented on AVRO-3631:
------------------------------------
Hi [~mgrigorov], please see the test-case I added
[here|https://github.com/apache/avro/compare/master...privacy-com:avro:avro-3631/fix-fixed-serialization?expand=1].
I did a bit of reading on the `Serialize` trait, and while that supports
sequence of bytes, SerDe's data model doesn't appear to be making a distinction
between a fixed length sequence of bytes or variable length sequences. For that
reason I don't think we could ever expect `apache_avro::to_value()` to return
`Value::Fixed`, therefore we might have to relax schema validation somewhat in
order to ensure we can both serialize and deserialize into/from structs that
represent a fixed through an array.
> Fix serialization of structs containing Fixed fields
> ----------------------------------------------------
>
> Key: AVRO-3631
> URL: https://issues.apache.org/jira/browse/AVRO-3631
> Project: Apache Avro
> Issue Type: Bug
> Components: rust
> Reporter: Rik Heijdens
> Priority: Major
>
> Consider the following minimal Avro Schema:
> {noformat}
> {
> "type": "record",
> "name": "TestStructFixedField",
> "fields": [
> {
> "name": "field",
> "type": {
> "name": "field",
> "type": "fixed",
> "size": 6
> }
> }
> ]
> }
> {noformat}
> In Rust, I might represent this schema with the following struct:
> {noformat}
> #[derive(Debug, Serialize, Deserialize)]
> struct TestStructFixedField {
> field: [u8; 6]
> }
> {noformat}
> I would then expect to be able to use `apache_avro::to_avro_datum()` to
> convert an instance of `TestStructFixedField` into an `Vec<u8>` using an
> instance of `Schema` initialized from the schema listed above.
> However, this fails because the `Value` produced by `apache_avro::to_value()`
> represents `field` as an `Value::Array<Vec<u8>>` rather than a
> `Value::Fixed<6, Vec<u8>` which does not pass schema validation.
> I believe that there are two options to fix this:
> 1. Allow Value::Array<Vec<u8>> to pass validation if the array has the
> expected length.
> 2. Update `apache_avro::to_value()` such that fixed length arrays are
> converted into `Value::Fixed<N, Vec<u8>>` rather than `Value::Array`.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)