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.



92
93
94
95
96
97
98
99
100
# File 'lib/vici.rb', line 92

def initialize(data = "")
  if data == nil
    @root = Hash.new()
  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



104
105
106
107
108
109
# File 'lib/vici.rb', line 104

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

#rootObject

Get the root element of the parsed ruby data structures



113
114
115
116
117
118
# File 'lib/vici.rb', line 113

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