Class: OrientDbClient::NetworkMessage

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

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ NetworkMessage

Returns a new instance of NetworkMessage.

Yields:

  • (_self)

Yield Parameters:



6
7
8
9
10
# File 'lib/orient_db_client/network_message.rb', line 6

def initialize(&block)
	@components = []

	yield(self) unless block.nil?
end

Instance Method Details

#add(type, value) ⇒ Object



12
13
14
15
# File 'lib/orient_db_client/network_message.rb', line 12

def add(type, value)
	@components << { :type => :integer, :value => (value && value.length) || 0 } if type == :string
	@components << { :type => type, :value => value } unless type == :string && value.nil?
end

#packObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/orient_db_client/network_message.rb', line 17

def pack()
	packing_list = @components.map do |c|
		case c[:type]
			when :byte then 'C'
			when :integer then 'l>'
			when :long  then 'q>'
			when :short then 's>'
			when :string, :raw_string then 'a*'
		end
	end

	content = @components.map do |c|
		value = c[:value]

		if c[:type] == :byte && value.is_a?(String)
			c[:value] = value.length > 0 ? value[0].ord : 0
		end

		c[:value]
	end

	content.pack packing_list.join(" ")
end

#to_sObject



41
42
43
# File 'lib/orient_db_client/network_message.rb', line 41

def to_s
	self.pack
end