Class: Rapid::Baps::Reader

Inherits:
Services::ResponseBuffer show all
Defined in:
lib/ury_rapid/baps/reader.rb

Overview

A low-level reading interface to the BAPS meta-protocol

The Reader works by operating on an internal buffer which can have new data fed to it.

Constant Summary collapse

PACKED_REQUESTS =

Create helpers for requesting BAPS primitive types. Each type results in a one-member unpacked array, so discard the array before yielding.

{
  uint32:  [4, FormatStrings::UINT32],
  uint16:  [2, FormatStrings::UINT16],
  float32: [4, FormatStrings::FLOAT32]
}

Instance Method Summary collapse

Methods inherited from Services::ResponseBuffer

#add, #initialize, #packed_request, #request

Constructor Details

This class inherits a constructor from Rapid::Services::ResponseBuffer

Instance Method Details

#command {|The| ... } ⇒ void

This method returns an undefined value.

Requests that the Reader read a BAPS command header

A BAPS command is begun with a 16-bit command word, which is yielded to the given block, and a 32-bit payload length, which is ignored (as it is untrustworthy, and we hopefully need not skip payloads as we understand every common BAPS command).

Examples:

Read a command word, and print it out

reader.command { |word| p word }

Yield Parameters:

  • The (Integer)

    16-bit command word as read from the header.


62
63
64
65
# File 'lib/ury_rapid/baps/reader.rb', line 62

def command(&block)
  uint16(&block)
  uint32 { |_| nil }  # Ignore the incoming data count.
end

#string {|The| ... } ⇒ void

This method returns an undefined value.

Requests that the Reader read a BAPS-formatted string

The given block will be fired with the string as soon as it is read into the Reader's buffer.

Examples:

Read a String, and print it out

reader.string { |s| p s }

Yield Parameters:

  • The (String)

    read string.


38
39
40
41
42
43
44
45
# File 'lib/ury_rapid/baps/reader.rb', line 38

def string
  # BAPS strings are preceded by their length, Pascal-style.
  uint32 do |length|
    request(length, true) do |bytes|
      yield bytes
    end
  end
end