Make serialize(UuidInterface) more compact

Resolves #318
This commit is contained in:
Ben Ramsey
2020-07-08 15:27:19 -05:00
parent a741fc66ac
commit 22ee596348
4 changed files with 36 additions and 6 deletions
+9 -3
View File
@@ -273,7 +273,7 @@ class Uuid implements UuidInterface
*/
public function serialize(): string
{
return $this->toString();
return $this->getBytes();
}
/**
@@ -286,8 +286,14 @@ class Uuid implements UuidInterface
*/
public function unserialize($serialized): void
{
/** @var \Ramsey\Uuid\Uuid $uuid */
$uuid = self::fromString($serialized);
if (strlen($serialized) === 16) {
/** @var Uuid $uuid */
$uuid = self::fromBytes($serialized);
} else {
/** @var Uuid $uuid */
$uuid = self::fromString($serialized);
}
$this->codec = $uuid->codec;
$this->numberConverter = $uuid->numberConverter;
$this->fields = $uuid->fields;