Jackie-Jiang commented on code in PR #19836:
URL: https://github.com/apache/pinot/pull/19836#discussion_r4288666648
##########
pinot-core/src/main/java/org/apache/pinot/core/common/ObjectSerDeUtils.java:
##########
@@ -323,11 +326,35 @@ public static ObjectType getObjectType(Object value) {
/// Serializer/De-serializer for a specific type of object.
///
+ /// Implementations must override either the byte-array serializer or both
[#getSerializedSize(Object)] and
+ /// the buffer serializer [#serialize(Object, ByteBuffer)].
+ ///
/// @param <T> Type of the object
public interface ObjectSerDe<T> {
/// Serializes a value into a byte array.
- byte[] serialize(T value);
+ /// Typed forwarding overrides preserve receiver specialization when
invoking this default.
+ default byte[] serialize(T value) {
+ byte[] bytes = new byte[getSerializedSize(value)];
+ serialize(value, ByteBuffer.wrap(bytes));
+ return bytes;
+ }
+
+ /// Returns the exact size of a representable payload, or `-1` when
allocation-free sizing is unsupported.
+ /// This method must not serialize the value or allocate a payload array.
The value must remain unchanged between
+ /// sizing and serialization. The destination must be bounded to this size
when serializing.
Review Comment:
Non-blocking simplification: can we require sufficient remaining space
instead of bounding the destination to the exact payload size? The
implementations already support this, so callers can append to a larger buffer
without adjusting its limit for every object.
```suggestion
/// sizing and serialization. The destination must have at least this
many bytes remaining.
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]