Class: TypeSerializer
- Inherits:
-
Object
- Object
- TypeSerializer
- 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
- .serialize_bool(bool_value) ⇒ Object
- .serialize_byte(byte_value) ⇒ Object
- .serialize_char(char_value) ⇒ Object
- .serialize_command(command) ⇒ Object
- .serialize_double(double_value) ⇒ Object
- .serialize_float(float_value) ⇒ Object
- .serialize_int(int_value) ⇒ Object
- .serialize_longlong(longlong_value) ⇒ Object
- .serialize_nil ⇒ Object
- .serialize_primitive(payload_item) ⇒ Object
- .serialize_string(string_value) ⇒ Object
- .serialize_uint(uint_value) ⇒ Object
- .serialize_ullong(ullong_value) ⇒ Object
Class Method Details
.serialize_bool(bool_value) ⇒ Object
46 47 48 49 50 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 46 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
58 59 60 61 62 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 58 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
64 65 66 67 68 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 64 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
29 30 31 32 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 29 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
76 77 78 79 80 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 76 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
52 53 54 55 56 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 52 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
40 41 42 43 44 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 40 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
70 71 72 73 74 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 70 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_nil ⇒ Object
94 95 96 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 94 def self.serialize_nil return [Type::JAVONET_NULL, 1, 0] end |
.serialize_primitive(payload_item) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 6 def self.serialize_primitive(payload_item) if payload_item.nil? return TypeSerializer.serialize_nil elsif [true, false].include? payload_item return TypeSerializer.serialize_bool(payload_item) elsif payload_item.is_a? Integer if (-2 ** 31..2 ** 31).include?(payload_item) return TypeSerializer.serialize_int(payload_item) elsif (-2 ** 63..2 ** 63).include?(payload_item) return TypeSerializer.serialize_longlong(payload_item) else return TypeSerializer.serialize_ullong(payload_item) end elsif payload_item.is_a? String return TypeSerializer.serialize_string(payload_item) elsif payload_item.is_a? Float return TypeSerializer.serialize_double(payload_item) elsif payload_item.is_a? else raise Exception.new("Payload not supported in command serializer") end end |
.serialize_string(string_value) ⇒ Object
34 35 36 37 38 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 34 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
82 83 84 85 86 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 82 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
88 89 90 91 92 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_serializer.rb', line 88 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 |