fix memleaks
[awesomized/ext-ion] / ion.stub.php
1 <?php
2
3 /**
4 * Amazon ION serialization format.
5 *
6 * @link https://github.com/awesomized/ext-ion
7 *
8 * @see https://github.com/amzn/ion-c amzn/ion-c
9 * @see https://amzn.github.io/ion-docs/ Amazon ION spec
10 *
11 * @generate-class-entries static
12 * @generate-function-entries static
13 */
14
15 namespace ion;
16
17 /**
18 * Serialize a PHP value as ION data.
19 *
20 * Serializes supported PHP values with the optionally provided \ion\Serializer:
21 * * NULL
22 * * bool
23 * * int
24 * * float
25 * * string
26 * * reference
27 * * array
28 * * object (incl. \Serializable, and classes implementing magic and custom __serialize)
29 *
30 * @param mixed $data PHP value(s).
31 * @param Serializer|array|null $serializer Custom Serializer (options).
32 * @return string serialized ION data
33 * @throws \ion\Exception
34 */
35 function serialize(mixed $data, Serializer|array|null $serializer = null) : string {}
36
37 /**
38 * Unserialize ION data (stream) as PHP value(s).
39 *
40 * @param string|resource $data Serialized ION data, either as string buffer or stream.
41 * @param Unserializer|array|null $unserializer Custom Unserializer (options).
42 * @return mixed unserialized PHP values
43 * @throws \ion\Exception
44 */
45 function unserialize($data, Unserializer|array|null $unserializer = null) : mixed {}
46
47 /**
48 * Serializer interface, used to customize ion\serialize()'s behavior.
49 */
50 interface Serializer {
51 public function serialize(mixed $data, \ion\Writer|\ion\Writer\Options|array|null $writer = null) : mixed;
52 }
53
54 /**
55 * Unserializer interface, used to customize ion\unserialize()'s behavior.
56 */
57 interface Unserializer {
58 /** @param \ion\Reader|string|resource $data */
59 public function unserialize($data) : mixed;
60 }
61
62 /**
63 * Base exception for the ION extension.
64 */
65 class Exception extends \Exception {
66 }
67
68 /**
69 * ION data type.
70 *
71 * The following special PHP classes are provided for some data types:
72 * * ion\Decimal
73 * * ion\Timestamp
74 * * ion\Symbol
75 * * ion\Lob
76 */
77 enum Type : int {
78 case Null = 0x000;
79 case Bool = 0x100;
80 case Int = 0x200;
81 case Float = 0x400;
82 case Decimal = 0x500;
83 case Timestamp = 0x600;
84 case Symbol = 0x700;
85 case String = 0x800;
86 case CLob = 0x900;
87 case BLob = 0xa00;
88 case List = 0xb00;
89 case SExp = 0xc00;
90 case Struct = 0xd00;
91 case Datagram = 0xf00;
92
93 case EOF =-0x100;
94 case NONE =-0x200;
95 }
96
97 /**
98 * @see https://amzn.github.io/ion-docs/docs/spec.html#symbol ION spec's symbol definition
99 * @see https://amzn.github.io/ion-docs/guides/symbols-guide.html ION spec's symbol guide
100 */
101 class Symbol {
102 /**
103 * Create an ION symbol.
104 */
105 public function __construct(
106 /**
107 * The symbol's text representation.
108 */
109 public readonly ?string $value = null,
110 /**
111 * The symbols ID, referencing its location within a shared symbol table.
112 */
113 public readonly int $sid = -1,
114 /**
115 * The import location referencing a shared symbol table.
116 */
117 public readonly ?Symbol\ImportLocation $importLocation = null,
118 ) {}
119
120 /**
121 * Compare two symbols for equality.
122 *
123 * Two symbols are considered equal, if either:
124 * * both are the same object or NULL
125 * * both values are NULL (unknown text), and both $importLocations match
126 * * both values match, regardless of $sid and $importLocation
127 *
128 * @param Symbol $symbol
129 * @return bool whether the two Symbols equal
130 */
131 public function equals(Symbol $symbol): bool {}
132 public function __toString() : string {}
133 /** @alias ion\Symbol::__toString */
134 public function toString() : string {}
135 }
136
137 /**
138 * The Catalog holds a collection of ion\Symbol\Table instances queried from ion\Reader and ion\Writer instances.
139 *
140 * @see https://amzn.github.io/ion-docs/docs/symbols.html#the-catalog the ION spec's symbol guide chapter on catalog.
141 */
142 class Catalog implements \Countable {
143 /** Internal cache. */
144 private array $symbolTables = [];
145
146 /** Create a new Catalog. */
147 public function __construct() {}
148
149 /** Count how many symbol tables the catalog holds. */
150 public function count() : int {}
151
152 /**
153 * Add a shared symbol table to the catalog.
154 *
155 * @param Symbol\Table $table The new table to add.
156 */
157 public function add(Symbol\Table $table) : void {}
158
159 /**
160 * Remove a shared symbol table from the catalog.
161 *
162 * @param Symbol\Table|string $table The symbol table to renmove.
163 * @return bool Success.
164 */
165 public function remove(Symbol\Table|string $table) : bool {}
166
167 /**
168 * Find a shared symbol table within the catalog.
169 *
170 * @param string $name The name of the symbol table.
171 * @param int $version The version the symbol table should match.
172 * @return Symbol\Table|null The symbol table found, if any.
173 */
174 public function find(string $name, int $version = 0) : ?Symbol\Table {}
175
176 /**
177 * Find a "best match" for a shared symbol table within the catalog.
178 *
179 * @param string $name The name of the symbol table,
180 * @param int $version The minimum version of the symbol table.
181 * @return Symbol\Table|null The symbol table found, if any.
182 */
183 public function findBest(string $name, int $version = 0) : ?Symbol\Table {}
184 }
185
186 /**
187 * A large object.
188 *
189 * @see ion\Type
190 * @see https://amzn.github.io/ion-docs/docs/spec.html#blob the ION spec's BLob definition
191 * @see https://amzn.github.io/ion-docs/docs/spec.html#clob the ION sepc's CLob definition
192 */
193 class LOB {
194 /**
195 * Create an ION large object.
196 */
197 public function __construct(
198 /**
199 * The value of the large object.
200 */
201 public readonly string $value,
202 /**
203 * The type (CLob/BLob).
204 */
205 public readonly Type $type = Type::CLob,
206 ) {}
207 }
208
209 /**
210 * An arbitrary precision fixed point decimal.
211 *
212 * @see ion\Decimal\Context
213 * @see https://amzn.github.io/ion-docs/docs/decimal.html the ION spec's decimal docs
214 */
215 class Decimal {
216 /**
217 * Create a new fixed point decimal.
218 */
219 public function __construct(
220 /**
221 * The decimal number.
222 */
223 public readonly string|int $number,
224 /**
225 * The decimal context.
226 */
227 public readonly ?Decimal\Context $context = null,
228 ) {}
229
230 /**
231 * Check two decimals for equality.
232 *
233 * @param Decimal $decimal The decimal to compare to.
234 * @return bool Whether both decimals equal.
235 */
236 public function equals(Decimal $decimal) : bool {}
237
238 /**
239 * Check whether the decimal is actually a big integer.
240 * @return bool Whether the decimal is actually an integer.
241 */
242 public function isInt() : bool {}
243
244 public function __toString() : string {}
245 /**
246 * Get the string representation of the decimal.
247 * @alias ion\Decimal::__toString
248 */
249 public function toString() : string {}
250
251 /**
252 * Get the integer represention of the decimal.
253 * @throws \ion\Exception If the decimal is actually not an integer.
254 */
255 public function toInt() : int {}
256 }
257
258 /**
259 * An ION Timestamp.
260 * @see https://amzn.github.io/ion-docs/docs/spec.html#timestamp the ION spec's timestamp definition
261 * @see https://php.net/date PHP's date documentation
262 */
263 class Timestamp extends \DateTime {
264 /**
265 * The timestamp's precision. See ion\Timestamp\Precision.
266 */
267 public readonly int $precision;
268 /**
269 * The timestamp's format. See ion\Timestamp\Format.
270 */
271 public readonly string $format;
272
273 /**
274 * Create a new ION timestamp.
275 *
276 * @param Timestamp\Precision|int $precision The timestamp's precision.
277 * @param Timestamp\Format|string|null $format The timestamp's format.
278 * @param string|null $datetime The timestamp's value.
279 * @param \DateTimeZone|string|null $timezone The timestamp's timezone.
280 */
281 public function __construct(
282 Timestamp\Precision|int $precision,
283 Timestamp\Format|string|null $format = null,
284 ?string $datetime = null,
285 \DateTimeZone|string|null $timezone = null,
286 ) {}
287
288 public function __toString() : string {}
289 }
290
291 /**
292 * ION reader API.
293 */
294 interface Reader extends \RecursiveIterator {
295 public function getType() : Type;
296 public function hasAnnotations() : bool;
297 public function hasAnnotation(string $annotation) : bool;
298 public function isNull() : bool;
299 public function isInStruct() : bool;
300 public function getFieldName() : string;
301 public function getFieldNameSymbol() : Symbol;
302 public function getAnnotations() : array;
303 public function getAnnotationSymbols() : array;
304 public function countAnnotations() : int;
305 public function getAnnotation(int $index) : string;
306 public function getAnnotationSymbol(int $index) : Symbol;
307
308 public function readNull() : Type;
309 public function readBool() : bool;
310 public function readInt() : int|string;
311 public function readFloat() : float;
312 public function readDecimal() : Decimal;
313 public function readTimestamp() : Timestamp;
314 public function readSymbol() : Symbol;
315 public function readString() : string;
316 /** @param ref $string */
317 public function readStringPart(&$string, int $length = 0x1000) : bool;
318 public function readLob() : string;
319 /** @param ref $string */
320 public function readLobPart(&$string, int $length = 0x1000) : bool;
321
322 public function getPosition() : int;
323 public function getDepth() : int;
324
325 public function seek(int $offset, int $length = -1) : void;
326 /*
327 public function getSymbolTable() : SymbolTable;
328 public function setSymbolTable(SymbolTable $table) : void;
329 */
330 public function getValueOffset() : int;
331 public function getValueLength() : int;
332 }
333
334 /**
335 * ION writer API.
336 */
337 interface Writer {
338 public function writeNull() : void;
339 public function writeTypedNull(Type $type) : void;
340 public function writeBool(bool $value) : void;
341 public function writeInt(int|string $value) : void;
342 public function writeFloat(float $value) : void;
343 public function writeDecimal(Decimal|string $value) : void;
344 public function writeTimestamp(Timestamp|string $value) : void;
345 public function writeSymbol(Symbol|string $value) : void;
346 public function writeString(string $value) : void;
347 public function writeCLob(string $value) : void;
348 public function writeBLob(string $value) : void;
349
350 public function startLob(Type $type) : void;
351 public function appendLob(string $data) : void;
352 public function finishLob() : void;
353
354 public function startContainer(Type $type) : void;
355 public function finishContainer() : void;
356
357 public function writeFieldName(string $name) : void;
358
359 public function writeAnnotation(Symbol|string ...$annotation) : void;
360
361 public function getDepth() : int;
362 public function flush() : int;
363 public function finish() : int;
364
365 // public function writeOne(Reader $reader) : void;
366 // public function writeAll(Reader $reader) : void;
367
368 // public function getCatalog() : Catalog;
369 // public function setCatalog(Catalog $catalog) : void;
370
371 // public function getSymbolTable() : Symbol\Table;
372 // puvlic function setSymbolTable(Symbol\Table $table) : void;
373 }
374
375 namespace ion\Symbol;
376
377 /**
378 * The import location (referring to a shared table) of a symbol.
379 */
380 class ImportLocation {
381 /**
382 * Create a new import location.
383 */
384 public function __construct(
385 /**
386 * The name of the shared symbol table.
387 */
388 public readonly string $name,
389 /**
390 * The location (sid) of the symbol within the table.
391 */
392 public readonly int $location,
393 ) {}
394 }
395
396 /**
397 * Base interface of built-in shared symbol tables.
398 */
399 interface Enum {
400 /**
401 * @return \ion\Symbol Instance of the symbol.
402 */
403 public function toSymbol() : \ion\Symbol;
404
405 /**
406 * @return int The symbol id.
407 */
408 public function toSID() : int;
409
410 /**
411 * @return string The symbol's textual representation.
412 */
413 public function toString() : string;
414 }
415
416 /**
417 * Base interface of an ION symbol table.
418 */
419 interface Table {
420 /**
421 * Get the maximum symbol ID within the symbol table.
422 * @return int The maximum symbol ID.
423 */
424 public function getMaxId() : int;
425
426 /**
427 * Add a symbol to the table.
428 *
429 * @param \ion\Symbol|string $symbol The symbol (value) to add.
430 * @return int The symbol ID.
431 */
432 public function add(\ion\Symbol|string $symbol) : int;
433
434 /**
435 * Find a symbol within the symbol table, including imports.
436 *
437 * @param string|int $id The ID or text of the symbol to find.
438 * @return \ion\Symbol|null The symbol found, if any.
439 */
440 public function find(string|int $id) : ?\ion\Symbol;
441
442 /**
443 * Find a symbol within **only this** symbol table, ignoring imports.
444 *
445 * @param string|int $id The ID or text of the symbol to find.
446 * @return \ion\Symbol|null The symbol found, if any.
447 */
448 public function findLocal(string|int $id) : ?\ion\Symbol;
449 }
450
451 /**
452 * The built-in ION system symbols.
453 */
454 enum System : string implements \ion\Symbol\Enum {
455 case Ion = '$ion';
456 case Ivm_1_0 = '$ion_1_0';
457 case IonSymbolTable = '$ion_symbol_table';
458 case Name = 'name';
459 case Version = 'version';
460 case Imports = 'imports';
461 case Symbols = 'symbols';
462 case MaxId = 'max_id';
463 case SharedSymbolTable = '$ion_shared_symbol_table';
464
465 /** @alias ion\Symbol\Enum::toSymbol */
466 public function toSymbol() : \ion\Symbol {}
467 /** @alias ion\Symbol\Enum::toSID */
468 public function toSID() : int {}
469 /** @alias ion\Symbol\Enum::toString */
470 public function toString() : string {}
471
472 /**
473 * Get the built-in ION system shared symbol table.
474 *
475 * @return Table\Shared The system symbol table.
476 */
477 public static function asTable() : Table\Shared {}
478 }
479
480 /**
481 * The built-in PHP symbols.
482 */
483 enum PHP : string implements \ion\Symbol\Enum {
484 case PHP = 'PHP';
485 case Reference = 'R';
486 case Backref = 'r';
487 case Property = 'p';
488 case Object = 'o';
489 case ClassObject = 'c';
490 case MagicObject = 'O';
491 case CustomObject = 'C';
492 case Enum = 'E';
493 case Serializable = 'S';
494
495 /** @alias ion\Symbol\Enum::toSymbol */
496 public function toSymbol() : \ion\Symbol {}
497 /** @alias ion\Symbol\Enum::toSID */
498 public function toSID() : int {}
499 /** @alias ion\Symbol\Enum::toString */
500 public function toString() : string {}
501
502 /**
503 * Get the built-in PHP shared symbol table.
504 *
505 * @return Table\Shared The builtin PHP shared symbol table.
506 */
507 public static function asTable() : Table\Shared {}
508 }
509
510 namespace ion\Symbol\Table;
511
512 /**
513 * A local symbol table.
514 *
515 * @see https://amzn.github.io/ion-docs/guides/symbols-guide.html the ION spec's symbol guide
516 * @see https://amzn.github.io/ion-docs/guides/cookbook.html#using-a-local-symbol-table the ION doc's cookbook
517 */
518 class Local implements \ion\Symbol\Table {
519 /** Internal cache. */
520 private array $imports = [];
521 /** Internal cache. */
522 private array $symbols = [];
523
524 /**
525 * Create a local symbol table.
526 */
527 public function __construct() {}
528
529 /**
530 * Import a symbol table.
531 *
532 * @param \ion\Symbol\Table $table The symbol table to import.
533 * @return void
534 */
535 public function import(\ion\Symbol\Table $table) : void {}
536
537 /** @alias ion\Symbol\Table::getMaxId */
538 public function getMaxId() : int {}
539
540 /** @alias ion\Symbol\Table::add */
541 public function add(\ion\Symbol|string $symbol) : int {}
542 /** @alias ion\Symbol\Table::find */
543 public function find(string|int $id) : ?\ion\Symbol {}
544 /** @alias ion\Symbol\Table::findLocal */
545 public function findLocal(string|int $id) : ?\ion\Symbol {}
546 }
547
548 /**
549 * A shared symbol table.
550 *
551 * @see https://amzn.github.io/ion-docs/guides/symbols-guide.html the ION spec's symbol guide
552 * @see https://amzn.github.io/ion-docs/guides/cookbook.html#using-a-shared-symbol-table the ION doc's cookbook
553 */
554 class Shared implements \ion\Symbol\Table {
555 /**
556 * Create a shared symbol table.
557 */
558 public function __construct(
559 /**
560 * The name of the shared symbol table.
561 */
562 public readonly string $name,
563 /**
564 * The version of the shared symbol table.
565 */
566 public readonly int $version = 1,
567 /**
568 * Predefined list of symbols as array of strings.
569 */
570 ?array $symbols = null,
571 ) {}
572
573 /** Internal cache. */
574 private array $symbols = [];
575
576 /** @alias ion\Symbol\Table::getMaxId */
577 public function getMaxId() : int {}
578
579 /** @alias ion\Symbol\Table::add */
580 public function add(\ion\Symbol|string $symbol) : int {}
581 /** @alias ion\Symbol\Table::find */
582 public function find(string|int $id) : ?\ion\Symbol {}
583 /** @alias ion\Symbol\Table::findLocal */
584 public function findLocal(string|int $id) : ?\ion\Symbol {}
585 }
586
587 namespace ion\Decimal;
588
589 /**
590 * An ion\Decimal's context.
591 */
592 class Context {
593 /**
594 * Create a new decimal context.
595 */
596 public function __construct(
597 /**
598 * Maximum digits.
599 */
600 public readonly int $digits,
601 /**
602 * Maximum exponent.
603 */
604 public readonly int $eMax,
605 /**
606 * Minimum exponent.
607 */
608 public readonly int $eMin,
609 /**
610 * Rounding mode.
611 */
612 public readonly Context\Rounding|int $round,
613 /**
614 * Whether to clamp.
615 */
616 public readonly bool $clamp,
617 ) {}
618
619 /**
620 * Create a context suitable for 32bit decimals.
621 */
622 public static function Dec32() : Context {}
623
624 /**
625 * Create a context suitable for 64bit decimals.
626 */
627 public static function Dec64() : Context {}
628
629 /**
630 * Create a context suitable for 128bit decimals.
631 */
632 public static function Dec128() : Context {}
633
634 /**
635 * Create a context with maximum settings.
636 * @param Context\Rounding|int $round Rounding mode.
637 */
638 public static function DecMax(Context\Rounding|int $round = Context\Rounding::HalfEven) : Context {}
639 }
640
641 namespace ion\Decimal\Context;
642
643 /**
644 * Rounding mode.
645 */
646 enum Rounding : int {
647 case Ceiling = 0;
648 case Up = 1;
649 case HalfUp = 2;
650 case HalfEven = 3;
651 case HalfDown = 4;
652 case Down = 5;
653 case Floor = 6;
654 case Down05Up = 7;
655 }
656
657 namespace ion\Timestamp;
658
659 /**
660 * Timestamp precision.
661 */
662 enum Precision : int {
663 case Year = 0x1;
664 case Month = 0x1|0x2;
665 case Day = 0x1|0x2|0x4;
666 case Min = 0x1|0x2|0x4|0x10;
667 case Sec = 0x1|0x2|0x4|0x10|0x20;
668 case Frac = 0x1|0x2|0x4|0x10|0x20|0x40;
669 case MinTZ = 0x1|0x2|0x4|0x10|0x80;
670 case SecTZ = 0x1|0x2|0x4|0x10|0x20|0x80;
671 case FracTZ = 0x1|0x2|0x4|0x10|0x20|0x40|0x80;
672 }
673
674 /**
675 * Timestamp format.
676 */
677 enum Format : string {
678 case Year = "Y\T";
679 case Month = "Y-m\T";
680 case Day = "Y-m-d\T";
681 case Min = "Y-m-d\TH:i";
682 case Sec = "Y-m-d\TH:i:s";
683 case Frac = "Y-m-d\TH:i:s.v";
684 case MinTZ = "Y-m-d\TH:iP";
685 case SecTZ = "Y-m-d\TH:i:sP";
686 case FracTZ = "Y-m-d\TH:i:s.vP";
687 }
688
689 namespace ion\Reader;
690
691 /**
692 * Reader options.
693 */
694 class Options {
695 public function __construct(
696 /**
697 * ION catalog to use for symbol lookup.
698 */
699 public readonly ?\ion\Catalog $catalog = null,
700 /**
701 * Decimal context to use.
702 */
703 public readonly ?\ion\Decimal\Context $decimalContext = null,
704 /**
705 * Callback as function(\ion\Reader):void called upon local symbol table context change.
706 */
707 public readonly ?\Closure $onContextChange = null,
708 /**
709 * Whether to return otherwise hidden system values.
710 */
711 public readonly bool $returnSystemValues = false,
712 /**
713 * The maximum depth of nested containers.
714 */
715 public readonly int $maxContainerDepth = 10,
716 /**
717 * The maximum number of annotations allowed on a single value.
718 */
719 public readonly int $maxAnnotations = 10,
720 /**
721 * The maximum number of bytes of all annotations on a single value.
722 */
723 public readonly int $annotationBufferSize = 0x4000,
724 /**
725 * The maximum number of bytes of a symbol/value/chunk.
726 */
727 public readonly int $tempBufferSize = 0x4000,
728 /**
729 * Whether to skip UTF-8 validation.
730 */
731 public readonly bool $skipCharacterValidation = false,
732 ) {}
733 }
734
735 /**
736 * Base implementation of ION readers.
737 */
738 abstract class Reader implements \ion\Reader {
739 /**
740 * Reader options.
741 */
742 public readonly ?Options $options;
743
744 public function hasChildren() : bool {}
745 public function getChildren() : \ion\Reader {}
746
747 public function rewind() : void {}
748 public function next() : void {}
749 public function valid() : bool {}
750 public function key() : mixed {}
751 public function current() : mixed {}
752
753 public function getType() : \ion\Type {}
754 public function hasAnnotations() : bool {}
755 public function hasAnnotation(string $annotation) : bool {}
756 public function isNull() : bool {}
757 public function isInStruct() : bool {}
758 public function getFieldName() : string {}
759 public function getFieldNameSymbol() : \ion\Symbol {}
760 public function getAnnotations() : array {}
761 public function getAnnotationSymbols() : array {}
762 public function countAnnotations() : int {}
763 public function getAnnotation(int $index) : string {}
764 public function getAnnotationSymbol(int $index) : \ion\Symbol {}
765
766 public function readNull() : \ion\Type {}
767 public function readBool() : bool {}
768 public function readInt() : int|string {}
769 public function readFloat() : float {}
770 public function readDecimal() : \ion\Decimal {}
771 public function readTimestamp() : \ion\Timestamp {}
772 public function readSymbol() : \ion\Symbol {}
773 public function readString() : string {}
774 /** @param ref $string */
775 public function readStringPart(&$string, int $length = 0x1000) : bool {}
776 public function readLob() : string {}
777 /** @param ref $string */
778 public function readLobPart(&$string, int $length = 0x1000) : bool {}
779
780 public function getPosition() : int {}
781 public function getDepth() : int{}
782
783 public function seek(int $offset, int $length = -1) : void {}
784 /*
785 public function getSymbolTable() : SymbolTable {}
786 public function setSymbolTable(SymbolTable $table) : void {}
787 */
788 public function getValueOffset() : int {}
789 public function getValueLength() : int {}
790 }
791
792 /**
793 * ION string buffer reader API.
794 */
795 interface Buffer extends \ion\Reader {
796 /**
797 * Get the buffer read from.
798 *
799 * @return string The buffer read from.
800 */
801 public function getBuffer() : string;
802 }
803
804 /**
805 * ION stream reader API.
806 */
807 interface Stream extends \ion\Reader {
808 /**
809 * Get the stream read from.
810 *
811 * @return resource The stream read from.
812 */
813 public function getStream();
814
815 /**
816 * Reset the stream read from.
817 *
818 * @param resource $stream The new stream to from.
819 */
820 public function resetStream($stream) : void;
821
822 /**
823 * Reset the stream read from, limiting length to read.
824 *
825 * @param resource $stream The stream to read from.
826 * @param int $length The maximum length to read from $stream.
827 */
828 public function resetStreamWithLength($stream, int $length) : void;
829 }
830
831 namespace ion\Reader\Buffer;
832
833 /**
834 * ION buffer reader.
835 */
836 class Reader extends \ion\Reader\Reader implements \ion\Reader\Buffer {
837 /**
838 * Create a new string buffer reader.
839 *
840 * @param string $buffer The buffer to read from.
841 * @param \ion\Reader\Options|array|null $options Reader options.
842 */
843 public function __construct(
844 string $buffer,
845 \ion\Reader\Options|array|null $options = null,
846 ) {}
847
848 public function getBuffer() : string {}
849 }
850
851 namespace ion\Reader\Stream;
852
853 /**
854 * ION stream reader.
855 */
856 class Reader extends \ion\Reader\Reader implements \ion\Reader\Stream {
857 /**
858 * Create a new stream reader.
859 *
860 * @param resource $stream The stream to read from.
861 * @param \ion\Reader\Options|array|null $options Reader options.
862 */
863 public function __construct(
864 $stream,
865 \ion\Reader\Options|array|null $options = null,
866 ) {}
867
868 /**
869 * Get the stream read from.
870 *
871 * @return resource The stream read from.
872 */
873 public function getStream() {}
874
875 /** @param resource $stream */
876 public function resetStream($stream) : void {}
877 /** @param resource $stream */
878 public function resetStreamWithLength($stream, int $length) : void {}
879 }
880
881 namespace ion\Writer;
882
883 /**
884 * ION writer options.
885 */
886 class Options {
887 /**
888 * Create custom ION writer options.
889 */
890 public function __construct(
891 /**
892 * ION catalog to use for symbol lookup.
893 */
894 public readonly ?\ion\Catalog $catalog = null,
895 /**
896 * Decimal context to use.
897 */
898 public readonly ?\ion\Decimal\Context $decimalContext = null,
899 /**
900 * Whether to output binary ION.
901 */
902 public readonly bool $outputBinary = false,
903 /**
904 * Whether to write doubles which fit in 32 bits as floats.
905 */
906 public readonly bool $compactFloats = false,
907 /**
908 * Whether to slash-escape all non ASCII bytes.
909 */
910 public readonly bool $escapeNonAscii = false,
911 /**
912 * Whether to produce pretty-printed output.
913 */
914 public readonly bool $prettyPrint = false,
915 /**
916 * Whether to indent with tabs, when pretty-printing.
917 */
918 public readonly bool $indentTabs = true,
919 /**
920 * The number of spaces to use for indentation instead of tabs, when pretty-printing.
921 */
922 public readonly int $indentSize = 2,
923 /**
924 * Whether to immediately flush every value written.
925 */
926 public readonly bool $flushEveryValue = false,
927 /**
928 * Maximum depth of nested containers.
929 */
930 public readonly int $maxContainerDepth = 10,
931 /**
932 * The maximum number of annotations allowed on a single value.
933 */
934 public readonly int $maxAnnotations = 10,
935 /**
936 * Temporary buffer size.
937 */
938 public readonly int $tempBufferSize = 0x4000,
939 ) {}
940 }
941
942 /**
943 * Base implementation of common functionality of ION writers.
944 */
945 abstract class Writer implements \ion\Writer {
946 public function writeNull() : void {}
947 public function writeTypedNull(\ion\Type $type) : void {}
948 public function writeBool(bool $value) : void {}
949 public function writeInt(int|string $value) : void {}
950 public function writeFloat(float $value) : void {}
951 public function writeDecimal(\ion\Decimal|string $value) : void {}
952 public function writeTimestamp(\ion\Timestamp|string $value) : void {}
953 public function writeSymbol(\ion\Symbol|string $value) : void {}
954 public function writeString(string $value) : void {}
955 public function writeCLob(string $value) : void {}
956 public function writeBLob(string $value) : void {}
957
958 public function startLob(\ion\Type $type) : void {}
959 public function appendLob(string $data) : void {}
960 public function finishLob() : void {}
961
962 public function startContainer(\ion\Type $type) : void {}
963 public function finishContainer() : void {}
964
965 public function writeFieldName(string $name) : void {}
966
967 public function writeAnnotation(\ion\Symbol|string ...$annotation) : void {}
968
969 public function getDepth() : int {}
970 public function flush() : int {}
971 public function finish() : int {}
972
973 // public function writeOne(\ion\Reader $reader) : void {}
974 // public function writeAll(\ion\Reader $reader) : void {}
975 }
976
977 /**
978 * ION buffer writer API.
979 */
980 interface Buffer extends \ion\Writer {
981 /**
982 * Get the buffer written to.
983 *
984 * @reeturn string The buffer written so far.
985 */
986 public function getBuffer() : string;
987
988 /**
989 * Reset the buffer written to.
990 */
991 public function resetBuffer() : void;
992 }
993
994 /**
995 * ION stream writer API.
996 */
997 interface Stream extends \ion\Writer {
998 /**
999 * Get the stream being written to.
1000 * @return resource
1001 */
1002 public function getStream();
1003 }
1004
1005 namespace ion\Writer\Buffer;
1006
1007 /**
1008 * IO buffer writer.
1009 */
1010 class Writer extends \ion\Writer\Writer implements \ion\Writer\Buffer {
1011 /**
1012 * Create a new buffer writer.
1013 *
1014 * @param \ion\Writer\Options|array|null $options Writer options.
1015 */
1016 public function __construct(
1017 \ion\Writer\Options|array|null $options = null,
1018 ) {}
1019
1020 public function getBuffer() : string {}
1021 public function resetBuffer() : void {}
1022 }
1023
1024 namespace ion\Writer\Stream;
1025
1026 /**
1027 * ION stream writer.
1028 */
1029 class Writer extends \ion\Writer\Writer implements \ion\Writer\Stream {
1030 /**
1031 * Create a new stream writer.
1032 *
1033 * @param resource $stream The stream to write to.
1034 * @param \ion\Writer\Options|array|null $options Writer options.
1035 */
1036 public function __construct(
1037 $stream,
1038 \ion\Writer\Options|array|null $options = null,
1039 ) {}
1040 /**
1041 * @return resource
1042 */
1043 public function getStream() {}
1044 }
1045
1046 namespace ion\Serializer;
1047 /**
1048 * Serializer implementation
1049 */
1050 class Serializer implements \ion\Serializer {
1051 /**
1052 * Create a new ION serializer.
1053 */
1054 public function __construct(
1055 /**
1056 * Whether to write the top level array as multiple ION sequences.
1057 */
1058 public readonly bool $multiSequence = false,
1059 /**
1060 * Whether to call magic __serialize() methods on objects to serialize.
1061 */
1062 public readonly bool $callMagicSerialize = true,
1063 /**
1064 * Whether and which custom serialize method to call on objects to serialize.
1065 */
1066 public readonly ?string $callCustomSerialize = null,
1067 ) {}
1068
1069 public function serialize(mixed $data, \ion\Writer|\ion\Writer\Options|array|null $writer = null) : mixed {}
1070 }
1071
1072 namespace ion\Unserializer;
1073
1074 /**
1075 * Unserializer implementation
1076 */
1077 class Unserializer implements \ion\Unserializer {
1078 /**
1079 * Create a new ION unserializer.
1080 */
1081 public function __construct(
1082 /**
1083 * Whether to continue reading multiple ION sequences after the first one.
1084 */
1085 public readonly bool $multiSequence = false,
1086 /**
1087 * Whether to call magic __unserialize() methods on objects to unserialize.
1088 */
1089 public readonly bool $callMagicUnserialize = true,
1090 /**
1091 * Whether and which custom unserialize method to call on objects to unserialize.
1092 */
1093 public readonly ?string $callCustomUnserialize = null,
1094 ){}
1095
1096 /** @param \ion\Reader|string|resource $data */
1097 public function unserialize($data) : mixed {}
1098 }