Class: Zrip::Dictionary
- Inherits:
-
Data
- Object
- Data
- Zrip::Dictionary
- Defined in:
- lib/zrip/dictionary.rb,
lib/zrip/dictionary.rb
Overview
Immutable Zstandard dictionary value.
Constant Summary collapse
- ZDICT_MAGIC =
"\x37\xA4\x30\xEC".b.freeze
- USER_DICT_ID_MIN =
32_768- USER_DICT_ID_MAX =
(2**31) - 1
- USER_DICT_ID_SIZE =
USER_DICT_ID_MAX - USER_DICT_ID_MIN + 1
Instance Attribute Summary collapse
-
#bytes ⇒ String
readonly
Frozen binary dictionary bytes.
-
#id ⇒ Integer
readonly
Dictionary ID.
Instance Method Summary collapse
-
#initialize(bytes:, id: nil) ⇒ Dictionary
constructor
A new instance of Dictionary.
-
#size ⇒ Integer
Dictionary size in bytes.
Constructor Details
#initialize(bytes:, id: nil) ⇒ Dictionary
Returns a new instance of Dictionary.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/zrip/dictionary.rb', line 24 def initialize(bytes:, id: nil) b = bytes.b id ||= if b.byteslice(0, 4) == ZDICT_MAGIC b.byteslice(4, 4).unpack1("V") else raw = Digest::SHA256.digest(b).byteslice(0, 4).unpack1("V") USER_DICT_ID_MIN + (raw % USER_DICT_ID_SIZE) end super(bytes: b.freeze, id: id) end |
Instance Attribute Details
#bytes ⇒ String (readonly)
Returns frozen binary dictionary bytes.
13 |
# File 'lib/zrip/dictionary.rb', line 13 Dictionary = Data.define(:bytes, :id) |
#id ⇒ Integer (readonly)
Returns dictionary ID.
13 |
# File 'lib/zrip/dictionary.rb', line 13 Dictionary = Data.define(:bytes, :id) |
Instance Method Details
#size ⇒ Integer
Returns dictionary size in bytes.
37 38 39 |
# File 'lib/zrip/dictionary.rb', line 37 def size bytes.bytesize end |