PhoenixMicro.Utils.Encoding (PhoenixMicro v1.0.0)

Copy Markdown View Source

Shared encoding/decoding helpers used across transports and the producer.

Provides a unified entry point for payload serialization so all transports produce and consume messages in the same format regardless of the underlying broker's wire format.

Summary

Functions

Returns the MIME content-type for the configured serializer.

Safely decodes a binary — returns {:ok, term} or {:error, reason}.

Decodes binary using the configured serializer. Returns the decoded term.

Safely encodes a term — returns {:ok, binary} or {:error, reason}.

Encodes payload using the configured serializer. Returns a binary.

Functions

content_type()

@spec content_type() :: String.t()

Returns the MIME content-type for the configured serializer.

decode(binary)

@spec decode(binary()) :: {:ok, term()} | {:error, Exception.t()}

Safely decodes a binary — returns {:ok, term} or {:error, reason}.

decode!(binary)

@spec decode!(binary()) :: term()

Decodes binary using the configured serializer. Returns the decoded term.

encode(payload)

@spec encode(term()) :: {:ok, binary()} | {:error, Exception.t()}

Safely encodes a term — returns {:ok, binary} or {:error, reason}.

encode!(payload)

@spec encode!(term()) :: binary()

Encodes payload using the configured serializer. Returns a binary.