Class: RLZ4::Dictionary
- Inherits:
-
Data
- Object
- Data
- RLZ4::Dictionary
- 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
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(bytes:, id: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V")) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #size ⇒ Object
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
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes
17 18 19 |
# File 'lib/rlz4/dictionary.rb', line 17 def bytes @bytes end |
#id ⇒ Object (readonly)
Returns the value of attribute id
17 18 19 |
# File 'lib/rlz4/dictionary.rb', line 17 def id @id end |
Instance Method Details
#size ⇒ Object
23 24 25 |
# File 'lib/rlz4/dictionary.rb', line 23 def size bytes.bytesize end |