You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/07/31 07:53:13 UTC

[GitHub] [rocketmq-schema-registry] MatrixHB commented on pull request #16: add avro schema serializer and deserializer

MatrixHB commented on PR #16:
URL: https://github.com/apache/rocketmq-schema-registry/pull/16#issuecomment-1200370038

   I have an idea about design of schema serializer/deserializer
   
   What's exposed to users is `SchemaWrapper`,  which includes `Map<String/*SchemaType*/, Serializer>` and `Map<String/*SchemaType*/, Deserializer>`(or Factory...).  Then the user doesn't need to know the schema type (avro/json/thrift....) and just leave the serializer work to `SchemaWrapper`. 
   In `SchemaWrapper`, after getting schema from registry, we can know the type of schema, then we can decide what kind of serializer to use.
   
   The pseudo code as follows.
   ```
   public class SchemaWrapper {
   
       private final SchemaRegistryClient schemaRegistryClient;
   
       private Map<String/*schema type*/, Serializer> serializerMap;
       
       <T> byte[] serialize(T data, String topic) throws Exception{
           GetSchemaResponse response = schemaRegistryClient.getSchemaBySubject(topic);
           Serializer serializer = serializerMap.get(response.getType);
           return serializer.serialize(data, response.getIdl());
       }
   
       
       <T> T deserialize(byte[] data, String topic) {
           
       }
   }
   
   ```
   @humkum @ferrirW  What do you think about this design?
   
   
   
   


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org