thesis / byte-order
The library adds methods for reading bytes in any byte order to Reader and Writer.
Fund package maintenance!
0.4.1
2026-04-08 23:35 UTC
Requires
- php: ^8.4
- ext-bcmath: *
- thesis/byte-reader: ^0.3.1
- thesis/byte-writer: ^0.2.2
- thesis/endian: ^0.3.3
README
Installation
composer require thesis/byte-order
Basic usage
<?php 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); }