Module: CLValueBytesParsers::CLStringBytesParser

Extended by:
CLStringBytesParser
Included in:
CLString, CLStringBytesParser
Defined in:
lib/serialization/cl_value_bytes_parsers.rb

Instance Method Summary collapse

Instance Method Details

#from_bytes(raw_bytes) ⇒ Object

Parameters:

  • raw_bytes (String)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 33

def from_bytes(raw_bytes)
  first_4_bytes = raw_bytes[0..7]
  string_length = [first_4_bytes].pack("H*").unpack("l").first
  rest = raw_bytes[8..raw_bytes.length]
  len2 = (rest.length) / 2
  if string_length == len2
    hex_to_string_value = [raw_bytes[8..raw_bytes.length]].pack("H*")
  else
    raise "Error"
  end
end

#from_jsonObject



56
57
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 56

def from_json
end

#to_bytes(value) ⇒ Object

Parameters:

  • value (String)


46
47
48
49
50
51
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 46

def to_bytes(value)
  len = value.length
  hex1 = len.to_s(16).rjust(8, '0').scan(/../).reverse.join('')
  hex2 = value.unpack("H*").first
  hex1 + hex2
end

#to_jsonObject



53
54
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 53

def to_json 
end