eolivelli commented on code in PR #14542:
URL: https://github.com/apache/pulsar/pull/14542#discussion_r845947704


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/MetaStoreImpl.java:
##########
@@ -364,41 +445,25 @@ private static MetaStoreException getException(Throwable 
t) {
         }
     }
 
-    public ManagedLedgerInfo parseManagedLedgerInfo(byte[] data) throws 
InvalidProtocolBufferException {
-        ByteBuf byteBuf = Unpooled.wrappedBuffer(data);
-        if (byteBuf.readableBytes() > 0 && byteBuf.readShort() == 
MAGIC_MANAGED_LEDGER_INFO_METADATA) {
-            ByteBuf decodeByteBuf = null;
-            try {
-                int metadataSize = byteBuf.readInt();
-                byte[] metadataBytes = new byte[metadataSize];
-                byteBuf.readBytes(metadataBytes);
-                MLDataFormats.ManagedLedgerInfoMetadata metadata =
-                        
MLDataFormats.ManagedLedgerInfoMetadata.parseFrom(metadataBytes);
-
-                long unpressedSize = metadata.getUncompressedSize();
-                decodeByteBuf = 
getCompressionCodec(metadata.getCompressionType())
-                        .decode(byteBuf, (int) unpressedSize);
-                byte[] decodeBytes;
-                // couldn't decode data by ZLIB compression byteBuf array() 
directly
-                if (decodeByteBuf.hasArray() && 
!CompressionType.ZLIB.equals(metadata.getCompressionType())) {
-                    decodeBytes = decodeByteBuf.array();
-                } else {
-                    decodeBytes = new byte[decodeByteBuf.readableBytes() - 
decodeByteBuf.readerIndex()];
-                    decodeByteBuf.readBytes(decodeBytes);
-                }
-                return ManagedLedgerInfo.parseFrom(decodeBytes);
-            } catch (Exception e) {
-                log.error("Failed to parse managedLedgerInfo metadata, "
-                        + "fall back to parse managedLedgerInfo directly.", e);
-                return ManagedLedgerInfo.parseFrom(data);
-            } finally {
-                if (decodeByteBuf != null) {
-                    decodeByteBuf.release();
-                }
-                byteBuf.release();
+    private byte[] parseCompressedInfo(ByteBuf byteBuf, 
MLDataFormats.CompressionType compressionType,
+                                       long unpressedSize) throws IOException {
+        ByteBuf decodeByteBuf = null;
+        try {
+            decodeByteBuf = getCompressionCodec(compressionType)
+                    .decode(byteBuf, (int) unpressedSize);
+            byte[] decodeBytes;
+            // couldn't decode data by ZLIB compression byteBuf array() 
directly
+            if (decodeByteBuf.hasArray() && 
!CompressionType.ZLIB.equals(compressionType)) {
+                decodeBytes = decodeByteBuf.array();

Review Comment:
   this is exactly my point.
   a ByteBuf maybe a wrapper over a portion of a byte[] at a give offset
   
   we MUST use
   
https://netty.io/4.1/api/io/netty/buffer/ByteBufUtil.html#getBytes-io.netty.buffer.ByteBuf-int-int-boolean-
   
   
   



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

Reply via email to