CompositeMetadataCodec { public static void encodeAndAddMetadataWithCompression( CompositeByteBuf compositeMetaData, ByteBufAllocator allocator, String mimeType, ByteBuf metadata) { WellKnownMimeType wkn = WellKnownMimeType.fromString(mimeType); if (wkn == WellKnownMimeType.UNPARSEABLE_MIME_TYPE) { compositeMetaData.addComponents( true, encodeMetadataHeader(allocator, mimeType, metadata.readableBytes()), metadata); } else { compositeMetaData.addComponents( true, encodeMetadataHeader(allocator, wkn.getIdentifier(), metadata.readableBytes()), metadata); } } private  CompositeMetadataCodec(); static int computeNextEntryIndex(
      int currentEntryIndex, ByteBuf headerSlice, ByteBuf contentSlice); static ByteBuf[] decodeMimeAndContentBuffersSlices(
      ByteBuf compositeMetadata, int entryIndex, boolean retainSlices); static byte decodeMimeIdFromMimeBuffer(ByteBuf mimeBuffer); @Nullable static CharSequence decodeMimeTypeFromMimeBuffer(ByteBuf flyweightMimeBuffer); static void encodeAndAddMetadata(
      CompositeByteBuf compositeMetaData,
      ByteBufAllocator allocator,
      String customMimeType,
      ByteBuf metadata); static void encodeAndAddMetadata(
      CompositeByteBuf compositeMetaData,
      ByteBufAllocator allocator,
      WellKnownMimeType knownMimeType,
      ByteBuf metadata); static void encodeAndAddMetadataWithCompression(
      CompositeByteBuf compositeMetaData,
      ByteBufAllocator allocator,
      String mimeType,
      ByteBuf metadata); static boolean hasEntry(ByteBuf compositeMetadata, int entryIndex); static boolean isWellKnownMimeType(ByteBuf header);  }
@Test void encodeTryCompressWithCompressableType() { ByteBuf metadata = ByteBufUtils.getRandomByteBuf(2); CompositeByteBuf target = UnpooledByteBufAllocator.DEFAULT.compositeBuffer(); CompositeMetadataCodec.encodeAndAddMetadataWithCompression( target, UnpooledByteBufAllocator.DEFAULT, WellKnownMimeType.APPLICATION_AVRO.getString(), metadata); assertThat(target.readableBytes()).as("readableBytes 1 + 3 + 2").isEqualTo(6); }
@Test void encodeTryCompressWithCustomType() { ByteBuf metadata = ByteBufUtils.getRandomByteBuf(2); CompositeByteBuf target = UnpooledByteBufAllocator.DEFAULT.compositeBuffer(); CompositeMetadataCodec.encodeAndAddMetadataWithCompression( target, UnpooledByteBufAllocator.DEFAULT, "custom/example", metadata); assertThat(target.readableBytes()).as("readableBytes 1 + 14 + 3 + 2").isEqualTo(20); }