Class: BinaryCodec::Int64
- Inherits:
-
Uint
- Object
- SerializedType
- ComparableSerializedType
- Uint
- BinaryCodec::Int64
- Defined in:
- lib/binary-codec/types/uint.rb
Instance Attribute Summary
Attributes inherited from SerializedType
Class Method Summary collapse
-
.from(value) ⇒ Int64
Creates a new Int64 instance from a value.
Instance Method Summary collapse
-
#value_of ⇒ Integer
Returns the numeric value of the Int64.
Methods inherited from Uint
#compare_to, from_parser, #initialize, width
Methods inherited from ComparableSerializedType
#compare_to, #eq, #gt, #gte, #lt, #lte
Methods inherited from SerializedType
from_bytes, from_hex, from_json, from_parser, get_type_by_name, #initialize, #to_byte_sink, #to_bytes, #to_hex, #to_json
Constructor Details
This class inherits a constructor from BinaryCodec::Uint
Class Method Details
.from(value) ⇒ Int64
Creates a new Int64 instance from a value.
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/binary-codec/types/uint.rb', line 153 def self.from(value) return value if value.is_a?(self) if value.is_a?(Integer) if value < -9223372036854775808 || value > 9223372036854775807 raise StandardError, "Value #{value} out of range for Int64" end u_val = value < 0 ? value + 0x10000000000000000 : value return new(int_to_bytes(u_val, 8)) end super(value) end |
Instance Method Details
#value_of ⇒ Integer
Returns the numeric value of the Int64.
145 146 147 148 |
# File 'lib/binary-codec/types/uint.rb', line 145 def value_of val = super val > 0x7FFFFFFFFFFFFFFF ? val - 0x10000000000000000 : val end |