java.lang.Object
org.elasticsearch.nativeaccess.Zstd

public final class Zstd extends Object
  • Method Details

    • compress

      public int compress(CloseableByteBuffer dst, CloseableByteBuffer src, int level)
      Compress the content of src into dst at compression level level, and return the number of compressed bytes. Buffer.position() and Buffer.limit() of both ByteBuffers are left unmodified.
    • decompress

      public int decompress(CloseableByteBuffer dst, CloseableByteBuffer src)
      Decompress the content of src into dst, and return the number of decompressed bytes. Buffer.position() and Buffer.limit() of both ByteBuffers are left unmodified.
    • decompress

      public int decompress(CloseableByteBuffer dst, ByteBuffer src)
      Variant of decompress(CloseableByteBuffer, CloseableByteBuffer) that accepts a direct ByteBuffer as the source. Use this when the caller already holds a direct buffer (e.g. from DirectAccessInput.withByteBufferSlice) to avoid allocating an intermediate CloseableByteBuffer.
    • decompress

      public int decompress(ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize)
      Decompress srcSize bytes starting at srcOffset of the direct ByteBuffer src into dstSize bytes starting at dstOffset of the direct ByteBuffer dst, and return the number of decompressed bytes. Both buffers must be direct. Buffer.position() and Buffer.limit() of both buffers are left unmodified — callers manage their own cursors. Suits external codec APIs that pass plain ByteBuffers with explicit offsets/sizes (e.g. parquet-mr's BytesInputDecompressor).
    • decompress

      public int decompress(byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize)
      One-shot heap byte[] decompress for callers that already hold the full compressed frame in a Java array (e.g. parquet-mr's BytesInputDecompressor#decompress(BytesInput,int)). Equivalent to com.github.luben.zstd.Zstd.decompress(byte[], byte[]) but routed through Panama FFI's critical(true) downcall — the heap segments are passed through directly without an off-heap staging copy. Returns the number of decompressed bytes actually written into dst[dstOffset .. dstOffset+dstSize).
    • compress

      public int compress(byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize, int level)
      One-shot heap byte[] compress at the given zstd compression level. The caller must size dst to at least compressBound(int) bytes for srcSize; Parquet's BytesInputCompressor sizes its output buffer based on libzstd's worst case. Returns the actual compressed length written into dst[dstOffset .. dstOffset+returned).
    • compressBound

      public int compressBound(int srcLen)
      Return the maximum number of compressed bytes given an input length.
    • dStreamInSize

      public int dStreamInSize()
      Recommended size for the input buffer feeding Zstd.DStream.decompress(byte[], int, int, byte[], int, int) (ZSTD_DStreamInSize). The value is constant per libzstd build (≈ 128 KB on 1.5.7); callers typically cache it in a static final field rather than calling per-stream.
    • dStreamOutSize

      public int dStreamOutSize()
      Recommended size for the output buffer of Zstd.DStream.decompress(byte[], int, int, byte[], int, int) (ZSTD_DStreamOutSize). Used only by the skip() scratch buffer in the wrapper — the regular read path writes straight into the caller's destination array.
    • newDStream

      public Zstd.DStream newDStream()
      Allocate a streaming decompression context wrapping ZSTD_DStream. The returned Zstd.DStream owns a native zstd context plus two small persistent struct holders; call Zstd.DStream.close() (or use try-with-resources) to release them. Single-threaded by contract — do not share a single Zstd.DStream across threads.