2 namespace callnotifier;
10 public function parse($bytes)
12 $m = new EDSS1_Message();
13 $m->sapi = ord($bytes{0}) >> 2;
14 $m->callResponse = (int) ((ord($bytes{0}) & 2) == 2);
15 $m->tei = ord($bytes{1}) >> 1;
18 list($curpos, $cCallRef, $crLen) = $this->readLengthData($bytes, ++$curpos);
22 $m->callRef = ord($cCallRef);
23 //var_dump($curpos, dechex($m->callRef));
24 $m->type = ord($bytes{++$curpos});
29 $curbit = $bytes{++$curpos};
30 if ($curbit == "\xFF" && $bytes{$curpos + 1} == "\n") {
34 $param = new EDSS1_Parameter();
35 $m->parameters[] = $param;
36 $param->type = ord($curbit);
39 $curbit = $bytes{++$curpos};
40 $param->length = ord($curbit);
43 $param->data = substr($bytes, $curpos + 1, $param->length);
44 $curpos += $param->length;
45 } while ($curpos < strlen($bytes) - 1);
51 * Read a datablock preceded with a length byte.
53 * @return array Array with new cursor position, data and data length
55 public function readLengthData($bytes, $curpos)
57 //var_dump('old' . $curpos);
58 $length = ord($bytes{$curpos});
59 if ($length != 0xFF) {
60 $data = substr($bytes, $curpos + 1, $length);
64 return array($curpos + $length, $data, $length);
68 * Read a datablock preceded with a length byte, return integer data.
70 * @return array Array with new cursor position, integer data and data length
72 public function readLengthDataInt($bytes, $curpos)
74 $ld = $this->readLengthData($bytes, $curpos);