Class: RLZ4::FrameCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/rlz4/frame_codec.rb

Class Method Summary collapse

Class Method Details

.new(dict: nil) ⇒ Object

Frame-format LZ4 codec, optionally dict-bound. Parallel in shape to BlockCodec, but emits a real LZ4 frame (magic ‘04 22 4D 18`) with the FLG.DictID bit set and `Dict_ID` written into the FrameDescriptor when a dict is installed. Output is interoperable with the reference `lz4` CLI given the same dictionary file.

Unlike BlockCodec, FrameCodec holds no thread-local mutable state: it’s a read-only dict bytes buffer plus a derived id. Shareable across Ractors.

Parameters:

  • dict (Dictionary, String, nil) (defaults to: nil)

    dictionary bytes or a Dictionary value. Passing a Dictionary reuses its cached id (skips the sha256 digest); a raw String derives the id on the fly.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rlz4/frame_codec.rb', line 21

def self.new(dict: nil)
  case dict
  when nil
    _native_new(nil, 0)
  when Dictionary
    _native_new(dict.bytes, dict.id)
  when String
    _native_new(dict, Dictionary.new(bytes: dict).id)
  else
    raise TypeError, "expected RLZ4::Dictionary, String, or nil; got #{dict.class}"
  end
end