Class: Vici::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/vici.rb

Overview

The Message class provides the low level encoding and decoding of vici protocol messages. Directly using this class is usually not required.

Constant Summary collapse

SECTION_START =
1
SECTION_END =
2
KEY_VALUE =
3
LIST_START =
4
LIST_ITEM =
5
LIST_END =
6

Instance Method Summary collapse

Constructor Details

#initialize(data = "") ⇒ Message

Returns a new instance of Message.



89
90
91
92
93
94
95
96
97
# File 'lib/vici.rb', line 89

def initialize(data = "")
  if data.nil?
    @root = {}
  elsif data.is_a?(Hash)
    @root = data
  else
    @encoded = data
  end
end

Instance Method Details

#encodingObject

Get the raw byte encoding of an on-the-wire message



101
102
103
104
# File 'lib/vici.rb', line 101

def encoding
  @encoded = encode(@root) if @encoded.nil?
  @encoded
end

#rootObject

Get the root element of the parsed ruby data structures



108
109
110
111
# File 'lib/vici.rb', line 108

def root
  @root = parse(@encoded) if @root.nil?
  @root
end