Class: Arpie::SeparatorProtocol
- 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
Instance Attribute Summary collapse
-
#separator ⇒ Object
Returns the value of attribute separator.
Attributes inherited from Protocol
Instance Method Summary collapse
- #from(binary) {|| ... } ⇒ Object
-
#initialize(separator = "\n") ⇒ SeparatorProtocol
constructor
A new instance of SeparatorProtocol.
- #to(object) {|object.to_s + @separator| ... } ⇒ Object
Methods inherited from Protocol
#again!, #assemble, #assemble!
Methods included from Arpie
Constructor Details
#initialize(separator = "\n") ⇒ SeparatorProtocol
Returns a new instance of SeparatorProtocol.
307 308 309 |
# File 'lib/arpie/protocol.rb', line 307 def initialize separator = "\n" @separator = separator end |
Instance Attribute Details
#separator ⇒ Object
Returns the value of attribute separator.
305 306 307 |
# File 'lib/arpie/protocol.rb', line 305 def separator @separator end |
Instance Method Details
#from(binary) {|| ... } ⇒ Object
311 312 313 314 315 316 |
# File 'lib/arpie/protocol.rb', line 311 def from binary idx = binary.index(@separator) or incomplete! yield binary[0, idx] @separator.size + idx end |
#to(object) {|object.to_s + @separator| ... } ⇒ Object
318 319 320 |
# File 'lib/arpie/protocol.rb', line 318 def to object yield object.to_s + @separator end |