Class List Method List File List

# Class: Vertx::RecordParser

Inherits:
  Object
  - Object
  - Vertx::RecordParser
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb

## Overview

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 '\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.

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
- + (::Vertx::RecordParser) new_delimited(param_1 = nil)
  Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented by the Buffer delim.
- + (::Vertx::RecordParser) new_fixed(size = nil) { ... }
  Create a new RecordParser instance, initially in fixed size mode, and where the record size is specified by the size parameter.
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (void) delimited_mode(param_1 = nil)
  Flip the parser into delimited mode, and where the delimiter can be represented by the delimiter delim.
- - (void) fixed_size_mode(size = nil)
  Flip the parser into fixed size mode, where the record size is specified by size in bytes.
- - (void) handle(buffer = nil)
  This method is called to provide the parser with data.
- - (void) set_output { ... }

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

    46
    47
    48
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 46

    def @@j_api_type.accept?(obj)
      obj.class == RecordParser
    end

### + (`Object`) j_api_type

    55
    56
    57
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 55

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    58
    59
    60
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 58

    def self.j_class
      Java::IoVertxCoreParsetools::RecordParser.java_class
    end

### + (`::Vertx::RecordParser`) newDelimited(delim, output) { ... } + (`::Vertx::RecordParser`) newDelimited(delim, output) { ... }

Create a new `RecordParser` instance, initially in delimited mode, and where the delimiter can be represented by the `Buffer` delim.

`output` Will receive whole records which have been parsed.

Overloads:

- + (`::Vertx::RecordParser`) newDelimited(delim, output) { ... }

  Parameters:

  - delim (`String`) —
    the initial delimiter string

  Yields:

  - handler that will receive the output
- + (`::Vertx::RecordParser`) newDelimited(delim, output) { ... }

  Parameters:

  - delim (`::Vertx::Buffer`) —
    the initial delimiter buffer

  Yields:

  - handler that will receive the output

Returns:

- (`::Vertx::RecordParser`)

Raises:

- (`ArgumentError`)

    80
    81
    82
    83
    84
    85
    86
    87
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 80

    def self.new_delimited(param_1=nil)
      if param_1.class == String && block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newDelimited, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) })),::Vertx::RecordParser)
      elsif param_1.class.method_defined?(:j_del) && block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newDelimited, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1.j_del,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) })),::Vertx::RecordParser)
      end
      raise ArgumentError, "Invalid arguments when calling new_delimited(#{param_1})"
    end

### + (`::Vertx::RecordParser`) new_fixed(size = nil) { ... }

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

`output` Will receive whole records which have been parsed.

Parameters:

- size (`Fixnum`) (defaults to: `nil`) —
  the initial record size

Yields:

- handler that will receive the output

Returns:

- (`::Vertx::RecordParser`)

Raises:

- (`ArgumentError`)

    95
    96
    97
    98
    99
    100
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 95

    def self.new_fixed(size=nil)
      if size.class == Fixnum && block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newFixed, [Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(size,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) })),::Vertx::RecordParser)
      end
      raise ArgumentError, "Invalid arguments when calling new_fixed(#{size})"
    end

### + (`Object`) unwrap(obj)

    52
    53
    54
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 52

    def @@j_api_type.unwrap(obj)
      obj.j_del
    end

### + (`Object`) wrap(obj)

    49
    50
    51
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 49

    def @@j_api_type.wrap(obj)
      RecordParser.new(obj)
    end

## Instance Method Details

### - (`void`) delimitedMode(delim) - (`void`) delimitedMode(delim)

This method returns an undefined value.

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.

Overloads:

- - (`void`) delimitedMode(delim)

  Parameters:

  - delim (`String`) —
    the new delimeter
- - (`void`) delimitedMode(delim)

  Parameters:

  - delim (`::Vertx::Buffer`) —
    the new delimiter

Raises:

- (`ArgumentError`)

    110
    111
    112
    113
    114
    115
    116
    117
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 110

    def delimited_mode(param_1=nil)
      if param_1.class == String && !block_given?
        return @j_del.java_method(:delimitedMode, [Java::java.lang.String.java_class]).call(param_1)
      elsif param_1.class.method_defined?(:j_del) && !block_given?
        return @j_del.java_method(:delimitedMode, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(param_1.j_del)
      end
      raise ArgumentError, "Invalid arguments when calling delimited_mode(#{param_1})"
    end

### - (`void`) fixed_size_mode(size = nil)

This method returns an undefined value.

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 (`Fixnum`) (defaults to: `nil`) —
  the new record size

Raises:

- (`ArgumentError`)

    123
    124
    125
    126
    127
    128
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 123

    def fixed_size_mode(size=nil)
      if size.class == Fixnum && !block_given?
        return @j_del.java_method(:fixedSizeMode, [Java::int.java_class]).call(size)
      end
      raise ArgumentError, "Invalid arguments when calling fixed_size_mode(#{size})"
    end

### - (`void`) handle(buffer = nil)

This method returns an undefined value.

This method is called to provide the parser with data.

Parameters:

- buffer (`::Vertx::Buffer`) (defaults to: `nil`) —
  a chunk of data

Raises:

- (`ArgumentError`)

    132
    133
    134
    135
    136
    137
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 132

    def handle(buffer=nil)
      if buffer.class.method_defined?(:j_del) && !block_given?
        return @j_del.java_method(:handle, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(buffer.j_del)
      end
      raise ArgumentError, "Invalid arguments when calling handle(#{buffer})"
    end

### - (`void`) set_output { ... }

This method returns an undefined value.

Yields:

Raises:

- (`ArgumentError`)

    63
    64
    65
    66
    67
    68
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/record_parser.rb', line 63

    def set_output
      if block_given?
        return @j_del.java_method(:setOutput, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) }))
      end
      raise ArgumentError, "Invalid arguments when calling set_output()"
    end