API Index — Namespaces, Packages, Reports, Indices
TypeCodec
in package
Backend-neutral row (de)serialization.
Redis HASH fields are byte strings on the wire (RESP2 has no typed
scalars). To keep get() returning the same array<string, scalar>
shape from both backends, the column schema decides how each field
is coerced back to int / float / string.
Used by RedisBackend (Task 6); TableBackend doesn't need it
because OpenSwoole\Table enforces the schema natively.
Table of Contents
Methods
- decodeField() : int|float|string
- Coerce a single wire value (or null for "field missing") to the
schema's declared type. Used by single-field
get($t, $k, $col). - decodeRow() : array<string, int|float|string>|null
- Inverse of encodeRow — coerces wire strings back to typed values per the schema. Returns null when the row didn't exist (empty wire).
- encodeRow() : array<string, string>
- Cast every row value to a string for the wire (HSET, HMGET args).
- coerce() : int|float|string
- Coerce a raw Redis wire string (or
nullfor a missing field) to the PHP type declared by$type(Table::TYPE_INT,Table::TYPE_FLOAT, orTable::TYPE_STRING). Returns the zero-value for the type onnull.
Methods
decodeField()
Coerce a single wire value (or null for "field missing") to the
schema's declared type. Used by single-field get($t, $k, $col).
public
decodeField(int $type, string|null $raw) : int|float|string
Parameters
- $type : int
- $raw : string|null
Return values
int|float|stringdecodeRow()
Inverse of encodeRow — coerces wire strings back to typed values per the schema. Returns null when the row didn't exist (empty wire).
public
decodeRow(array<string, array{0: int, 1?: int}> $schema, array<string, string> $wire) : array<string, int|float|string>|null
Missing fields in a known row get their zero-value-by-type (matches OpenSwoole\Table's behaviour for unset columns).
Parameters
- $schema : array<string, array{0: int, 1?: int}>
- $wire : array<string, string>
Return values
array<string, int|float|string>|nullencodeRow()
Cast every row value to a string for the wire (HSET, HMGET args).
public
encodeRow(array<string, array{0: int, 1?: int}> $schema, array<string, scalar> $row) : array<string, string>
Returns a parallel array of strings keyed by column name.
Parameters
- $schema : array<string, array{0: int, 1?: int}>
-
ignored at encode time but kept for symmetry
- $row : array<string, scalar>
Return values
array<string, string>coerce()
Coerce a raw Redis wire string (or null for a missing field) to the
PHP type declared by $type (Table::TYPE_INT, Table::TYPE_FLOAT,
or Table::TYPE_STRING). Returns the zero-value for the type on null.
private
coerce(int $type, string|null $raw) : int|float|string
Parameters
- $type : int
- $raw : string|null