Skip to content

Codec

[Source]

Encodes and decodes values for a PostgreSQL type in a specific wire format (text or binary).

Each codec handles one format. The OID-to-codec mapping is the registry's responsibility, not the codec's — a single codec implementation can serve multiple OIDs (e.g., one text passthrough codec for all text-like OIDs).

Codecs are val (immutable, shareable across actors). Built-in codecs are primitives (zero allocation, global singletons).

interface val Codec

Public Functions

format

[Source]

Wire format: 0 for text, 1 for binary.

fun box format()
: U16 val

Returns


encode

[Source]

Encode a Pony value to wire format bytes for use as a parameter. Errors when the value's type doesn't match what this codec expects.

fun box encode(
  value: FieldDataTypes)
: Array[U8 val] val ?

Parameters

Returns


decode

[Source]

Decode wire format bytes from a result column to a Pony value. Errors when the data is malformed or has an unexpected length.

The return type is FieldData (an open interface) rather than FieldDataTypes (a closed union) so that custom codecs can return their own types. The encode path stays FieldDataTypes because parameters must map to known PostgreSQL OIDs for the wire protocol.

fun box decode(
  data: Array[U8 val] val)
: FieldData val ?

Parameters

Returns