php-dextrin

Encoder
in package

FinalYes

`.dxnb` encoder -- a recursive walk over CBOR's major types plus a fixed tag dispatch table, matching `dxn/DXN.md` §2.2's table row order.

Scope note: value sharing (dxn/DXN.md §2.5, tags 28/29) is decode-only for now, same as the JS port -- the spec requires a conforming decoder to accept it but never requires an encoder to produce it. Every document round-trips correctly either way; producing shared references would only ever change output size, never semantics.

Envelope (magic version cbor_item, dxn/DXN.md §2.1) is written once, at self::encode() itself; everything below that is self::encodeItem(), one recursive method keyed on the PHP value's own shape.

An optional $registry lets a genuine, registered application class instance be encoded as its schema's named struct rather than one named after its own PHP class, when the two differ -- see Printer's own doc on the identical text-side behavior.

Table of Contents

Constants

MAGIC  : mixed = 'DX'
VERSION  : mixed = "\x01"

Methods

encode()  : string
__construct()  : mixed
encodeDecimal()  : string
encodeDuration()  : string
encodeItem()  : string
encodeMapEntries()  : array<int, array{0: string, 1: string}>
A bare PHP array's own key already tells `MapBuilder::toDxnMapKey()` apart a `DXNKeyword` key from a `string` key with the same text (see that class's own doc) -- a keyword-originated key encodes under `Tags::T_KEYWORD`, same as any other `DXNKeyword` value; a genuinely string-typed key encodes as a plain untagged text item, same as before.
encodePairs()  : array<int, array{0: string, 1: string}>
encodePlainObjectAsStruct()  : string
Same registry-first precedence as {@see \JOetjen\Dextrin\Text\Printer::printPlainObjectAsStruct()}'s own doc: a struct name registered for `$value`'s class takes priority (schema's own field order, not `$value`'s declared-property order); a registered tag encoder takes priority over the generic struct-by-class-name fallback next, since that's a scalar-wrapping extension, not a struct one.
encodeStruct()  : string
`.dxnb` structs are always positional (`dxn/DXN.md` §2.1) -- a keyed `DXNStruct` (no schema known) falls back to its pairs' own iteration order, the only field order available without a schema.
epochDays()  : int
shortClassName()  : string
totalMicroseconds()  : int

Constants

VERSION

private mixed VERSION = "\x01"

Methods

encode()

public static encode(mixed $value[, Registry|null $registry = null ]) : string
Parameters
$value : mixed
$registry : Registry|null = null
Return values
string

__construct()

private __construct() : mixed

encodeItem()

private static encodeItem(mixed $value, Registry|null $registry) : string
Parameters
$value : mixed
$registry : Registry|null
Return values
string

encodeMapEntries()

A bare PHP array's own key already tells `MapBuilder::toDxnMapKey()` apart a `DXNKeyword` key from a `string` key with the same text (see that class's own doc) -- a keyword-originated key encodes under `Tags::T_KEYWORD`, same as any other `DXNKeyword` value; a genuinely string-typed key encodes as a plain untagged text item, same as before.

private static encodeMapEntries(array<int|string, mixed> $map, Registry|null $registry) : array<int, array{0: string, 1: string}>
Parameters
$map : array<int|string, mixed>
$registry : Registry|null
Return values
array<int, array{0: string, 1: string}>

encodePairs()

private static encodePairs(array<int, array{0: mixed, 1: mixed}> $pairs, Registry|null $registry) : array<int, array{0: string, 1: string}>
Parameters
$pairs : array<int, array{0: mixed, 1: mixed}>
$registry : Registry|null
Return values
array<int, array{0: string, 1: string}>

encodePlainObjectAsStruct()

Same registry-first precedence as {@see \JOetjen\Dextrin\Text\Printer::printPlainObjectAsStruct()}'s own doc: a struct name registered for `$value`'s class takes priority (schema's own field order, not `$value`'s declared-property order); a registered tag encoder takes priority over the generic struct-by-class-name fallback next, since that's a scalar-wrapping extension, not a struct one.

private static encodePlainObjectAsStruct(object $value, Registry|null $registry) : string
Parameters
$value : object
$registry : Registry|null
Return values
string

encodeStruct()

`.dxnb` structs are always positional (`dxn/DXN.md` §2.1) -- a keyed `DXNStruct` (no schema known) falls back to its pairs' own iteration order, the only field order available without a schema.

private static encodeStruct(string $name, array<int, mixed> $values, Registry|null $registry) : string
Parameters
$name : string
$values : array<int, mixed>
$registry : Registry|null
Return values
string

shortClassName()

private static shortClassName(string $className) : string
Parameters
$className : string
Return values
string

totalMicroseconds()

private static totalMicroseconds(DXNTime $time) : int
Parameters
$time : DXNTime
Return values
int
On this page

Search results