Object.Serialization (object v0.1.2)

Serialization and deserialization for Object instances.

Provides multiple serialization formats optimized for different use cases:

  • ETF (Erlang Term Format) - Native, fast, compact
  • JSON - Human-readable, widely compatible
  • Protocol Buffers - Efficient, schema-based
  • MessagePack - Compact binary format

Features

  • Multiple format support with automatic negotiation
  • Schema versioning and migration
  • Partial serialization for large objects
  • Compression support
  • Type preservation across formats
  • Streaming serialization for large data

Summary

Functions

Calculates serialized size without actually serializing.

Deserializes binary data back into an Object.

Serializes an Object to the specified format.

Serializes only specific fields of an object.

Streams serialization for large objects.

Types

format()

@type format() :: :etf | :json | :protobuf | :msgpack

serialize_opts()

@type serialize_opts() :: [
  format: format(),
  compress: boolean(),
  include_methods: boolean(),
  include_private: boolean(),
  max_depth: pos_integer(),
  fields: [atom()]
]

Functions

calculate_size(object, opts \\ [])

@spec calculate_size(Object.t(), serialize_opts()) ::
  {:ok, non_neg_integer()} | {:error, term()}

Calculates serialized size without actually serializing.

deserialize(data, opts \\ [])

@spec deserialize(binary(), Keyword.t()) :: {:ok, Object.t()} | {:error, term()}

Deserializes binary data back into an Object.

serialize(object, opts \\ [])

@spec serialize(Object.t(), serialize_opts()) :: {:ok, binary()} | {:error, term()}

Serializes an Object to the specified format.

serialize_partial(object, fields, opts \\ [])

@spec serialize_partial(Object.t(), [atom()], serialize_opts()) ::
  {:ok, binary()} | {:error, term()}

Serializes only specific fields of an object.

serialize_stream(object, opts \\ [])

@spec serialize_stream(Object.t(), serialize_opts()) :: Enumerable.t()

Streams serialization for large objects.