Module: CLValueBytesParsers::CLU32BytesParser

Extended by:
CLU32BytesParser
Included in:
CLU32BytesParser, CLu32
Defined in:
lib/serialization/cl_value_bytes_parsers.rb

Instance Method Summary collapse

Instance Method Details

#from_bytes(byte_array) ⇒ Object



132
133
134
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 132

def from_bytes(byte_array)
    byte_array.reverse.inject(0) {|m, b| (m << 8) + b }
end

#to_bytes(value) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 136

def to_bytes(value)
  if value < 0 || value > MAX_U32
    "Parameter value '#{value}' is out of range."
  else
    [value].pack("L<*").unpack("C*")
  end
end