Class: RLZ4::Dictionary

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

Overview

Pure value type for an LZ4 dictionary: raw bytes plus a 4-byte id. Built on ‘Data.define`, so it’s immutable, gets ‘==` / `#hash` / `#deconstruct` for free, and is shareable across Ractors.

The id defaults to ‘sha256(bytes)[0, 4]` interpreted little-endian — the same derivation LZ4 frame FLG.DictID uses. Callers can pass their own id (e.g. a value coordinated out of band) via `id:`.

The id is load-bearing in the frame format (FrameCodec writes it into the FrameDescriptor); BlockCodec accepts a Dictionary for API symmetry but doesn’t consult the id.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes:, id: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V")) ⇒ Dictionary

Returns a new instance of Dictionary.



18
19
20
# File 'lib/rlz4/dictionary.rb', line 18

def initialize(bytes:, id: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V"))
  super(bytes: bytes.b.freeze, id: id)
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes

Returns:

  • (Object)

    the current value of bytes



17
18
19
# File 'lib/rlz4/dictionary.rb', line 17

def bytes
  @bytes
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



17
18
19
# File 'lib/rlz4/dictionary.rb', line 17

def id
  @id
end

Instance Method Details

#sizeObject



23
24
25
# File 'lib/rlz4/dictionary.rb', line 23

def size
  bytes.bytesize
end