25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
|
# File 'lib/ynl/parser.rb', line 25
def parse
protocol = @yaml['protocol'] || 'genetlink'
protonum = @yaml['protonum']
name = @yaml['name']
doc = translate_doc(@yaml['doc'])
@yaml['definitions']&.each do |d|
parse_definition(d)
end
@yaml['attribute-sets'].each do |d|
parse_attribute_set(d)
end
@yaml['sub-messages']&.each do |d|
parse_sub_message(d)
end
if operations = @yaml['operations']
enum_model = case operations['enum-model']
when 'directional'
:directional
when 'unified', nil
:unified
else
raise ParseError, "Unknown enum model: #{operations['enum-model']}"
end
@default_fixed_header = operations['fixed-header']&.then { @structs.fetch(it) }
if enum_model == :unified
counter = 0
operations['list']&.each do |d|
counter = d['value'] || (counter + 1)
parse_operation(d, request_id: counter, reply_id: counter)
end
else
request_counter = 1
reply_counter = 1
operations['list']&.each do |d|
if d.key?('notify') || d.key?('event')
reply_counter = d['value'] || reply_counter
parse_operation(d, request_id: nil, reply_id: reply_counter)
reply_counter += 1
else
primary = d['do'] || d['dump']
request_counter = primary&.dig('request', 'value') || request_counter
request_id = request_counter
request_counter += 1
if primary&.key?('reply')
reply_counter = primary.dig('reply', 'value') || reply_counter
reply_id = reply_counter
reply_counter += 1
else
reply_id = nil
end
parse_operation(d, request_id:, reply_id:)
end
end
end
end
@yaml['mcast-groups']&.each do |d|
parse_mcast_group(d)
end
Models::Family.new(
name:,
protocol:,
protonum:,
doc:,
consts: @consts,
enums: @enums,
flags: @flags,
structs: @structs,
attribute_sets: @attribute_sets,
sub_messages: @sub_messages,
operations: @operations,
mcast_groups: @mcast_groups,
).resolve
end
|