id = $id; $this->body = $body; } public function __get($key) { switch ($key) { case 'len': return strlen($this->body)+1+self::BLK_HDR_SIZE; case 'msg': $buf = self::mkheader((strlen($this->body)+1) | 0x8000); $buf .= chr($this->id); $buf .= $this->body; return $buf; default: throw new \Exception('Unknown key :'.$key); } } public static function mkheader(int $l): string { $buf = chr(($l>>8)&0xff); $buf .= chr($l&0xff); return $buf; } }