index/src/Serialisation/Base64Serialiser.php

34 lines
788 B
PHP
Raw Normal View History

2022-09-13 13:13:11 +00:00
<?php
// Base64Serialiser.php
// Created: 2022-01-13
// Updated: 2022-02-27
namespace Index\Serialisation;
use Index\IO\Stream;
/**
* Provides a Base64 serialiser.
*/
class Base64Serialiser extends Serialiser {
/**
* Encodes binary data as a Base64 string.
*
* @param mixed $input Input binary data.
* @return string Base64 string representing the binary data.
*/
public function serialise(mixed $input): string {
return base64_encode((string)$input);
}
/**
* Decodes a Base64 string back to binary data.
*
* @param Stream|string $input Input Base64 string.
* @return string Binary data.
*/
public function deserialise(Stream|string $input): mixed {
return base64_decode((string)$input);
}
}