minghuaw / fe2o3-amqp

A rust implementation of the AMQP1.0 protocol based on serde and tokio.
MIT License
58 stars 7 forks source link

serde_amqp does not symmetrically encode an empty array #277

Closed LarryOsterman closed 1 week ago

LarryOsterman commented 3 weeks ago

When decoding an empty array, serde_amqp::to_vec returns a 3 byte encoding:

0xE0, 0x01, 0x00

However when encoding this 3 byte encoding, the serde_amqp::from_slice fails because "Err(Io(Custom { kind: UnexpectedEof, error: "Expecting format code" }))"

A simple reproduction is:

    let value_to_encode = fe2o3_amqp_types::primitives::Value::Array(fe2o3_amqp_types::primitives::Array::from(vec![]));
    let buffer = serde_amqp::to_vec(&value_to_encode).unwrap();

    let value: Result<fe2o3_amqp_types::primitives::Value, serde_amqp::error::Error> =
        serde_amqp::from_slice(buffer.as_slice());

    if value.is_err() {
        println!("Error: {:?}", value);
    }
    assert!(value.is_ok());

Note that if the buffer is 0xE0, 0x02, 0x00, 0x40 the from_slice call succeeds, but if you subsequently call to_vec on the buffer, you get the 0xE0, 0x01, 0x00 output.

minghuaw commented 3 weeks ago

Thanks for raising this. Should be fixed in 0.12.1 (#278) :)

LarryOsterman commented 3 weeks ago

Thank you SO very much for the insanely fast turnaround.