php-dextrin

Decoder
in package

FinalYes

`.dxnb` decoder -- the mirror image of {@see Encoder}. Envelope (`magic` `version` `cbor_item`) checked once at the top; everything below that is a single recursive {@see self::decodeItem()}, keyed on CBOR major type first, then on tag -- matching `dxn/DXN.md` §2.2's table row order.

readHead()'s argument is always a numeric string, never a native int -- CBOR major 0's argument can reach 2^64-1, which exceeds PHP_INT_MAX, the same boundary Writer's own doc explains.

One case needs care that the JS port didn't: @ordered's payload is an untagged CBOR map (major 5), and the plain, untagged major -5 case decodes through MapBuilder (this port's own PHP-array-key coercion for map) -- which ordered-map must NOT go through, since its pairs can hold any key type. decodeTag() special-cases T_ORDERED to read raw pairs directly, exactly mirroring how Text\Parser::parseOrderedTag() avoids the same trap.

Table of Contents

Properties

$buf  : string
$pos  : int
$registry  : Registry|null
$sharedItems  : array<int, mixed>
$stringrefStack  : array<int, array<int, string>>

Methods

decode()  : mixed
__construct()  : mixed
buildBignum()  : int|DXNInteger
buildChar()  : DXNChar
buildCustom()  : mixed
buildDate()  : DXNDate
buildDatetimeOffset()  : DXNDateTime
buildDecimal()  : DXNDecimal
buildDuration()  : DXNDuration
buildFromList()  : mixed
buildRational()  : DXNRational
buildRegex()  : DXNRegex
buildStruct()  : mixed
`.dxnb` structs are always positional (`dxn/DXN.md` §2.1).
buildTagged()  : mixed
buildTime()  : DXNTime
buildUuid()  : DXNUuid
decodeByMajor()  : mixed
decodeItem()  : mixed
decodeMajor7()  : mixed
decodeMapPairsRaw()  : array<int, array{0: mixed, 1: mixed}>
decodeNItems()  : array<int, mixed>
decodeOrderedPairs()  : array<int, array{0: mixed, 1: mixed}>
decodeShareable()  : mixed
decodeSharedRef()  : mixed
decodeStringref()  : string
decodeStringrefNamespace()  : mixed
decodeTag()  : mixed
decodeText()  : string
deepClone()  : mixed
Structural deep clone of a decoded value, used only to resolve a tag-29 shared-value reference into an independent copy. Every `DXN*` class here is `readonly`, so mutation-based aliasing is already structurally impossible -- this still rebuilds compound shapes (the ones with DXN-value-typed fields to recurse into) for full spec compliance and consistency with the JS port's own (mutable-object) behavior; scalar-only-field classes have nothing to alias and are returned as-is.
expectString()  : mixed
integerAsString()  : numeric-string
readByte()  : int
readHead()  : array{0: int, 1: numeric-string}
registerStringref()  : void
requireInteger()  : int|DXNInteger
requireSmallInt()  : int
smallIndexOrNull()  : int|null
take()  : string
unpackFloat()  : float
unpackUint()  : int

Properties

$sharedItems

private array<int, mixed> $sharedItems = []

indexed by tag-28 registration order.

$stringrefStack

private array<int, array<int, string>> $stringrefStack = []

innermost scope last.

Methods

decode()

public static decode(string $bytes[, Registry|null $registry = null ]) : mixed
Parameters
$bytes : string
$registry : Registry|null = null

__construct()

private __construct(string $buf, int $pos, Registry|null $registry) : mixed
Parameters
$buf : string
$pos : int
$registry : Registry|null

buildBignum()

private buildBignum(mixed $value, int $tag, bool $negative) : int|DXNInteger
Parameters
$value : mixed
$tag : int
$negative : bool
Return values
int|DXNInteger

buildCustom()

private buildCustom(mixed $value) : mixed
Parameters
$value : mixed

buildFromList()

private buildFromList(mixed $value, int $tag, string $name, callable(array<int, mixed>): mixed $build) : mixed
Parameters
$value : mixed
$tag : int
$name : string
$build : callable(array<int, mixed>): mixed

buildStruct()

`.dxnb` structs are always positional (`dxn/DXN.md` §2.1).

private buildStruct(mixed $value) : mixed

Decoded against a compiled schema when $this->registry has one for $name -- same as Parser's own materializeStruct() -- falling back to an opaque DXNStruct when it doesn't.

Parameters
$value : mixed

buildTagged()

private buildTagged(int $tag, mixed $value) : mixed
Parameters
$tag : int
$value : mixed

decodeByMajor()

private decodeByMajor(int $major, numeric-string $arg) : mixed
Parameters
$major : int
$arg : numeric-string

decodeItem()

private decodeItem() : mixed

decodeMajor7()

private decodeMajor7(int $info) : mixed
Parameters
$info : int

decodeMapPairsRaw()

private decodeMapPairsRaw(int $pairCount) : array<int, array{0: mixed, 1: mixed}>
Parameters
$pairCount : int
Return values
array<int, array{0: mixed, 1: mixed}>

decodeNItems()

private decodeNItems(int $count) : array<int, mixed>
Parameters
$count : int
Return values
array<int, mixed>

decodeOrderedPairs()

private decodeOrderedPairs() : array<int, array{0: mixed, 1: mixed}>
Return values
array<int, array{0: mixed, 1: mixed}>

decodeShareable()

private decodeShareable() : mixed

decodeSharedRef()

private decodeSharedRef() : mixed

decodeStringref()

private decodeStringref() : string
Return values
string

decodeStringrefNamespace()

private decodeStringrefNamespace() : mixed

decodeTag()

private decodeTag(int $tagNumber) : mixed
Parameters
$tagNumber : int

decodeText()

private decodeText(int $len) : string
Parameters
$len : int
Return values
string

deepClone()

Structural deep clone of a decoded value, used only to resolve a tag-29 shared-value reference into an independent copy. Every `DXN*` class here is `readonly`, so mutation-based aliasing is already structurally impossible -- this still rebuilds compound shapes (the ones with DXN-value-typed fields to recurse into) for full spec compliance and consistency with the JS port's own (mutable-object) behavior; scalar-only-field classes have nothing to alias and are returned as-is.

private static deepClone(mixed $value) : mixed
Parameters
$value : mixed

expectString()

private expectString(mixed $value, int $tag, string $name, callable(string): mixed $build) : mixed
Parameters
$value : mixed
$tag : int
$name : string
$build : callable(string): mixed

integerAsString()

private integerAsString(int|DXNInteger $value) : numeric-string
Parameters
$value : int|DXNInteger
Return values
numeric-string

readByte()

private readByte() : int
Return values
int

readHead()

private readHead() : array{0: int, 1: numeric-string}
Return values
array{0: int, 1: numeric-string}

registerStringref()

private registerStringref(string $text) : void
Parameters
$text : string

requireInteger()

private requireInteger(mixed $value, int $tag, string $name) : int|DXNInteger
Parameters
$value : mixed
$tag : int
$name : string
Return values
int|DXNInteger

requireSmallInt()

private requireSmallInt(mixed $value, int $tag, string $name) : int
Parameters
$value : mixed
$tag : int
$name : string
Return values
int

smallIndexOrNull()

private smallIndexOrNull(mixed $value) : int|null
Parameters
$value : mixed
Return values
int|null

take()

private take(int $len) : string
Parameters
$len : int
Return values
string

unpackFloat()

private static unpackFloat(string $bytes, string $format) : float
Parameters
$bytes : string
$format : string
Return values
float

unpackUint()

private static unpackUint(string $bytes, string $format) : int
Parameters
$bytes : string
$format : string
Return values
int
On this page

Search results