Method: LibSL::Packet#initialize

Defined in:
lib/packet.rb

#initialize(blocks = {}) ⇒ Packet

Create a new packet Example: { :Block1 => { # Block :Var1 => LLU8.new(0xff), :Var2 => LLVariable1.new(“abcd”) }, :Block2 => [ # Block collection { :Var1 => LLFixed.new(“block1”), :Var2 => LLS32.new(0x12345678) }, { :Var1 => LLFixed.new(“block2”), :Var2 => LLS32.new(0x12345678) } ] }

Parameters:

  • blocks (Hash) (defaults to: {})

    (optional) Data blocks



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/packet.rb', line 74

def initialize(blocks={})
	@zero_coded_flag = false
	@reliable_flag = false
	@resent_flag = false
	@acks_flag = false
	@acks = []
	@resent_count = 0
	build_structure
	blocks.each do |name, block|
		case block
		when Array then
			block.each_index do |i|
				collection = self.send(name)
				case collection
				when VariableBlockCollection then
					b = collection.add
				when FixedBlockCollection then
					b = collection[i]
				end

				block[i].each do |v|
					b.send((v[0].to_s + "=").to_sym, v[1])
				end
			end
		when Hash then
			block.each do |v|
				self.send(name).send((v[0].to_s + "=").to_sym, v[1])
			end
		end
	end
end