Skip to content

Commit

Permalink
remove Options classes
Browse files Browse the repository at this point in the history
  • Loading branch information
m6w6 committed Apr 28, 2022
1 parent a34b502 commit 717c399
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 761 deletions.
343 changes: 148 additions & 195 deletions ion.c

Large diffs are not rendered by default.

119 changes: 63 additions & 56 deletions ion.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ function unserialize($data, Unserializer|array|null $unserializer = null) : mixe
* Serializer interface, used to customize ion\serialize()'s behavior.
*/
interface Serializer {
public function serialize(mixed $data, \ion\Writer|\ion\Writer\Options|array|null $writer = null) : mixed;
public function serialize(mixed $data, Writer|array|null $writer = null) : mixed;
}

/**
* Unserializer interface, used to customize ion\unserialize()'s behavior.
*/
interface Unserializer {
/** @param \ion\Reader|string|resource $data */
/** @param Reader|string|resource $data */
public function unserialize($data) : mixed;
}

Expand Down Expand Up @@ -689,10 +689,14 @@ enum Format : string {
namespace ion\Reader;

/**
* Reader options.
* Base implementation of ION readers.
*/
class Options {
abstract class Reader implements \ion\Reader {
/**
* @param string|resource $data The string or resource to read from.
*/
public function __construct(
$data,
/**
* ION catalog to use for symbol lookup.
*/
Expand Down Expand Up @@ -730,16 +734,6 @@ public function __construct(
*/
public readonly bool $skipCharacterValidation = false,
) {}
}

/**
* Base implementation of ION readers.
*/
abstract class Reader implements \ion\Reader {
/**
* Reader options.
*/
public readonly ?Options $options;

public function hasChildren() : bool {}
public function getChildren() : \ion\Reader {}
Expand Down Expand Up @@ -794,7 +788,7 @@ public function getValueLength() : int {}
*/
interface Buffer extends \ion\Reader {
/**
* Get the buffer read from.
* Get the buffer being read from.
*
* @return string The buffer read from.
*/
Expand All @@ -806,7 +800,7 @@ public function getBuffer() : string;
*/
interface Stream extends \ion\Reader {
/**
* Get the stream read from.
* Get the stream being read from.
*
* @return resource The stream read from.
*/
Expand Down Expand Up @@ -834,16 +828,6 @@ public function resetStreamWithLength($stream, int $length) : void;
* ION buffer reader.
*/
class Reader extends \ion\Reader\Reader implements \ion\Reader\Buffer {
/**
* Create a new string buffer reader.
*
* @param string $buffer The buffer to read from.
* @param \ion\Reader\Options|array|null $options Reader options.
*/
public function __construct(
string $buffer,
\ion\Reader\Options|array|null $options = null,
) {}

public function getBuffer() : string {}
}
Expand All @@ -854,16 +838,6 @@ public function getBuffer() : string {}
* ION stream reader.
*/
class Reader extends \ion\Reader\Reader implements \ion\Reader\Stream {
/**
* Create a new stream reader.
*
* @param resource $stream The stream to read from.
* @param \ion\Reader\Options|array|null $options Reader options.
*/
public function __construct(
$stream,
\ion\Reader\Options|array|null $options = null,
) {}

/**
* Get the stream read from.
Expand All @@ -881,11 +855,11 @@ public function resetStreamWithLength($stream, int $length) : void {}
namespace ion\Writer;

/**
* ION writer options.
* Base implementation of common functionality of ION writers.
*/
class Options {
abstract class Writer implements \ion\Writer {
/**
* Create custom ION writer options.
* Create custom ION writer.
*/
public function __construct(
/**
Expand Down Expand Up @@ -937,12 +911,7 @@ public function __construct(
*/
public readonly int $tempBufferSize = 0x4000,
) {}
}

/**
* Base implementation of common functionality of ION writers.
*/
abstract class Writer implements \ion\Writer {
public function writeNull() : void {}
public function writeTypedNull(\ion\Type $type) : void {}
public function writeBool(bool $value) : void {}
Expand Down Expand Up @@ -1005,17 +974,9 @@ public function getStream();
namespace ion\Writer\Buffer;

/**
* IO buffer writer.
* ION buffer writer.
*/
class Writer extends \ion\Writer\Writer implements \ion\Writer\Buffer {
/**
* Create a new buffer writer.
*
* @param \ion\Writer\Options|array|null $options Writer options.
*/
public function __construct(
\ion\Writer\Options|array|null $options = null,
) {}

public function getBuffer() : string {}
public function resetBuffer() : void {}
Expand All @@ -1031,11 +992,57 @@ class Writer extends \ion\Writer\Writer implements \ion\Writer\Stream {
* Create a new stream writer.
*
* @param resource $stream The stream to write to.
* @param \ion\Writer\Options|array|null $options Writer options.
*/
public function __construct(
$stream,
\ion\Writer\Options|array|null $options = null,
/**
* ION catalog to use for symbol lookup.
*/
public readonly ?\ion\Catalog $catalog = null,
/**
* Decimal context to use.
*/
public readonly ?\ion\Decimal\Context $decimalContext = null,
/**
* Whether to output binary ION.
*/
public readonly bool $outputBinary = false,
/**
* Whether to write doubles which fit in 32 bits as floats.
*/
public readonly bool $compactFloats = false,
/**
* Whether to slash-escape all non ASCII bytes.
*/
public readonly bool $escapeNonAscii = false,
/**
* Whether to produce pretty-printed output.
*/
public readonly bool $prettyPrint = false,
/**
* Whether to indent with tabs, when pretty-printing.
*/
public readonly bool $indentTabs = true,
/**
* The number of spaces to use for indentation instead of tabs, when pretty-printing.
*/
public readonly int $indentSize = 2,
/**
* Whether to immediately flush every value written.
*/
public readonly bool $flushEveryValue = false,
/**
* Maximum depth of nested containers.
*/
public readonly int $maxContainerDepth = 10,
/**
* The maximum number of annotations allowed on a single value.
*/
public readonly int $maxAnnotations = 10,
/**
* Temporary buffer size.
*/
public readonly int $tempBufferSize = 0x4000,
) {}
/**
* @return resource
Expand Down Expand Up @@ -1066,7 +1073,7 @@ public function __construct(
public readonly ?string $callCustomSerialize = null,
) {}

public function serialize(mixed $data, \ion\Writer|\ion\Writer\Options|array|null $writer = null) : mixed {}
public function serialize(mixed $data, \ion\Writer|array|null $writer = null) : mixed {}
}

namespace ion\Unserializer;
Expand Down
Loading

0 comments on commit 717c399

Please sign in to comment.