gaoran10 commented on a change in pull request #11490:
URL: https://github.com/apache/pulsar/pull/11490#discussion_r680364986



##########
File path: 
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/MetaStoreImpl.java
##########
@@ -264,4 +285,70 @@ private static MetaStoreException getException(Throwable 
t) {
             return new MetaStoreException(t);
         }
     }
+
+    /**
+     * Compress ManagedLedgerInfo data.
+     *
+     * compression data structure
+     * [MAGIC_NUMBER](2) + [METADATA_SIZE](4) + [METADATA_PAYLOAD] + 
[MANAGED_LEDGER_INFO_PAYLOAD]
+      */
+    public byte[] compressLedgerInfo(ManagedLedgerInfo managedLedgerInfo) {
+        if (compressionType == null || 
compressionType.equals(CompressionType.NONE)) {
+            return managedLedgerInfo.toByteArray();
+        }
+        byte[] originalBytes = managedLedgerInfo.toByteArray();
+        MLDataFormats.ManagedLedgerInfoMetadata mlInfoMetadata = 
MLDataFormats.ManagedLedgerInfoMetadata.newBuilder()
+                .setCompressionType(compressionType.name())
+                .setUnpressedSize(originalBytes.length)
+                .build();
+        ByteBuf metadataByteBuf = PulsarByteBufAllocator.DEFAULT.buffer(
+                mlInfoMetadata.getSerializedSize() + 6, 
mlInfoMetadata.getSerializedSize() + 6);
+        metadataByteBuf.writeShort(MAGIC_MANAGED_LEDGER_INFO_METADATA);
+        metadataByteBuf.writeInt(mlInfoMetadata.getSerializedSize());
+        metadataByteBuf.writeBytes(mlInfoMetadata.toByteArray());
+
+        ByteBuf originalByteBuf = 
PulsarByteBufAllocator.DEFAULT.buffer(originalBytes.length, 
originalBytes.length);
+        originalByteBuf.writeBytes(originalBytes);
+        ByteBuf encodeByteBuf = 
CompressionCodecProvider.getCompressionCodec(compressionType).encode(originalByteBuf);

Review comment:
       I'll fix 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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to