Module: CLValueBytesParsers::CLU128BytesParser
- Extended by:
- CLU128BytesParser
- Included in:
- CLU128BytesParser, CLu128
- Defined in:
- lib/serialization/cl_value_bytes_parsers.rb
Instance Method Summary collapse
Instance Method Details
#from_bytes(byte_array) ⇒ Object
162 163 164 |
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 162 def from_bytes(byte_array) byte_array.reverse.inject(0) {|m, b| (m << 8) + b } end |
#to_bytes(value) ⇒ Object
166 167 168 169 170 171 172 173 174 |
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 166 def to_bytes(value) if value < 0 || value > MAX_U128 "Parameter value '#{value}' is out of range." else str = value.to_s(16) arr = str.scan(/[0-9a-f]{4}/).map { |x| x.to_i(16) } packed = arr.pack("n*").unpack("C*").reverse() end end |