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



29
30
31
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 29

def self.deserialize_bool(encoded_bool)
  encoded_bool[0] == 1
end

.deserialize_byte(encoded_byte) ⇒ Object



37
38
39
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 37

def self.deserialize_byte(encoded_byte)
  encoded_byte[0]
end

.deserialize_char(encoded_char) ⇒ Object



41
42
43
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 41

def self.deserialize_char(encoded_char)
  encoded_char[0].ord
end

.deserialize_command(command_byte_array) ⇒ Object



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

def self.deserialize_command(command_byte_array)
  Command.new(RuntimeName(command_byte_array[0]), CommandType(command_byte_array[1]), [])
end

.deserialize_double(encoded_double) ⇒ Object



49
50
51
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 49

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

.deserialize_float(encoded_float) ⇒ Object



33
34
35
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 33

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

.deserialize_int(encoded_int) ⇒ Object



25
26
27
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 25

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

.deserialize_longlong(encoded_long) ⇒ Object



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

def self.deserialize_longlong(encoded_long)
  encoded_long.map(&:chr).join.unpack('q').first
end

.deserialize_nil(encoded_nil) ⇒ Object



61
62
63
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 61

def self.deserialize_nil(encoded_nil)
  nil
end

.deserialize_string(string_encoding_mode, encoded_string) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 9

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

end

.deserialize_uint(encoded_uint) ⇒ Object



57
58
59
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 57

def self.deserialize_uint(encoded_uint)
  encoded_uint.map(&:chr).join.unpack('I').first
end

.deserialize_ullong(encoded_ullong) ⇒ Object



53
54
55
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 53

def self.deserialize_ullong(encoded_ullong)
  encoded_ullong.map(&:chr).join.unpack('Q').first
end