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 Buffer instances containing raw bytes, and output records.

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

 buffer1:HELLO
HOW ARE Y
 buffer2:OU?
I AM
 buffer3: DOING OK
 buffer4:

 

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.

no subtypes hierarchy

Initializer
RecordParser(RecordParser unknown)
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
delimitedModeshared default void delimitedMode(Buffer 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.

Parameters:
  • delim

    the new delimiter

delimitedModeshared default void delimitedMode(String delim)

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

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

Parameters:
  • delim

    the new delimeter

endHandlershared actual default RecordParser endHandler(Anything()? endHandler)

Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.

exceptionHandlershared actual default RecordParser exceptionHandler(Anything(Throwable)? handler)

Set an exception handler.

fixedSizeModeshared default void fixedSizeMode(Integer size)

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

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

Parameters:
  • size

    the new record size

handleshared default void handle(Buffer buffer)

This method is called to provide the parser with data.

Parameters:
  • buffer

    a chunk of data

handlershared actual default RecordParser handler(Anything(Buffer)? handler)

Set a data handler. As data is read, the handler will be called with the data.

maxRecordSizeshared default RecordParser maxRecordSize(Integer size)

Set the maximum allowed size for a record when using the delimited mode. The delimiter itself does not count for the record size.

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

Parameters:
  • size

    the maximum record size

pauseshared actual default RecordParser pause()

Pause the ReadSupport. While it's paused, no data will be sent to the dataHandler

resumeshared actual default RecordParser resume()

Resume reading. If the ReadSupport has been paused, reading will recommence on it.

setOutputshared default void setOutput(Anything(Buffer) output)
Inherited Methods
Methods inherited from: Object
equals
Methods inherited from: ReadStream<T>
Methods inherited from: StreamBase