DXNBits
in package
implements
DXNValueInterface
DXN `bits` (DXN.md ยง1.4): a run of bits that is not whole bytes -- `@bits {"oA==" 3}` in text, `T_BITS` around `[bytes, count]` in `.dxnb`. PHP has no bitstring, so this holds the bytes, the unused low bits of the last one zero, and how many bits are the value.
Bits and bytes are one value space: a run of whole bytes is bytes,
so DXNBits::from() answers a DXNBytes for one, and the
constructor refuses it. Mirrors the Elixir reference's bitstring in a
Dextrin.Bytes.
Table of Contents
Interfaces
- DXNValueInterface
- Implemented by every `DXN*` wrapper class -- the PHP analog of the `dxnType` string tag used for kind dispatch in the JS port, and of `Dextrin.Value`'s closed type union in the Elixir original. Native PHP values (`null`, `bool`, `int`, `float`, `string`, and `array` for `map`/`array`) never implement this; {@see Equality::kindOf()} handles those directly.
Constants
- DXN_TYPE : mixed = 'bits'
Properties
- $bitLength : int
- $data : string
Methods
- __construct() : mixed
- compareTo() : int
- A total order against any other DXN value, not just another instance of this class -- backs {@see DXNSortedSet}. Cross-kind ordering is implementation-defined per DXN.md; within a kind, uses the kind's own natural order where one exists, or a deterministic structural fallback where it doesn't.
- dxnType() : string
- The DXN type name this value represents, e.g. "symbol", "uuid".
- equals() : bool
- Structural equality, recursing into nested DXN values as needed.
- from() : self|DXNBytes
- The value `$data` and `$bitLength` write: bits, or bytes when the count is a whole number of them. An `\InvalidArgumentException` when they write none (a count the data does not match).
- parts() : string|null
- `$data` with the unused low bits of its last byte cleared, or null when it is not exactly the bytes `$bitLength` needs.
Constants
DXN_TYPE
private
mixed
DXN_TYPE
= 'bits'
Properties
$bitLength read-only
public
int
$bitLength
$data read-only
public
string
$data
Methods
__construct()
public
__construct(string $data, int $bitLength) : mixed
Parameters
- $data : string
-
the bits, from the high bit of the first byte
- $bitLength : int
-
how many of them are the value; not a multiple of 8
compareTo()
A total order against any other DXN value, not just another instance of this class -- backs {@see DXNSortedSet}. Cross-kind ordering is implementation-defined per DXN.md; within a kind, uses the kind's own natural order where one exists, or a deterministic structural fallback where it doesn't.
public
compareTo(mixed $other) : int
Parameters
- $other : mixed
Return values
intdxnType()
The DXN type name this value represents, e.g. "symbol", "uuid".
public
dxnType() : string
Return values
stringequals()
Structural equality, recursing into nested DXN values as needed.
public
equals(mixed $other) : bool
Parameters
- $other : mixed
Return values
boolfrom()
The value `$data` and `$bitLength` write: bits, or bytes when the count is a whole number of them. An `\InvalidArgumentException` when they write none (a count the data does not match).
public
static from(string $data, int $bitLength) : self|DXNBytes
Parameters
- $data : string
- $bitLength : int
Return values
self|DXNBytesparts()
`$data` with the unused low bits of its last byte cleared, or null when it is not exactly the bytes `$bitLength` needs.
private
static parts(string $data, int $bitLength) : string|null
Parameters
- $data : string
- $bitLength : int