Class ZstdNative

java.lang.Object
com.hypixel.hytale.protocol.io.ZstdNative

public final class ZstdNative extends Object
FFM bindings for libzstd compression library. Loads the native library from classpath resources (same binaries as the client).

All target platforms (Linux x64, macOS arm64, Windows x64) are 64-bit, so size_t is always 8 bytes and mapped to Java long.

  • Field Details

  • Method Details

    • compress

      public static long compress(MemorySegment dst, long dstCapacity, MemorySegment src, long srcSize, int compressionLevel)
      Compress src into dst.
      Returns:
      compressed size, or an error code (check with isError(long))
    • decompress

      public static long decompress(MemorySegment dst, long dstCapacity, MemorySegment src, long compressedSize)
      Decompress src into dst.
      Returns:
      decompressed size, or an error code (check with isError(long))
    • compressBound

      public static long compressBound(long srcSize)
      Returns:
      maximum compressed size for a given source size
    • getFrameContentSize

      public static long getFrameContentSize(MemorySegment src, long srcSize)
      Returns:
      decompressed content size from the frame header, or CONTENT_SIZE_UNKNOWN / CONTENT_SIZE_ERROR
    • isError

      public static boolean isError(long code)
    • getErrorName

      public static String getErrorName(long code)
    • defaultCompressionLevel

      public static int defaultCompressionLevel()
    • createCCtx

      public static MemorySegment createCCtx()
      Create a compression context. The returned segment must be freed with freeCCtx(MemorySegment).
      Returns:
      opaque ZSTD_CCtx pointer, or MemorySegment.NULL on allocation failure
    • freeCCtx

      public static long freeCCtx(MemorySegment cctx)
      Free a compression context previously created with createCCtx().
      Returns:
      0 on success, or an error code (check with isError(long))
    • compressCCtx

      public static long compressCCtx(MemorySegment cctx, MemorySegment dst, long dstCapacity, MemorySegment src, long srcSize, int compressionLevel)
      Compress src into dst using a reusable compression context. The context is reset internally between calls so it can be reused without recreation.
      Returns:
      compressed size, or an error code (check with isError(long))
    • createDCtx

      public static MemorySegment createDCtx()
      Create a decompression context. The returned segment must be freed with freeDCtx(MemorySegment).
      Returns:
      opaque ZSTD_DCtx pointer, or MemorySegment.NULL on allocation failure
    • freeDCtx

      public static long freeDCtx(MemorySegment dctx)
      Free a decompression context previously created with createDCtx().
      Returns:
      0 on success, or an error code (check with isError(long))
    • decompressDCtx

      public static long decompressDCtx(MemorySegment dctx, MemorySegment dst, long dstCapacity, MemorySegment src, long compressedSize)
      Decompress src into dst using a reusable decompression context. The context is reset internally between calls so it can be reused without recreation.
      Returns:
      decompressed size, or an error code (check with isError(long))