Module: CLValueBytesParsers::CLURefBytesParser

Extended by:
CLURefBytesParser
Included in:
CLURef, CLURefBytesParser
Defined in:
lib/serialization/cl_value_bytes_parsers.rb

Instance Method Summary collapse

Instance Method Details

#decode_base_16(str) ⇒ Array<Integer>

Returns decoded.

Parameters:

  • str (String)

Returns:

  • (Array<Integer>)

    decoded



282
283
284
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 282

def decode_base_16(str)
  decoded = [str].pack('H*').unpack("C*")
end

#encode_base_16(byte_array) ⇒ String

Returns encoded.

Parameters:

  • byte_array (Array<Integer>)

Returns:

  • (String)

    encoded



288
289
290
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 288

def encode_base_16(byte_array)
  encoded = byte_array.pack("C*").unpack("H*").first
end

#from_bytes(byte_array) ⇒ CLURef

Returns uref.

Parameters:

  • byte_array (Array<Integer>)

Returns:



303
304
305
306
307
308
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 303

def from_bytes(byte_array)
  get_access_rights = byte_array.last
  byte_array = byte_array[0..byte_array.size-2]
  # p byte_array
  uref = CLURef.new(byte_array, get_access_rights)
end

#to_bytes(clvalue) ⇒ Array<Integer>

Returns value.

Parameters:

Returns:

  • (Array<Integer>)

    value



294
295
296
297
298
299
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 294

def to_bytes(clvalue)
  value = clvalue.get_value
  access_rights = clvalue.get_access_rights
  value = value.dup
  value.push(access_rights)
end