Class: TypeDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/protocol/type_deserializer.rb

Class Method Summary collapse

Class Method Details

.deserialize_bool(encoded_bool) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 49

def self.deserialize_bool(encoded_bool)
  if encoded_bool[0] == 1
    bool_value = true
  else
    bool_value = false
  end

  return bool_value
end

.deserialize_command(command_byte_array) ⇒ Object

def self.deserialize_char(encoded_char)

char_value = struct.unpack("<c", bytearray(encoded_char))[0]
return char_value

end

def self.deserialize_bytes(encoded_bytes)

bytes_value = struct.unpack("<c", bytearray(encoded_bytes))[0]
return bytes_value

end



69
70
71
72
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 69

def self.deserialize_command(command_byte_array)
  python_command = RubyCommand.new(RuntimeLib(command_byte_array[0]), RubyCommandType(command_byte_array[1]), [])
  return python_command
end

.deserialize_double(encoded_double) ⇒ Object



21
22
23
24
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 21

def self.deserialize_double(encoded_double)
  double_value = encoded_double.map(&:chr).join.unpack('d').first
  return double_value
end

.deserialize_float(encoded_float) ⇒ Object



44
45
46
47
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 44

def self.deserialize_float(encoded_float)
  float_value = encoded_float.map(&:chr).join.unpack('f').first
  return float_value
end

.deserialize_int(encoded_int) ⇒ Object



5
6
7
8
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 5

def self.deserialize_int(encoded_int)
  int_value = encoded_int.map(&:chr).join.unpack('i').first
  return int_value
end

.deserialize_string(string_encoding_mode, encoded_string) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 26

def self.deserialize_string(string_encoding_mode, encoded_string)

  case string_encoding_mode
  when StringEncodingMode::ASCII
      string_value = encoded_string.pack('C*').force_encoding("US-ASCII").encode("UTF-8")
  when StringEncodingMode::UTF8
      string_value = encoded_string.pack("C*").force_encoding("UTF-8").encode("UTF-8")
  when StringEncodingMode::UTF16
      string_value = encoded_string.pack("C*").force_encoding("UTF-16LE").encode("UTF-8")
  when StringEncodingMode::UTF32
      string_value = encoded_string.pack("C*").force_encoding("UTF-32").encode("UTF-8")
  else
      raise "Argument out of range in deserialize_string"
  end

  return string_value
end