$c = new ion\Catalog;
$c->add(new ion\Symbol\Table\Shared("shared", 1, ["shared1", "shared2"]));
-$w = new ion\Writer\Buffer\Writer($buf,
- new ion\Writer\Options(catalog: $c, outputBinary: true));
+$w = new ion\Writer\Buffer\Writer(catalog: $c, outputBinary: true);
$w->writeSymbol("shared1");
$w->writeSymbol("shared1");
$w->finish();
-foreach (str_split($buf, 8) as $line) {
+foreach (str_split($w->getBuffer(), 8) as $line) {
printf("%-26s", chunk_split(bin2hex($line), 2, " "));
foreach (str_split($line) as $byte) {
- echo ctype_print($byte) ? $byte : ".";
+ echo $byte >= ' ' && $byte <= '~' ? $byte : ".";
}
echo "\n";
}
echo "\n";
-$u = new ion\Unserializer\PHP(multiSequence: true);
-var_dump($u->unserialize($buf));
+$u = new ion\Unserializer\Unserializer(multiSequence: true);
+var_dump($s = $u->unserialize($w->getBuffer()));
-$u = new ion\Unserializer\PHP(multiSequence: true,
- readerOptions: new ion\Reader\Options(
+foreach ($s as $sym) {
+ /** @var ion\Symbol $sym */
+ $t = $c->findBest($sym->importLocation->name);
+ $r = $t->findLocal($sym->importLocation->location);
+ printf("%s: %s@%d\n", $r->value, $sym->importLocation->name,
+ $sym->importLocation->location);
+}
+
+$u = new ion\Unserializer\Unserializer(multiSequence: true);
+var_dump($u->unserialize(new ion\Reader\Buffer\Reader($w->getBuffer(),
catalog: $c,
- onContextChange: fn(ion\Reader $r) => print("on_context_change\n")));
-var_dump($u->unserialize($buf));
+ onContextChange: fn(ion\Reader $r) => print("on_context_change\n")
+)));
?>
DONE
}
}
}
+shared1: shared@1
+shared1: shared@1
+shared2: shared@2
+shared2: shared@2
on_context_change
array(4) {
[0]=>