martin-g commented on code in PR #339:
URL: https://github.com/apache/avro-rs/pull/339#discussion_r2639571425


##########
avro/src/types.rs:
##########
@@ -478,6 +480,15 @@ impl Value {
                     None
                 }
             }
+            (&Value::Fixed(n, _), Schema::Uuid(UuidSchema::Fixed(size, ..))) 
=> {
+                if n != 16 || size.size != 16 {
+                    Some(format!(
+                        "The value's size ('{n}') must be exactly 16 to be a 
Uuid"

Review Comment:
   `size.size` checks the the schema's size. The error message always says 
`value's size`



##########
avro/tests/serde_human_readable_true.rs:
##########
@@ -18,8 +18,7 @@ fn avro_rs_53_uuid_with_fixed_true() -> TestResult {
                         "fields" : [ {
                           "name" : "id",
                           "type" : {
-                            "type" : "fixed",
-                            "size" : 16,
+                            "type" : "string",
                             "logicalType" : "uuid",
                             "name": "FixedUUID"

Review Comment:
   ```suggestion
                               "name": "StringUUID"
   ```



##########
avro/src/encode.rs:
##########
@@ -136,23 +144,30 @@ pub(crate) fn encode_internal<W: Write, S: 
Borrow<Schema>>(
                 .map_err(|e| Details::WriteBytes(e).into())
         }
         Value::Uuid(uuid) => match *schema {
-            Schema::Uuid | Schema::String => encode_bytes(
+            Schema::Uuid(UuidSchema::String) | Schema::String => encode_bytes(
                 // we need the call .to_string() to properly convert ASCII to 
UTF-8
                 #[allow(clippy::unnecessary_to_owned)]
                 &uuid.to_string(),
                 writer,
             ),
-            Schema::Fixed(FixedSchema { size, .. }) => {
+            Schema::Uuid(UuidSchema::Bytes) | Schema::Bytes => {
+                let bytes = uuid.as_bytes();
+                encode_bytes(bytes, writer)
+            }
+            Schema::Uuid(UuidSchema::Fixed(FixedSchema { size, .. }))
+            | Schema::Fixed(FixedSchema { size, .. }) => {
                 if size != 16 {
                     return Err(Details::ConvertFixedToUuid(size).into());
                 }
 
                 let bytes = uuid.as_bytes();
-                encode_bytes(bytes, writer)
+                writer
+                    .write(bytes.as_slice())
+                    .map_err(|e| Details::WriteBytes(e).into())
             }
             _ => Err(Details::EncodeValueAsSchemaError {
                 value_kind: ValueKind::Uuid,
-                supported_schema: vec![SchemaKind::Uuid, SchemaKind::Fixed],
+                supported_schema: vec![SchemaKind::Uuid, SchemaKind::Fixed, 
SchemaKind::Bytes],

Review Comment:
   ```suggestion
                   supported_schema: vec![SchemaKind::Uuid, SchemaKind::Fixed, 
SchemaKind::Bytes, SchemaKind::String],
   ```



-- 
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]

Reply via email to