. * * @author Daniil Gentili * @copyright 2016-2020 Daniil Gentili * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * * @link https://docs.madelineproto.xyz MadelineProto documentation */ namespace danog\MadelineProto\TL\Types; /** * Bytes wrapper. */ class Bytes implements \JsonSerializable, \ArrayAccess { /** * Bytes. * * @var string Bytes */ private string $bytes; /** * Constructor function. * * @param string $bytes Contents */ public function __construct(string $bytes) { $this->bytes = $bytes; } /** * Sleep function. * * @return array */ public function __sleep(): array { return ['bytes']; } /** * Cast bytes to string. * * @return string */ public function __toString(): string { return $this->bytes; } /** * Obtain values for JSON-encoding. * * @return array */ public function jsonSerialize(): array { return ['_' => 'bytes', 'bytes' => \base64_encode($this->bytes)]; } /** * Set char at offset. * * @param integer|null $offset Offset * @param string $value Char * * @return void */ public function offsetSet($offset, $value): void { if ($offset === null) { $this->bytes .= $value; } else { $this->bytes[$offset] = $value; } } /** * Get char at offset. * * @param integer $offset Name * * @return string */ public function offsetGet($offset): string { return $this->bytes[$offset]; } /** * Unset char at offset. * * @param integer $offset Offset * * @return void */ public function offsetUnset($offset): void { unset($this->bytes[$offset]); } /** * Check if char at offset exists. * * @param integer $offset Offset * * @return boolean */ public function offsetExists($offset): bool { return isset($this->bytes[$offset]); } }