Jido.Signal.Serialization.Serializer behaviour (Jido Signal v1.0.0)
View SourceBehaviour for serialization strategies.
This behavior defines a common interface for different serialization formats such as JSON, Erlang Term format, and MessagePack.
Implementation Examples
defmodule MySerializer do
@behaviour Jido.Signal.Serialization.Serializer
def serialize(data, _opts \ []) do
# Your serialization logic here
{:ok, serialized_data}
end
def deserialize(binary, opts \ []) do
# Your deserialization logic here
{:ok, deserialized_data}
end
end
Configuration
The default serializer can be configured in your application config:
config :jido, :default_serializer, MySerializer
You can also override the serializer per operation by passing the :serializer
option:
Signal.serialize(signal, serializer: MySerializer)
Signal.deserialize(binary, serializer: MySerializer)
Summary
Callbacks
Deserialize the given binary data back to the original format.
Serialize the given term to binary format.
Functions
Get the configured default serializer.
Deserialize data using the specified or default serializer.
Serialize data using the specified or default serializer.
Types
Callbacks
@callback deserialize(serialized(), opts()) :: result()
Deserialize the given binary data back to the original format.
Parameters
binary
- The serialized binary dataopts
- Optional configuration (e.g., type information, type provider)
Returns
{:ok, term}
- Success with deserialized data{:error, reason}
- Failure with reason
@callback serialize(serializable(), opts()) :: {:ok, serialized()} | {:error, term()}
Serialize the given term to binary format.
Parameters
data
- The data to serializeopts
- Optional configuration (e.g., type information)
Returns
{:ok, binary}
- Success with serialized binary{:error, reason}
- Failure with reason
Functions
@spec default_serializer() :: module()
Get the configured default serializer.
@spec deserialize(serialized(), opts()) :: result()
Deserialize data using the specified or default serializer.
@spec serialize(serializable(), opts()) :: {:ok, serialized()} | {:error, term()}
Serialize data using the specified or default serializer.