Class: VibeZstd::DCtx

Inherits:
Object
  • Object
show all
Defined in:
sig/vibe_zstd.rbs,
ext/vibe_zstd/vibe_zstd.c

Overview

Decompression context for reusable decompression operations

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDCtx

Returns a new instance of DCtx.



17
# File 'sig/vibe_zstd.rbs', line 17

def initialize: () -> void

Class Method Details

.default_initial_capacityObject

DCtx default_initial_capacity getter (class method)



181
182
183
184
185
186
187
# File 'ext/vibe_zstd/dctx.c', line 181

static VALUE
vibe_zstd_dctx_get_default_initial_capacity(VALUE self) {
    if (default_initial_capacity == 0) {
        return SIZET2NUM(ZSTD_DStreamOutSize());
    }
    return SIZET2NUM(default_initial_capacity);
}

.default_initial_capacity=(value) ⇒ Object

DCtx default_initial_capacity setter (class method)



190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'ext/vibe_zstd/dctx.c', line 190

static VALUE
vibe_zstd_dctx_set_default_initial_capacity(VALUE self, VALUE value) {
    if (NIL_P(value)) {
        default_initial_capacity = 0;  // Reset to default
    } else {
        size_t capacity = NUM2SIZET(value);
        if (capacity == 0) {
            rb_raise(rb_eArgError, "initial_capacity must be positive (or nil to reset to default)");
        }
        default_initial_capacity = capacity;
    }
    return value;
}

.default_max_decompressed_sizeObject

DCtx default_max_decompressed_size getter (class method); 0 = unlimited



236
237
238
239
# File 'ext/vibe_zstd/dctx.c', line 236

static VALUE
vibe_zstd_dctx_get_default_max_decompressed_size(VALUE self) {
    return SIZET2NUM(default_max_decompressed_size);
}

.default_max_decompressed_size=(value) ⇒ Object

DCtx default_max_decompressed_size setter (class method)



242
243
244
245
246
247
248
249
250
# File 'ext/vibe_zstd/dctx.c', line 242

static VALUE
vibe_zstd_dctx_set_default_max_decompressed_size(VALUE self, VALUE value) {
    if (NIL_P(value)) {
        default_max_decompressed_size = 0;  // unlimited
    } else {
        default_max_decompressed_size = NUM2SIZET(value);
    }
    return value;
}

.estimate_memoryObject

DCtx.estimate_memory()



55
# File 'ext/vibe_zstd/dctx.c', line 55

def self.estimate_memory: () -> Integer

.frame_content_size(data) ⇒ Object

DCtx frame_content_size - class method to get frame content size



461
# File 'ext/vibe_zstd/dctx.c', line 461

def self.frame_content_size: (String data) -> Integer?

.parameter_boundsHash[Symbol, Integer]

Parameters:

Returns:



22
# File 'sig/vibe_zstd.rbs', line 22

def self.parameter_bounds: (Symbol param) -> Hash[Symbol, Integer]

Instance Method Details

#decompress(*args) ⇒ Object

Skippable frames at the beginning of data are automatically skipped.



489
# File 'ext/vibe_zstd/dctx.c', line 489

def decompress: (String data, ?DDict? dict) -> String

#formatObject

#format=Object

#get_parameterInteger

Parameters:

Returns:



20
# File 'sig/vibe_zstd.rbs', line 20

def get_parameter: (Symbol param) -> Integer

#initial_capacityObject

DCtx initial_capacity getter (instance method)



205
206
207
208
209
210
211
212
213
214
215
# File 'ext/vibe_zstd/dctx.c', line 205

static VALUE
vibe_zstd_dctx_get_initial_capacity(VALUE self) {
    vibe_zstd_dctx* dctx;
    TypedData_Get_Struct(self, vibe_zstd_dctx, &vibe_zstd_dctx_type, dctx);

    if (dctx->initial_capacity == 0) {
        // Return the class default
        return vibe_zstd_dctx_get_default_initial_capacity(Qnil);
    }
    return SIZET2NUM(dctx->initial_capacity);
}

#initial_capacity=(value) ⇒ Object

DCtx initial_capacity setter (instance method)



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'ext/vibe_zstd/dctx.c', line 218

static VALUE
vibe_zstd_dctx_set_initial_capacity(VALUE self, VALUE value) {
    vibe_zstd_dctx* dctx;
    TypedData_Get_Struct(self, vibe_zstd_dctx, &vibe_zstd_dctx_type, dctx);

    if (NIL_P(value)) {
        dctx->initial_capacity = 0;  // Use class default
    } else {
        size_t capacity = NUM2SIZET(value);
        if (capacity == 0) {
            rb_raise(rb_eArgError, "initial_capacity must be positive (or nil to use class default)");
        }
        dctx->initial_capacity = capacity;
    }
    return value;
}

#max_decompressed_sizeObject Also known as: max_size

limit, falling back to the class default. Returns 0 when unlimited.



254
255
256
257
258
259
260
261
262
263
# File 'ext/vibe_zstd/dctx.c', line 254

static VALUE
vibe_zstd_dctx_get_max_decompressed_size(VALUE self) {
    vibe_zstd_dctx* dctx;
    TypedData_Get_Struct(self, vibe_zstd_dctx, &vibe_zstd_dctx_type, dctx);

    if (dctx->max_decompressed_size == 0) {
        return SIZET2NUM(default_max_decompressed_size);
    }
    return SIZET2NUM(dctx->max_decompressed_size);
}

#max_decompressed_size=(value) ⇒ Object Also known as: max_size=

DCtx max_decompressed_size setter (instance method); nil = inherit class default



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'ext/vibe_zstd/dctx.c', line 266

static VALUE
vibe_zstd_dctx_set_max_decompressed_size(VALUE self, VALUE value) {
    vibe_zstd_dctx* dctx;
    TypedData_Get_Struct(self, vibe_zstd_dctx, &vibe_zstd_dctx_type, dctx);

    if (NIL_P(value)) {
        dctx->max_decompressed_size = 0;  // inherit class default
    } else {
        size_t limit = NUM2SIZET(value);
        if (limit == 0) {
            rb_raise(rb_eArgError, "max_decompressed_size must be positive (or nil to inherit the class default)");
        }
        dctx->max_decompressed_size = limit;
    }
    return value;
}

#reset(*args) ⇒ Object

DCtx reset - reset context to clean state



698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'ext/vibe_zstd/dctx.c', line 698

static VALUE
vibe_zstd_dctx_reset(int argc, VALUE* argv, VALUE self) {
    VALUE reset_mode;
    rb_scan_args(argc, argv, "01", &reset_mode);

    vibe_zstd_dctx* dctx;
    TypedData_Get_Struct(self, vibe_zstd_dctx, &vibe_zstd_dctx_type, dctx);

    // Default to SESSION_AND_PARAMETERS if no argument provided
    ZSTD_ResetDirective directive = ZSTD_reset_session_and_parameters;

    if (!NIL_P(reset_mode)) {
        int mode = NUM2INT(reset_mode);
        if (mode == ZSTD_reset_session_only) {
            directive = ZSTD_reset_session_only;
        } else if (mode == ZSTD_reset_parameters) {
            directive = ZSTD_reset_parameters;
        } else if (mode == ZSTD_reset_session_and_parameters) {
            directive = ZSTD_reset_session_and_parameters;
        } else {
            rb_raise(rb_eArgError, "Invalid reset_mode %d: must be ResetDirective::SESSION (1), PARAMETERS (2), or BOTH (3)", mode);
        }
    }

    size_t result = ZSTD_DCtx_reset(dctx->dctx, directive);

    if (ZSTD_isError(result)) {
        rb_raise(rb_eRuntimeError, "Failed to reset decompression context: %s", ZSTD_getErrorName(result));
    }

    return self;
}

#set_parameterself

Parameters:

Returns:



19
# File 'sig/vibe_zstd.rbs', line 19

def set_parameter: (Symbol param, Integer value) -> self

#use_prefix(prefix_data) ⇒ Object

DCtx use_prefix - use raw data as prefix (lightweight dictionary)



681
# File 'ext/vibe_zstd/dctx.c', line 681

def use_prefix: (String prefix_data) -> self

#window_log_maxObject Also known as: max_window_log

#window_log_max=Object Also known as: max_window_log=

DCtx parameter accessors