using System; namespace ScreenConnect; public class ZStandardEncoder : ZStandardCoder { public int WindowLog { get; } public int CompressionLevel { get; } public ZStandardEncoder(int compressionLevel, int windowLog) { WindowLog = windowLog; CompressionLevel = compressionLevel; } protected override (Native.libzstd.ZSTD_cParameter, int)[] GetParameterValues() { return new(Native.libzstd.ZSTD_cParameter, int)[6] { (Native.libzstd.ZSTD_cParameter.ZSTD_c_compressionLevel, CompressionLevel), (Native.libzstd.ZSTD_cParameter.ZSTD_c_windowLog, WindowLog), (Native.libzstd.ZSTD_cParameter.ZSTD_c_enableLongDistanceMatching, 1), (Native.libzstd.ZSTD_cParameter.ZSTD_c_strategy, 2), (Native.libzstd.ZSTD_cParameter.ZSTD_c_hashLog, Math.Max(WindowLog - 7, 0)), (Native.libzstd.ZSTD_cParameter.ZSTD_c_chainLog, Math.Max(WindowLog - 7, 0)) }; } protected override IntPtr CreateStream() { return NativeLibrarySingleton.Instance.ZSTD_createCCtx(); } protected override IntPtr InitializeStream(IntPtr stream) { return IntPtr.Zero; } protected override IntPtr FreeStream(IntPtr stream) { return NativeLibrarySingleton.Instance.ZSTD_freeCStream(stream); } protected override IntPtr SetParameterValue(IntPtr stream, Native.libzstd.ZSTD_cParameter parameter, int value) { return NativeLibrarySingleton.Instance.ZSTD_CCtx_setParameter(stream, parameter, value); } protected override IntPtr GetInputSize() { return NativeLibrarySingleton.Instance.ZSTD_CStreamInSize(); } protected override IntPtr GetOutputSize() { return NativeLibrarySingleton.Instance.ZSTD_CStreamOutSize(); } protected override IntPtr Process(IntPtr stream, ref Native.libzstd.ZSTD_Buffer input, ref Native.libzstd.ZSTD_Buffer output, CoderFlushType flushType) { return NativeLibrarySingleton.Instance.ZSTD_compressStream2(stream, ref output, ref input, (flushType == CoderFlushType.Sync) ? Native.libzstd.ZSTD_EndDirective.ZSTD_e_flush : Native.libzstd.ZSTD_EndDirective.ZSTD_e_continue); } public override IntPtr GetCurrentSize(IntPtr stream) { return NativeLibrarySingleton.Instance.ZSTD_sizeof_CCtx(stream); } }