Sha256: d24c5bef1e02ab6a10e705cc804b0e466e000e1900b221977e36ba1a940fafda

Contents?: true

Size: 1.69 KB

Versions: 24

Compression:

Stored size: 1.69 KB

Contents

require_relative '../../utils/string_encoding_mode'

class TypeDeserializer

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

  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

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

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

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

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

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

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

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

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

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

  def self.deserialize_nil(encoded_nil)
    nil
  end

end

Version data entries

24 entries across 12 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/type_deserializer.rb
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/type_deserializer.rb