Class: BinaryCodec::Hash128
- Inherits:
-
Hash
- Object
- SerializedType
- ComparableSerializedType
- Hash
- BinaryCodec::Hash128
- Defined in:
- lib/binary-codec/types/hash.rb
Class Attribute Summary collapse
-
.width ⇒ Object
readonly
Returns the value of attribute width.
-
.zero_128 ⇒ Object
readonly
Returns the value of attribute zero_128.
Attributes inherited from SerializedType
Instance Method Summary collapse
-
#initialize(bytes = nil) ⇒ Hash128
constructor
A new instance of Hash128.
- #to_hex ⇒ Object
Methods inherited from Hash
#compare_to, from, from_parser, #nibblet
Methods inherited from ComparableSerializedType
#compare_to, #eq, #gt, #gte, #lt, #lte
Methods inherited from SerializedType
from, from_bytes, from_hex, from_json, from_parser, get_type_by_name, #to_byte_sink, #to_bytes, #to_json, #to_s
Constructor Details
#initialize(bytes = nil) ⇒ Hash128
Returns a new instance of Hash128.
51 52 53 54 |
# File 'lib/binary-codec/types/hash.rb', line 51 def initialize(bytes = nil) bytes = self.class.zero_128 if bytes&.empty? super(bytes, self.class.width) end |
Class Attribute Details
.width ⇒ Object (readonly)
Returns the value of attribute width.
48 49 50 |
# File 'lib/binary-codec/types/hash.rb', line 48 def width @width end |
.zero_128 ⇒ Object (readonly)
Returns the value of attribute zero_128.
48 49 50 |
# File 'lib/binary-codec/types/hash.rb', line 48 def zero_128 @zero_128 end |
Instance Method Details
#to_hex ⇒ Object
56 57 58 59 60 |
# File 'lib/binary-codec/types/hash.rb', line 56 def to_hex hex = bytes_to_hex(to_bytes) return '' if hex.match?(/^0+$/) hex end |