-
Notifications
You must be signed in to change notification settings - Fork 11
/
actions.rb
42 lines (35 loc) · 907 Bytes
/
actions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'bindata'
module Pio
# Actions not yet implemented.
class UnsupportedAction < BinData::Record
endian :big
uint16 :action_type
uint16 :action_length
end
# Actions list of actions-apply instruction.
class Actions < BinData::Primitive
mandatory_parameter :length
endian :big
string :binary, read_length: :length
def set(actions)
self.binary = Array(actions).map(&:to_binary).join
end
# rubocop:disable MethodLength
def get
actions = []
tmp = binary
while tmp.length > 0
action = case BinData::Uint16be.read(tmp)
when 0
SendOutPort.read(tmp)
else
UnsupportedAction.read(tmp)
end
tmp = tmp[action.action_length..-1]
actions << action
end
actions
end
# rubocop:enable MethodLength
end
end