struct Athena::Serializer::Serializer

Overview

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

Defined in:

serializer.cr

Constructors

Instance Method Summary

Instance methods inherited from module Athena::Serializer::SerializerInterface

deserialize(type : ASR::Model.class, data : String | IO, format : ASR::Format | String, context : ASR::DeserializationContext = ASR::DeserializationContext.new) deserialize, serialize(data : _, format : ASR::Format | String, io : IO, context : ASR::SerializationContext = ASR::SerializationContext.new, **named_args) : Nil
serialize(data : _, format : ASR::Format | String, context : ASR::SerializationContext = ASR::SerializationContext.new, **named_args) : String
serialize

Constructor Detail

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

[View source]

Instance Method Detail

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

:inherit:


[View source]
def 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]
def 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]