congbobo184 commented on a change in pull request #9481:
URL: https://github.com/apache/pulsar/pull/9481#discussion_r572722501



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericAvroWriter.java
##########
@@ -52,4 +67,29 @@ public GenericAvroWriter(Schema schema) {
             this.byteArrayOutputStream.reset();
         }
     }
+
+    /**
+     * This is an adapter from Pulsar GenericRecord to Avro classes.
+     */
+    private class GenericRecordAdapter extends SpecificRecordBase {
+        private GenericRecord message;
+
+        void setCurrentMessage(GenericRecord message) {
+            this.message = message;
+        }
+        @Override
+        public Schema getSchema() {
+            return schema;
+        }
+
+        @Override
+        public Object get(int field) {
+            return message.getField(schema.getFields().get(field).name());
+        }
+
+        @Override
+        public void put(int field, Object value) {
+            throw new UnsupportedOperationException();
+        }
+    }

Review comment:
       why we make `GenericRecordAdapter` extend `SpecificRecordBase` not 
`GenericRecord `, seem `private final 
GenericDatumWriter<org.apache.avro.generic.GenericRecord> writer;` only can 
write `GenericRecord` not `SpecificRecordBase`.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to