Class: TypeDeserializer
- Inherits:
-
Object
- Object
- TypeDeserializer
- Defined in:
- lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb
Class Method Summary collapse
- .deserialize_bool(encoded_bool) ⇒ Object
- .deserialize_byte(encoded_byte) ⇒ Object
- .deserialize_char(encoded_char) ⇒ Object
- .deserialize_command(command_byte_array) ⇒ Object
- .deserialize_double(encoded_double) ⇒ Object
- .deserialize_float(encoded_float) ⇒ Object
- .deserialize_int(encoded_int) ⇒ Object
- .deserialize_longlong(encoded_long) ⇒ Object
- .deserialize_nil(_encoded_nil) ⇒ Object
- .deserialize_string(string_encoding_mode, encoded_string) ⇒ Object
- .deserialize_uint(encoded_uint) ⇒ Object
- .deserialize_ullong(encoded_ullong) ⇒ Object
Class Method Details
.deserialize_bool(encoded_bool) ⇒ Object
30 31 32 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 30 def self.deserialize_bool(encoded_bool) encoded_bool[0] == 1 end |
.deserialize_byte(encoded_byte) ⇒ Object
38 39 40 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 38 def self.deserialize_byte(encoded_byte) encoded_byte.pack('C*').unpack1('C') # or simply encoded_byte[0] end |
.deserialize_char(encoded_char) ⇒ Object
42 43 44 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 42 def self.deserialize_char(encoded_char) encoded_char.pack('C*').unpack1('C') # returns codepoint 0..255 end |
.deserialize_command(command_byte_array) ⇒ Object
4 5 6 7 8 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 4 def self.deserialize_command(command_byte_array) Command.new(RuntimeNameJavonet(command_byte_array[0]), CommandType(command_byte_array[1]), []) end |
.deserialize_double(encoded_double) ⇒ Object
50 51 52 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 50 def self.deserialize_double(encoded_double) encoded_double.pack('C*').unpack1('E') # 64-bit double LE (IEEE-754) end |
.deserialize_float(encoded_float) ⇒ Object
34 35 36 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 34 def self.deserialize_float(encoded_float) encoded_float.pack('C*').unpack1('e') # 32-bit float LE (IEEE-754) end |
.deserialize_int(encoded_int) ⇒ Object
26 27 28 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 26 def self.deserialize_int(encoded_int) encoded_int.pack('C*').unpack1('l<') # 32-bit signed LE end |
.deserialize_longlong(encoded_long) ⇒ Object
46 47 48 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 46 def self.deserialize_longlong(encoded_long) encoded_long.pack('C*').unpack1('q<') # 64-bit signed LE end |
.deserialize_nil(_encoded_nil) ⇒ Object
62 63 64 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 62 def self.deserialize_nil(_encoded_nil) nil end |
.deserialize_string(string_encoding_mode, encoded_string) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 10 def self.deserialize_string(string_encoding_mode, encoded_string) raw = encoded_string.pack('C*') case string_encoding_mode when StringEncodingModeJavonet::ASCII raw.force_encoding('US-ASCII').encode('UTF-8') when StringEncodingModeJavonet::UTF8 raw.force_encoding('UTF-8').encode('UTF-8') when StringEncodingModeJavonet::UTF16 raw.force_encoding('UTF-16LE').encode('UTF-8') when StringEncodingModeJavonet::UTF32 raw.force_encoding('UTF-32').encode('UTF-8') else raise 'Argument out of range in deserialize_string' end end |
.deserialize_uint(encoded_uint) ⇒ Object
58 59 60 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 58 def self.deserialize_uint(encoded_uint) encoded_uint.pack('C*').unpack1('L<') # 32-bit unsigned LE end |
.deserialize_ullong(encoded_ullong) ⇒ Object
54 55 56 |
# File 'lib/javonet-ruby-sdk/core/protocol/type_deserializer.rb', line 54 def self.deserialize_ullong(encoded_ullong) encoded_ullong.pack('C*').unpack1('Q<') # 64-bit unsigned LE end |