RecordParser

A helper class which allows you to easily parse protocols which are delimited by a sequence of bytes, or fixed size records.

Instances of this class take as input @see \io\vertx\jphp\core\buffer\Buffer instances containing raw bytes, and output records.

For example, if I had a simple ASCII text protocol delimited by '\n' and the input was the following:

buffer1:HELLO\nHOW ARE Y
buffer2:OU?\nI AM
buffer3: DOING OK
buffer4:\n
Then the output would be:

buffer1:HELLO
buffer2:HOW ARE YOU?
buffer3:I AM DOING OK
Instances of this class can be changed between delimited mode and fixed size record mode on the fly as individual records are read, this allows you to parse protocols where, for example, the first 5 records might all be fixed size (of potentially different sizes), followed by some delimited records, followed by more fixed size records.

Instances of this class can't currently be used for protocols where the text is encoded with something other than a 1-1 byte-char mapping.

Please see the documentation for more information.

package

Default

Methods

__construct

__construct() 

Flip the parser into delimited mode, and where the delimiter can be represented by the String <code>delim</code> encoded in latin-1 . Don't use this if your String contains other than latin-1 characters.

delimitedMode( $arg0) : void

This method can be called multiple times with different values of delim while data is being parsed. param $delim [string] the new delimeter delimitedMode($delim) Flip the parser into delimited mode, and where the delimiter can be represented by the delimiter delim.

This method can be called multiple times with different values of delim while data is being parsed. param $delim [Buffer] the new delimiter delimitedMode($delim)

Arguments

$arg0

Buffer | string

endHandler

endHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

exceptionHandler

exceptionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

fetch

fetch( $arg0) : $this

Arguments

$arg0

integer

Response

$this

Flip the parser into fixed size mode, where the record size is specified by <code>size</code> in bytes.

fixedSizeMode( $arg0) : void

This method can be called multiple times with different values of size while data is being parsed.

Arguments

$arg0

integer

This method is called to provide the parser with data.

handle( $arg0) : void

Arguments

$arg0

Buffer

handler

handler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

Set the maximum allowed size for a record when using the delimited mode.

maxRecordSize( $arg0) : $this

The delimiter itself does not count for the record size.

If a record is longer than specified, an \java.lang.IllegalStateException will be thrown.

Arguments

$arg0

integer

Response

$this

a reference to this, so the API can be used fluently

Create a new <code>RecordParser</code> instance, initially in delimited mode, and where the delimiter can be represented by the String <code></code> delim endcoded in latin-1 . Don't use this if your String contains other than latin-1 characters.

newDelimited( $arg0,  $arg1 = null) : \io\vertx\jphp\core\parsetools\RecordParser
static

output Will receive whole records which have been parsed. param $delim [string] the initial delimiter string newDelimited($delim) Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented by the Buffer delim.

param $delim [Buffer] the initial delimiter buffer newDelimited($delim) Like @see \io\vertx\jphp\core\parsetools\RecordParser::newDelimited but set the output that will receive whole records which have been parsed. param $delim [string] the initial delimiter string param $output [callable] handler that will receive the output newDelimited($delim, $output) Like @see \io\vertx\jphp\core\parsetools\RecordParser::newDelimited but wraps the stream. The stream handlers will be set/unset when the @see \io\vertx\jphp\core\parsetools\RecordParser::handler is set.

The pause()/resume() operations are propagated to the stream. param $delim [string] the initial delimiter string param $stream [ReadStream] the wrapped stream newDelimited($delim, $stream) Like @see \io\vertx\jphp\core\parsetools\RecordParser::newDelimited but set the output that will receive whole records which have been parsed. param $delim [Buffer] the initial delimiter buffer param $output [callable] handler that will receive the output newDelimited($delim, $output) Like @see \io\vertx\jphp\core\parsetools\RecordParser::newDelimited but wraps the stream. The stream handlers will be set/unset when the @see \io\vertx\jphp\core\parsetools\RecordParser::handler is set.

The pause()/resume() operations are propagated to the stream. param $delim [Buffer] the initial delimiter buffer param $stream [ReadStream] the wrapped stream newDelimited($delim, $stream)

Arguments

$arg0

Buffer | string

$arg1

callable | ReadStream

Response

\io\vertx\jphp\core\parsetools\RecordParser

Create a new <code>RecordParser</code> instance, initially in fixed size mode, and where the record size is specified by the <code>size</code> parameter.

newFixed( $arg0,  $arg1 = null) : \io\vertx\jphp\core\parsetools\RecordParser
static

output Will receive whole records which have been parsed. param $size [integer] the initial record size newFixed($size) Like @see \io\vertx\jphp\core\parsetools\RecordParser::newFixed but set the output that will receive whole records which have been parsed. param $size [integer] the initial record size param $output [callable] handler that will receive the output newFixed($size, $output) Like @see \io\vertx\jphp\core\parsetools\RecordParser::newFixed but wraps the stream. The stream handlers will be set/unset when the @see \io\vertx\jphp\core\parsetools\RecordParser::handler is set.

The pause()/resume() operations are propagated to the stream. param $size [integer] the initial record size param $stream [ReadStream] the wrapped stream newFixed($size, $stream)

Arguments

$arg0

integer

$arg1

callable | ReadStream

Response

\io\vertx\jphp\core\parsetools\RecordParser

pause

pause() : $this

Response

$this

resume

resume() : $this

Response

$this

setOutput

setOutput( $arg0) : void

Arguments

$arg0

callable