Update objects to use __toString()

This commit is contained in:
Deon George
2020-06-24 22:37:14 +10:00
parent 358f28273c
commit 9936e839a4
15 changed files with 145 additions and 78 deletions

View File

@@ -9,18 +9,9 @@ class Subpacket extends Packet
{
protected $tag = NULL;
function body()
protected function header_and_body(): array
{
return $this->data;
}
function header_and_body(): array
{
$body = $this->body(); // Get body first, we will need it's length
$size = chr(255).pack('N',strlen($body)+1); // Use 5-octet lengths + 1 for tag as first packet body octet
$tag = chr($this->tag);
return ['header'=>$size.$tag,'body'=>$body];
return ['header'=>$this->size().chr($this->tag),'body'=>$this->body()];
}
/* Defaults for unsupported packets */
@@ -36,4 +27,10 @@ class Subpacket extends Packet
$this->tag = $tag;
}
protected function size(): string
{
// Use 5-octet lengths + 1 for tag as first packet body octet
return chr(255).pack('N',strlen($this->body())+1);
}
}