eolivelli commented on a change in pull request #10184:
URL: https://github.com/apache/pulsar/pull/10184#discussion_r611008720
##########
File path:
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/Schema.java
##########
@@ -120,6 +122,21 @@ default T decode(byte[] bytes, byte[] schemaVersion) {
return decode(bytes);
}
+ /**
+ * Decode a ByteBuf into an object using a given version. <br/>
+ * <b>NOTE</b>: This method should not modify reader/writer index of
ByteBuf else it can cause corruption while
+ * accessing same ByteBuf for decoding and deserialization.
+ *
+ * @param byteBuf
+ * the byte array to decode
+ * @param schemaVersion
+ * the schema version to decode the object. null indicates
using latest version.
+ * @return the deserialized object
+ */
+ default T decode(ByteBuf bytes, byte[] schemaVersion) {
+ return null;
Review comment:
if you look at this from Pulsar point of view you are right.
but sometimes in your application or Pulsar IO Sink you have a Schema
instance and you want to decode a given payload using the Schema.
In this case if you see that there is a `decode(ByteBuf) `method and you
already have a `ByteBuf` you are tempted to use this new method, but it is not
implemented for most of the system Schema and it is absolutely not implemented
for new custom Schema.
this is why I believe that we should provide a default implementation that
relies on the fact that the `decode(byte[]....) `method is always implemented.
the default implementation is straightforward and I believe it is worth to
add it
--
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]