-
Notifications
You must be signed in to change notification settings - Fork 5
/
ari_data_loader.lua
83 lines (60 loc) · 2.09 KB
/
ari_data_loader.lua
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
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
---
-- This file contains the loader, responsible for loading the TLV parsers, look-up-tables and data from the folder structure.
-- @author Tobias Kröll
--
require("ari_utils")
local cwd = debug.getinfo(1).source:match("@?(.*/)")
local searchpath = "parsers/tlv"
local tlv_parsers = {}
local fields = {}
-- Load TLV parsers
for file in Dir.open(cwd .. searchpath) do
dofile(cwd .. searchpath .. "/" .. file)
local path = { PARSER.group_id, PARSER.type_id, PARSER.tlv_id }
local tlv_parser_table = table.GetWithPath(tlv_parsers, path)
if not tlv_parser_table then
tlv_parser_table = {}
table.SetWithPath(tlv_parsers, path, tlv_parser_table)
end
tlv_parser_table[#tlv_parser_table + 1] = PARSER.parse
table.Merge(fields, PARSER.fields or {})
-- Reset global table
PARSER = nil
end
searchpath = "parsers/codec"
local codec_parsers = {}
-- Load Codec parsers
for file in Dir.open(cwd .. searchpath) do
dofile(cwd .. searchpath .. "/" .. file)
local path = { PARSER.codec_name }
local codec_parser_table = table.GetWithPath(codec_parsers, path)
if not codec_parser_table then
codec_parser_table = {}
table.SetWithPath(codec_parsers, path, codec_parser_table)
end
codec_parser_table[#codec_parser_table + 1] = PARSER
table.Merge(fields, PARSER.fields or {})
-- Reset global table
PARSER = nil
end
searchpath = "types/structure"
local tlv_structure = {}
-- Load additional structure LUTs and merge them together
for file in Dir.open(cwd .. searchpath) do
local loaded_structure = dofile(cwd .. searchpath .. "/" .. file)
table.Merge(tlv_structure, loaded_structure)
end
local asstring_lut = {}
searchpath = "types/asstring"
-- Load additional asstring LUTs and merge them together
for file in Dir.open(cwd .. searchpath) do
local loaded_asstring_lut = dofile(cwd .. searchpath .. "/" .. file)
table.Merge(asstring_lut, loaded_asstring_lut)
end
return {
tlv_parsers = tlv_parsers,
codec_parsers = codec_parsers,
fields = fields,
structure = tlv_structure,
asstring_lut = asstring_lut,
}