Class: Arpie::SeparatorProtocol

Inherits:
Protocol
  • Object
show all
Defined in:
lib/arpie/protocol.rb

Overview

A simple separator-based protocol. This can be used to implement newline-delimited communication.

Constant Summary collapse

CAN_SEPARATE_MESSAGES =
true

Constants included from Arpie

MTU, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Protocol

#assemble, #assemble!

Methods included from Arpie

#bogon!, #incomplete!

Constructor Details

#initialize(separator = "\n") ⇒ SeparatorProtocol

Returns a new instance of SeparatorProtocol.



294
295
296
# File 'lib/arpie/protocol.rb', line 294

def initialize separator = "\n"
  @separator = separator
end

Instance Attribute Details

#separatorObject

Returns the value of attribute separator.



292
293
294
# File 'lib/arpie/protocol.rb', line 292

def separator
  @separator
end

Instance Method Details

#from(binary) {|| ... } ⇒ Object

Yields:

  • ()


298
299
300
301
302
303
# File 'lib/arpie/protocol.rb', line 298

def from binary
  idx = binary.index(@separator) or incomplete!
  yield binary[0, idx]

  @separator.size + idx
end

#to(object) {|object.to_s + @separator| ... } ⇒ Object

Yields:



305
306
307
# File 'lib/arpie/protocol.rb', line 305

def to object
  yield object.to_s + @separator
end