import struct from javonet.utils import Command, CommandType, RuntimeName from javonet.utils.StringEncodingMode import StringEncodingMode class TypeDeserializer: @staticmethod def deserialize_command(encoded_command ): return Command(RuntimeName(encoded_command[0]), CommandType(encoded_command[1]), []) @staticmethod def deserialize_string(string_encoding_mode, encoded_string): if string_encoding_mode == StringEncodingMode.ASCII: return bytearray(encoded_string).decode('ascii') if string_encoding_mode == StringEncodingMode.UTF8: return bytearray(encoded_string).decode('utf-8') if string_encoding_mode == StringEncodingMode.UTF16: return bytearray(encoded_string).decode('utf-16') if string_encoding_mode == StringEncodingMode.UTF32: return bytearray(encoded_string).decode('utf-32') raise IndexError("String encoding mode out of range") @staticmethod def deserialize_int(encoded_int): return struct.unpack("