szetszwo commented on code in PR #9061:
URL: https://github.com/apache/ozone/pull/9061#discussion_r2380571833
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/KeyPrefixContainerCodec.java:
##########
@@ -50,6 +56,130 @@ public Class<KeyPrefixContainer> getTypeClass() {
return KeyPrefixContainer.class;
}
+ @Override
+ public boolean supportCodecBuffer() {
+ return true;
+ }
+
+ @Override
+ public CodecBuffer toCodecBuffer(@Nonnull KeyPrefixContainer object,
CodecBuffer.Allocator allocator) {
+ Preconditions.checkNotNull(object, "Null object can't be converted to
CodecBuffer.");
+
+ final byte[] keyPrefixBytes = object.getKeyPrefix().getBytes(UTF_8);
+ int totalSize = keyPrefixBytes.length;
+
+ if (object.getKeyVersion() != -1) {
+ totalSize += KEY_DELIMITER.getBytes(UTF_8).length + Long.BYTES;
+ }
+ if (object.getContainerId() != -1) {
+ totalSize += KEY_DELIMITER.getBytes(UTF_8).length + Long.BYTES;
+ }
+
+ final CodecBuffer buffer = allocator.apply(totalSize);
+ buffer.put(ByteBuffer.wrap(keyPrefixBytes));
+
+ if (object.getKeyVersion() != -1) {
+ buffer.put(ByteBuffer.wrap(KEY_DELIMITER.getBytes(UTF_8)));
+ buffer.putLong(object.getKeyVersion());
+ }
+
+ if (object.getContainerId() != -1) {
+ buffer.put(ByteBuffer.wrap(KEY_DELIMITER.getBytes(UTF_8)));
+ buffer.putLong(object.getContainerId());
+ }
+
+ return buffer;
+ }
+
+ @Override
+ public KeyPrefixContainer fromCodecBuffer(@Nonnull CodecBuffer buffer)
throws CodecException {
+
+ Object wrapped = buffer.getWrapped();
+ if (wrapped instanceof byte[]) {
+ return fromPersistedFormat((byte[]) wrapped);
+ }
Review Comment:
@YutaLin , one more thing: Let's remove this? The test use heap buffers.
Then, it will have arrays and won't test the code below this.
--
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]