Ejemplo n.º 1
0
    def to_object(self, data):
        """
        Deserialize input data
        :param data: serialized input Data object
        :return: Deserialized object
        """
        if not isinstance(data, Data):
            return data
        if is_null_data(data):
            return None

        inp = self._create_data_input(data)
        try:
            type_id = data.get_type()
            serializer = self._registry.serializer_by_type_id(type_id)
            if serializer is None:
                if self._active:
                    raise HazelcastSerializationError(
                        "Missing Serializer for type-id:{}".format(type_id))
                else:
                    raise HazelcastInstanceNotActiveError()
            return serializer.read(inp)
        except Exception as e:
            handle_exception(e)
        finally:
            pass
Ejemplo n.º 2
0
 def read_object(self, inp):
     try:
         type_id = inp.read_int()
         serializer = self._registry.serializer_by_type_id(type_id)
         if serializer is None:
             if self._active:
                 raise HazelcastSerializationError("Missing Serializer for type-id:{}".format(type_id))
             else:
                 raise HazelcastInstanceNotActiveError()
         return serializer.read(inp)
     except:
         handle_exception(sys.exc_info()[1], sys.exc_info()[2])
Ejemplo n.º 3
0
    def serializer_for(self, obj):
        """
            Searches for a serializer for the provided object
            Serializers will be  searched in this order;

            1-NULL serializer
            2-Default serializers, like primitives, arrays, string and some default types
            3-Custom registered types by user
            4-Global serializer if registered by user
            4-pickle serialization as a fallback

        :param obj: input object
        :return: Serializer
        """
        # 1-NULL serializer
        if obj is None:
            return self._null_serializer

        obj_type = type(obj)

        # 2-Default serializers, Dataserializable, Portable, primitives, arrays, String and some helper types(BigInteger etc)
        serializer = self.lookup_default_serializer(obj_type, obj)

        # 3-Custom registered types by user
        if serializer is None:
            serializer = self.lookup_custom_serializer(obj_type)

        # 5-Global serializer if registered by user
        if serializer is None:
            serializer = self.lookup_global_serializer(obj_type)

        # 4 Internal serializer
        if serializer is None:
            serializer = self.lookup_python_serializer(obj_type)

        if serializer is None:
            if self._active:
                raise HazelcastSerializationError(
                    "There is no suitable serializer for:" + str(obj_type))
            else:
                raise HazelcastInstanceNotActiveError()
        return serializer