Skip to content

struct Athena::Serializer::Serializer
inherits Struct #

Default implementation of ASR::SerializerInterface.

Provides the main API used to (de)serialize objects.

Custom formats can be implemented by creating the required visitors for that type, then overriding #get_deserialization_visitor_class and #get_serialization_visitor_class.

# Redefine the visitor class getters in order to first check for custom formats.
# This assumes these visitor types are defined, with the proper logic to handle
# the (de)serialization process.
struct Athena::Serializer::Serializer
  protected def get_deserialization_visitor_class(format : ASR::Format | String)
    return MessagePackDeserializationVisitor if format == "message_pack"

    previous_def
  end

  protected def get_serialization_visitor_class(format : ASR::Format | String)
    return MessagePackSerializationVisitor if format == "message_pack"

    previous_def
  end
end

Included modules

Athena::Serializer::SerializerInterface

Class methods#

.new(navigator_factory : ASR::Navigators::NavigatorFactoryInterface = ASR::Navigators::NavigatorFactory.new) #

View source

Methods#

#deserialize(type : _, input_data : String | IO, format : ASR::Format | String, context : ASR::DeserializationContext = ASR::DeserializationContext.new) #

:inherit:

View source

#serialize(data : _, format : ASR::Format | String, io : IO, context : ASR::SerializationContext = ASR::SerializationContext.new, **named_args) : Nil #

Serializes the provided data into format writing it to the provided io, optionally with the provided context.=

View source

#serialize(data : _, format : ASR::Format | String, context : ASR::SerializationContext = ASR::SerializationContext.new, **named_args) : String #

Serializes the provided data into format, optionally with the provided context.

View source