Skip to content

Serialize an empty buffer as Decimal creates a value that fail to read #683

Closed

Description

@hvnsweeting

Related to #680 and #681

Using functions like write_ser or append_ser still able to write zero length Decimal.

    #[test]
    fn avro_rs_xxx_serde_decimal_bytes_zero_length_union() -> TestResult {
        use crate::reader::datum::GenericDatumReader;
        use crate::writer::datum::GenericDatumWriter;

        use serde_bytes::ByteBuf;
        let schema = Schema::parse_str(
            r#"[{"type": "bytes", "logicalType": "decimal", "precision": 4}, "string"]"#,
        )?;
        let buf: &[u8] = &[0x00, 0x00];

        let writer = GenericDatumWriter::builder(&schema).build().unwrap();
        let v = writer.write_ser_to_vec(&ByteBuf::new()).unwrap();
        assert_eq!(buf, v);
        let reader = GenericDatumReader::builder(&schema).build().unwrap();
        dbg!(reader.read_value(&mut &buf[..]));
        Ok(())
    }

Output

[avro/src/decode.rs:1228:9] reader.read_value(&mut &buf[..]) = Err(
    Error {
        details: Decimal bytes cannot be zero length,
    },
)
test decode::tests::avro_rs_xxx_serde_decimal_bytes_zero_length_union ... ok

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions