TimestampLastCombCodec
extends StringCodec
in package
TimestampLastCombCodec encodes and decodes COMBs, with the timestamp as the last 48 bits
The CombGenerator when used with the StringCodec (and, by proxy, the TimestampLastCombCodec) adds the timestamp to the last 48 bits of the COMB. The TimestampLastCombCodec is provided for the sake of consistency. In practice, it is identical to the standard StringCodec but, it may be used with the CombGenerator for additional context when reading code.
Consider the following code. By default, the codec used by UuidFactory is the StringCodec, but here, we explicitly set the TimestampLastCombCodec. It is redundant, but it is clear that we intend this COMB to be generated with the timestamp appearing at the end.
$factory = new UuidFactory();
$factory->setCodec(new TimestampLastCombCodec($factory->getUuidBuilder()));
$factory->setRandomGenerator(new CombGenerator(
$factory->getRandomGenerator(),
$factory->getNumberConverter()
));
$timestampLastComb = $factory->uuid4();
Tags
Table of Contents
- $builder : UuidBuilderInterface
- __construct() : mixed
- Constructs a StringCodec
- decode() : UuidInterface
- Returns a UuidInterface derived from a hexadecimal string representation
- decodeBytes() : UuidInterface
- Returns a UuidInterface derived from a binary string representation
- encode() : string
- Returns a hexadecimal string representation of a UuidInterface
- encodeBinary() : string
- Returns a binary string representation of a UuidInterface
- getBuilder() : UuidBuilderInterface
- Returns the UUID builder
- getBytes() : string
- Returns a byte string of the UUID
Properties
$builder
private
UuidBuilderInterface
$builder
Methods
__construct()
Constructs a StringCodec
public
__construct(UuidBuilderInterface $builder) : mixed
Parameters
- $builder : UuidBuilderInterface
-
The builder to use when encoding UUIDs
Return values
mixed —decode()
Returns a UuidInterface derived from a hexadecimal string representation
public
decode(string $encodedUuid) : UuidInterface
Parameters
- $encodedUuid : string
-
The hexadecimal string representation to convert into a UuidInterface instance
Tags
Return values
UuidInterface —An instance of a UUID decoded from a hexadecimal string representation
decodeBytes()
Returns a UuidInterface derived from a binary string representation
public
decodeBytes(string $bytes) : UuidInterface
Parameters
- $bytes : string
-
The binary string representation to convert into a UuidInterface instance
Return values
UuidInterface —An instance of a UUID decoded from a binary string representation
encode()
Returns a hexadecimal string representation of a UuidInterface
public
encode(UuidInterface $uuid) : string
Parameters
- $uuid : UuidInterface
-
The UUID for which to create a hexadecimal string representation
Return values
string —Hexadecimal string representation of a UUID
encodeBinary()
Returns a binary string representation of a UuidInterface
public
encodeBinary(UuidInterface $uuid) : string
Parameters
- $uuid : UuidInterface
-
The UUID for which to create a binary string representation
Tags
Return values
string —Binary string representation of a UUID
getBuilder()
Returns the UUID builder
protected
getBuilder() : UuidBuilderInterface
Return values
UuidBuilderInterface —getBytes()
Returns a byte string of the UUID
protected
getBytes(string $encodedUuid) : string
Parameters
- $encodedUuid : string