Kriskras99 commented on code in PR #663:
URL: https://github.com/apache/avro-rs/pull/663#discussion_r3947205146
##########
avro/src/decode.rs:
##########
@@ -222,46 +222,42 @@ fn decode_internal_body<R: Read, S: Borrow<Schema>>(
}
}
Schema::Uuid(UuidSchema::String) => {
- let Value::String(string) =
- decode_internal(&Schema::String, names, enclosing_namespace,
reader, ctx)?
- else {
- // decoding a String can also return a Null, indicating EOF
- return Err(Error::new(Details::ReadBytes(std::io::Error::from(
- ErrorKind::UnexpectedEof,
- ))));
- };
- let uuid =
Uuid::parse_str(&string).map_err(Details::ConvertStrToUuid)?;
- Ok(Value::Uuid(uuid))
+ let len = decode_len(reader)?;
+ if len <= uuid::fmt::Urn::LENGTH {
+ let mut buf = [0u8; uuid::fmt::Urn::LENGTH];
+ reader
+ .read_exact(&mut buf[..len])
+ .map_err(Details::ReadString)?;
+ let uuid =
Uuid::try_parse_ascii(&buf[..len]).map_err(Details::ConvertStrToUuid)?;
+ Ok(Value::Uuid(uuid))
+ } else {
+ Err(Details::ConvertStringToUuid(uuid::fmt::Urn::LENGTH,
len).into())
+ }
}
Schema::Uuid(UuidSchema::Bytes) => {
- let Value::Bytes(bytes) =
- decode_internal(&Schema::Bytes, names, enclosing_namespace,
reader, ctx)?
- else {
- unreachable!(
- "decode_internal(Schema::Bytes) can only return a
Value::Bytes or an error"
- )
- };
- let uuid =
Uuid::from_slice(&bytes).map_err(Details::ConvertSliceToUuid)?;
- Ok(Value::Uuid(uuid))
+ let len = decode_len(reader)?;
+ if len == 16 {
+ let mut buf = [0u8; 16];
+ reader
+ .read_exact(&mut buf)
+ .map_err(|e| Details::ReadFixed(e, 16))?;
Review Comment:
No it is not, I'll fix it tonight!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]