PHP の⽂字列はエンコード情報を持たないバイト列
添え字アクセスと ord()で 1 バイト分のデータを取り出す実
装が作れる
final class StringByteReader implements ByteReaderInterface
{
use ByteReaderDisableWriteAccessTrait;
public function offsetGet($offset): int
{
return ord($this->source[$offset]);
}
62.
このインターフェースを通じて 32 ビットや64 ビットの整数値
を取り出すクラスも作る
final class LittleEndianReader implements IntegerByteSequenceReader
{
public function read8(ByteReaderInterface $data, int $offset): int
{
return $data[$offset];
}
public function read16(ByteReaderInterface $data, int $offset): int
{
return ($data[$offset + 1] << 8) | $data[$offset];
}
public function read32(ByteReaderInterface $data, int $offset): int
{
return ($data[$offset + 3] << 24)
| ($data[$offset + 2] << 16)
| ($data[$offset + 1] << 8)
| $data[$offset];
}