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:\nThen the output would be:
buffer1:HELLO buffer2:HOW ARE YOU? buffer3:I AM DOING OKInstances 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 |
---|
__construct()
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)
Buffer | string
endHandler( $arg0) : $this
callable
$this
exceptionHandler( $arg0) : $this
callable
$this
fetch( $arg0) : $this
integer
$this
fixedSizeMode( $arg0) : void
This method can be called multiple times with different values of size while data is being parsed.
integer
handle( $arg0) : void
Buffer
handler( $arg0) : $this
callable
$this
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.
integer
$this
a reference to this, so the API can be used fluently
newDelimited( $arg0, $arg1 = null) : \io\vertx\jphp\core\parsetools\RecordParser
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.
pause()
/resume()
operations are propagated to the stream
.
param $delim [string] the initial delimiter string
param $stream [ReadStreamoutput
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
Buffer | string
callable | ReadStream
\io\vertx\jphp\core\parsetools\RecordParser
newFixed( $arg0, $arg1 = null) : \io\vertx\jphp\core\parsetools\RecordParser
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.
pause()
/resume()
operations are propagated to the stream
.
param $size [integer] the initial record size
param $stream [ReadStream
integer
callable | ReadStream
\io\vertx\jphp\core\parsetools\RecordParser
pause() : $this
$this
resume() : $this
$this
setOutput( $arg0) : void
callable