public function unpickle_stream(phpickle_stream $stream) { $reader = new phpickle_read_ops(); $stack = new phpickle_stack(); $memo = new phpickle_memo(); $ops = new phpickle_op_mapper(); if ($this->debug) { echo "start unpickle \r\n"; } while (!$stream->eof()) { $byte = $stream->get_byte(); if ($this->debug) { echo "read command as {$byte} (" . ord($byte) . ") \r\n"; } $op_str = $ops->bin2str($byte); if ($this->debug) { echo "op_str = {$op_str} \r\n"; } if ($op_str == "STOP") { break; } $fn = "op_" . $op_str; if ($this->debug) { echo "calling {$fn} \r\n"; } $reader->{$fn}($stream, $stack, $memo, $this->debug); } return $stack->pop(); }
public function gen_op_handlers(phpickle_stream $stream) { // go over file lines, // skip starting with // // skip empty // handle starting with OP and -- read: and --write: $read_ct = ""; $write_ct = ""; while (!$stream->eof()) { $line = trim($stream->get_line()); if ($line == "") { continue; } else { if (substr($line, 0, 2) == "//") { continue; } else { if (substr($line, 0, 3) == "OP:") { list($read, $write) = $this->_process_op($line, $stream); $read_ct .= $read; $write_ct .= $write; } else { throw "Unexpected line in op handlers! {$line}"; } } } } $read_ct = <<<EOD class phpickle_read_ops { {$read_ct} } EOD; $write_ct = <<<EOD class phpickle_write_ops { {$write_ct} } EOD; return array($read_ct, $write_ct); }