<?php
namespace FWIF;
class FWIFDecodeStream {
private string $body;
private int $length;
private int $position = 0;
public function __construct(string $body) {
$this->body = $body;
$this->length = strlen($body);
}
public function getLength(): int {
return $this->length;
public function getPosition(): int {
return $this->position;
public function stepBack(): void {
$this->position = max(0, $this->position - 1);
public function readByte(): int {
if($this->position + 1 >= $this->length)
return FWIF::TRAILER;
return ord($this->body[$this->position++]);
public function readChar(): string {
return chr($this->readByte());
public function readString(int $length): string {
// Bounds checks? What are those?
$string = substr($this->body, $this->position, $length);
$this->position += $length;
return $string;