function OrderedTimeCodec::decodeBytes
Returns a UuidInterface derived from an ordered-time binary string representation
@inheritDoc
Throws
InvalidArgumentException if $bytes is an invalid length
Overrides StringCodec::decodeBytes
File
-
vendor/
ramsey/ uuid/ src/ Codec/ OrderedTimeCodec.php, line 85
Class
- OrderedTimeCodec
- OrderedTimeCodec encodes and decodes a UUID, optimizing the byte order for more efficient storage
Namespace
Ramsey\Uuid\CodecCode
public function decodeBytes(string $bytes) : UuidInterface {
if (strlen($bytes) !== 16) {
throw new InvalidArgumentException('$bytes string should contain 16 characters.');
}
// Rearrange the bytes to their original order.
$rearrangedBytes = $bytes[4] . $bytes[5] . $bytes[6] . $bytes[7] . $bytes[2] . $bytes[3] . $bytes[0] . $bytes[1] . substr($bytes, 8);
$uuid = parent::decodeBytes($rearrangedBytes);
if (!$uuid->getFields() instanceof Rfc4122FieldsInterface || $uuid->getFields()
->getVersion() !== Uuid::UUID_TYPE_TIME) {
throw new UnsupportedOperationException('Attempting to decode a non-time-based UUID using ' . 'OrderedTimeCodec');
}
return $uuid;
}