Theodlz commented on issue #350:
URL: https://github.com/apache/avro-rs/issues/350#issuecomment-3612471306

   I wonder if there is a more elegant solution, but I ended up writing the 
following:
   ```rust
   // Wrapper around cutout bytes, so we can implement AvroSchemaComponent
   // for it, to serialize as bytes in Avro
   #[derive(Debug, serde::Deserialize, serde::Serialize)]
   pub struct CutoutBytes(Vec<u8>);
   
   impl apache_avro::schema::derive::AvroSchemaComponent for CutoutBytes {
       fn get_schema_in_ctxt(
           _named_schemas: &mut HashMap<apache_avro::schema::Name, 
apache_avro::schema::Schema>,
           _enclosing_namespace: &apache_avro::schema::Namespace,
       ) -> apache_avro::Schema {
           apache_avro::Schema::Bytes
       }
   }
   
   pub fn serialize_cutout_bytes_option<S>(cutout: &Option<CutoutBytes>, 
serializer: S) -> Result<S::Ok, S::Error>
   where
       S: serde::ser::Serializer,
   {
       match cutout {
           Some(cutout_bytes) => 
apache_avro::serde_avro_bytes::serialize(&cutout_bytes.0, serializer),
           None => serializer.serialize_none(),
       }
   }
   ```
   
   then a struct would just use `CutoutBytes` in place of a Vec<u8> + the 
serializer defined above, and the schema uses the `bytes` type + the data is 
serialized to bytes.


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