thesis / byte-order
The library adds methods for reading bytes in any byte order to Reader and Writer.
Fund package maintenance!
www.tinkoff.ru/cf/5MqZQas2dk7
Installs: 12 754
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
pkg:composer/thesis/byte-order
Requires
- php: ^8.3
- thesis/byte-reader: ^0.3.1
- thesis/byte-writer: ^0.2.2
- thesis/endian: ^0.1.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8.2
- ergebnis/composer-normalize: ^2.45.0
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); }