Class: CommandDeserializer
- Inherits:
-
Object
- Object
- CommandDeserializer
- Defined in:
- lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/command_deserializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/command_deserializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/protocol/command_deserializer.rb
Instance Method Summary collapse
- #deserialize ⇒ Object
-
#initialize(buffer, byte_array_len) ⇒ CommandDeserializer
constructor
A new instance of CommandDeserializer.
- #is_at_end ⇒ Object
- #read_bool ⇒ Object
- #read_byte ⇒ Object
- #read_char ⇒ Object
- #read_command ⇒ Object
- #read_command_recursively(number_of_elements_in_payload_left, cmd) ⇒ Object
- #read_double ⇒ Object
- #read_float ⇒ Object
- #read_int ⇒ Object
- #read_longlong ⇒ Object
- #read_nil ⇒ Object
-
#read_object(type_num) ⇒ Object
def copy_from(self, bytes_to_copy, elements_to_skip): size = len(bytes_to_copy) - elements_to_skip new_byte_array = bytes_to_copy return new_byte_array.
- #read_string ⇒ Object
- #read_uint ⇒ Object
- #read_ullong ⇒ Object
Constructor Details
#initialize(buffer, byte_array_len) ⇒ CommandDeserializer
Returns a new instance of CommandDeserializer.
8 9 10 11 12 13 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 8 def initialize(buffer, byte_array_len) @buffer = buffer @byte_array_len = byte_array_len @command = Command.new(buffer[0], buffer[10], []) @position = 11 end |
Instance Method Details
#deserialize ⇒ Object
19 20 21 22 23 24 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 19 def deserialize until is_at_end @command = @command.add_arg_to_payload(read_object(@buffer[@position])) end @command end |
#is_at_end ⇒ Object
15 16 17 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 15 def is_at_end @position == @byte_array_len end |
#read_bool ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 100 def read_bool size = 1 @position += 2 p = @position @position += size TypeDeserializer.deserialize_bool(@buffer[p..p + size]) end |
#read_byte ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 116 def read_byte size = 1 @position += 2 p = @position @position += size TypeDeserializer.deserialize_byte(@buffer[p..p + size]) end |
#read_char ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 124 def read_char size = 1 @position += 2 p = @position @position += size TypeDeserializer.deserialize_char(@buffer[p..p + size]) end |
#read_command ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 62 def read_command p = @position number_of_elements_in_payload = TypeDeserializer.deserialize_int(@buffer[p + 1..p + 4]) runtime = @buffer[p + 5] command_type = @buffer[p + 6] @position += 7 return_command = Command.new(runtime, command_type, []) read_command_recursively(number_of_elements_in_payload, return_command) end |
#read_command_recursively(number_of_elements_in_payload_left, cmd) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 72 def read_command_recursively(number_of_elements_in_payload_left, cmd) if number_of_elements_in_payload_left == 0 cmd else p = @position cmd = cmd.add_arg_to_payload(self.read_object(@buffer[p])) read_command_recursively(number_of_elements_in_payload_left - 1, cmd) end end |
#read_double ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 140 def read_double size = 8 @position += 2 p = @position @position += size TypeDeserializer.deserialize_double(@buffer[p..p + size - 1]) end |
#read_float ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 108 def read_float size = 4 @position += 2 p = @position @position += size TypeDeserializer.deserialize_float(@buffer[p..p + size - 1]) end |
#read_int ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 92 def read_int size = 4 @position += 2 p = @position @position += size TypeDeserializer.deserialize_int(@buffer[p..p + size - 1]) end |
#read_longlong ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 132 def read_longlong size = 8 @position += 2 p = @position @position += size TypeDeserializer.deserialize_longlong(@buffer[p..p + size - 1]) end |
#read_nil ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 164 def read_nil size = 1 @position += 2 p = @position @position += size TypeDeserializer.deserialize_nil(@buffer[p..p + size]) end |
#read_object(type_num) ⇒ Object
def copy_from(self, bytes_to_copy, elements_to_skip):
size = len(bytes_to_copy) - elements_to_skip
new_byte_array = bytes_to_copy[size]
return new_byte_array
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 31 def read_object(type_num) case type_num when Type::COMMAND return self.read_command when Type::JAVONET_STRING return self.read_string when Type::JAVONET_INTEGER return self.read_int when Type::JAVONET_BOOLEAN return self.read_bool when Type::JAVONET_FLOAT return self.read_float when Type::JAVONET_BYTE return self.read_byte when Type::JAVONET_CHAR return self.read_char when Type::JAVONET_LONG_LONG return self.read_longlong when Type::JAVONET_DOUBLE return self.read_double when Type::JAVONET_UNSIGNED_LONG_LONG return self.read_ullong when Type::JAVONET_UNSIGNED_INTEGER return self.read_uint when Type::JAVONET_NULL return self.read_nil else raise Exception.new("Type #{type_num} not supported in command deserializer") end end |
#read_string ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 82 def read_string p = @position string_encoding_mode = @buffer[p + 1] size = TypeDeserializer.deserialize_int(@buffer[p + 2..p + 5]) @position += 6 p = @position @position += size TypeDeserializer.deserialize_string(string_encoding_mode, @buffer[p..p + size - 1]) end |
#read_uint ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 156 def read_uint size = 4 @position += 2 p = @position @position += size TypeDeserializer.deserialize_uint(@buffer[p..p + size - 1]) end |
#read_ullong ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/javonet-ruby-sdk/core/protocol/command_deserializer.rb', line 148 def read_ullong size = 8 @position += 2 p = @position @position += size TypeDeserializer.deserialize_ullong(@buffer[p..p + size - 1]) end |