Contents
- Description
- Field Summary
- Method Summary
- Field Details
- Method Details
- compress(MemorySegment, long, MemorySegment, long, int)
- decompress(MemorySegment, long, MemorySegment, long)
- compressBound(long)
- getFrameContentSize(MemorySegment, long)
- isError(long)
- getErrorName(long)
- defaultCompressionLevel()
- createCCtx()
- freeCCtx(MemorySegment)
- compressCCtx(MemorySegment, MemorySegment, long, MemorySegment, long, int)
- createDCtx()
- freeDCtx(MemorySegment)
- decompressDCtx(MemorySegment, MemorySegment, long, MemorySegment, long)
Class ZstdNative
java.lang.Object
com.hypixel.hytale.protocol.io.ZstdNative
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final longReturned bygetFrameContentSize(MemorySegment, long)on error.static final longReturned bygetFrameContentSize(MemorySegment, long)when the size is unknown. -
Method Summary
Modifier and TypeMethodDescriptionstatic longcompress(MemorySegment dst, long dstCapacity, MemorySegment src, long srcSize, int compressionLevel) Compress src into dst.static longcompressBound(long srcSize) static longcompressCCtx(MemorySegment cctx, MemorySegment dst, long dstCapacity, MemorySegment src, long srcSize, int compressionLevel) Compress src into dst using a reusable compression context.static MemorySegmentCreate a compression context.static MemorySegmentCreate a decompression context.static longdecompress(MemorySegment dst, long dstCapacity, MemorySegment src, long compressedSize) Decompress src into dst.static longdecompressDCtx(MemorySegment dctx, MemorySegment dst, long dstCapacity, MemorySegment src, long compressedSize) Decompress src into dst using a reusable decompression context.static intstatic longfreeCCtx(MemorySegment cctx) Free a compression context previously created withcreateCCtx().static longfreeDCtx(MemorySegment dctx) Free a decompression context previously created withcreateDCtx().static StringgetErrorName(long code) static longgetFrameContentSize(MemorySegment src, long srcSize) static booleanisError(long code)
-
Field Details
-
CONTENT_SIZE_UNKNOWN
public static final long CONTENT_SIZE_UNKNOWNReturned bygetFrameContentSize(MemorySegment, long)when the size is unknown.- See Also:
-
CONTENT_SIZE_ERROR
public static final long CONTENT_SIZE_ERRORReturned bygetFrameContentSize(MemorySegment, long)on error.- See Also:
-
-
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
- Returns:
- decompressed content size from the frame header, or
CONTENT_SIZE_UNKNOWN/CONTENT_SIZE_ERROR
-
isError
public static boolean isError(long code) -
getErrorName
-
defaultCompressionLevel
public static int defaultCompressionLevel() -
createCCtx
Create a compression context. The returned segment must be freed withfreeCCtx(MemorySegment).- Returns:
- opaque ZSTD_CCtx pointer, or
MemorySegment.NULLon allocation failure
-
freeCCtx
Free a compression context previously created withcreateCCtx().- 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
Create a decompression context. The returned segment must be freed withfreeDCtx(MemorySegment).- Returns:
- opaque ZSTD_DCtx pointer, or
MemorySegment.NULLon allocation failure
-
freeDCtx
Free a decompression context previously created withcreateDCtx().- 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))
-