Class: TypeSerializer

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

Class Method Summary collapse

Class Method Details

.serialize_bool(bool_value) ⇒ Object



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

def self.serialize_bool(bool_value)
  encoded_bool_list = bool_value ? [1] : [0]
  length = encoded_bool_list.length
  return [Type::JAVONET_BOOLEAN, length] + encoded_bool_list
end

.serialize_byte(byte_value) ⇒ Object



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

def self.serialize_byte(byte_value)
  encoded_byte_list = [byte_value].pack("c").bytes
  length = encoded_byte_list.length
  return [Type::JAVONET_BYTE, length] + encoded_byte_list
end

.serialize_char(char_value) ⇒ Object



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

def self.serialize_char(char_value)
  encoded_char_list = [char_value].pack("c").bytes
  length = encoded_char_list.length
  return [Type::JAVONET_CHAR, length] + encoded_char_list
end

.serialize_command(command) ⇒ Object



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

def self.serialize_command(command)
  length = [command.payload.length].pack("i").bytes
  return [Type::COMMAND] + length + [command.runtime_name, command.command_type]
end

.serialize_double(double_value) ⇒ Object



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

def self.serialize_double(double_value)
  encoded_double_list = [double_value].pack("d").bytes
  length = encoded_double_list.length
  return [Type::JAVONET_DOUBLE, length] + encoded_double_list
end

.serialize_float(float_value) ⇒ Object



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

def self.serialize_float(float_value)
  encoded_float_list = [float_value].pack("f").bytes
  length = encoded_float_list.length
  return [Type::JAVONET_FLOAT, length] + encoded_float_list
end

.serialize_int(int_value) ⇒ Object



17
18
19
20
21
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 17

def self.serialize_int(int_value)
  encoded_int_list = [int_value].pack("i").bytes
  length = encoded_int_list.length
  return [Type::JAVONET_INTEGER, length] + encoded_int_list
end

.serialize_longlong(longlong_value) ⇒ Object



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

def self.serialize_longlong(longlong_value)
  encoded_longlong_list = [longlong_value].pack("q").bytes
  length = encoded_longlong_list.length
  return [Type::JAVONET_LONG_LONG, length] + encoded_longlong_list
end

.serialize_nilObject



71
72
73
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 71

def self.serialize_nil
  return [Type::JAVONET_NULL, 1, 0]
end

.serialize_string(string_value) ⇒ Object



11
12
13
14
15
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 11

def self.serialize_string(string_value)
  encoded_string_list = string_value.bytes
  length = [encoded_string_list.length].pack("i").bytes
  return [Type::JAVONET_STRING, StringEncodingMode::UTF8] + length + encoded_string_list
end

.serialize_uint(uint_value) ⇒ Object



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

def self.serialize_uint(uint_value)
  encoded_uint_list = [uint_value].pack("I").bytes
  length = encoded_uint_list.length
  return [Type::JAVONET_UNSIGNED_INTEGER, length] + encoded_uint_list
end

.serialize_ullong(ullong_value) ⇒ Object



65
66
67
68
69
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 65

def self.serialize_ullong(ullong_value)
  encoded_ullong_list = [ullong_value].pack("Q").bytes
  length = encoded_ullong_list.length
  return [Type::JAVONET_UNSIGNED_LONG_LONG, length] + encoded_ullong_list
end