PHP code example of thesis / byte-order
1. Go to this page and download the library: Download thesis/byte-order library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thesis / byte-order example snippets
declare(strict_types=1);
use Thesis\ByteOrder\ReadFrom;
use Thesis\ByteOrder\WriteTo;
final class Frame
{
/**
* @param non-empty-string $id
* @param non-negative-int $attempts
*/
public function __construct(
public readonly string $id,
public readonly int $attempts,
) {}
}
function readFrame(ReadFrom $reader): Frame
{
return new Frame(
$reader->read($reader->readUint16()),
$reader->readUint32(),
);
}
function writeFrame(WriteTo $writer, Frame $frame): void
{
$writer->writeUint16(\strlen($frame->id));
$writer->write($frame->id);
$writer->writeUint32($frame->attempts);
}