class JsonStreamDecoder (View source)

Constants

ESCAPE_CHAR

Methods

__construct(StreamInterface $stream, string $decodeType, array $options = [])

JsonStreamDecoder is a HTTP-JSON response stream decoder for JSON-ecoded protobuf messages. The response stream must be a JSON array, where the first byte is the opening of the array (i.e. '['), and the last byte is the closing of the array (i.e. ']'). Each array item must be a JSON object and comma separated.

decode()

Begins decoding the configured response stream. It is a generator which yields messages of the given decode type from the stream until the stream completes. Throws an Exception if the stream is closed before the closing byte is read or if it encounters an error while decoding a message.

void
close()

Closes the underlying stream. If the stream is actively being decoded, an exception will not be thrown due to the interruption.

Details

__construct(StreamInterface $stream, string $decodeType, array $options = [])

JsonStreamDecoder is a HTTP-JSON response stream decoder for JSON-ecoded protobuf messages. The response stream must be a JSON array, where the first byte is the opening of the array (i.e. '['), and the last byte is the closing of the array (i.e. ']'). Each array item must be a JSON object and comma separated.

Parameters

StreamInterface $stream

The stream to decode.

string $decodeType

The type name of response messages to decode.

array $options

{ An array of optional arguments.

@type bool $ignoreUnknown
      Toggles whether or not to throw an exception when an unknown field
      is encountered in a response message. The default is true.
@type int $readChunkSizeBytes
      The upper size limit in bytes that can be read at a time from the
      response stream. The default is 1 KB.

}

Generator decode()

Begins decoding the configured response stream. It is a generator which yields messages of the given decode type from the stream until the stream completes. Throws an Exception if the stream is closed before the closing byte is read or if it encounters an error while decoding a message.

Return Value

Generator

Exceptions

RuntimeException

void close()

Closes the underlying stream. If the stream is actively being decoded, an exception will not be thrown due to the interruption.

Return Value

void