forked from bigeasy/packet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransmogrifier.js
More file actions
49 lines (45 loc) · 998 Bytes
/
transmogrifier.js
File metadata and controls
49 lines (45 loc) · 998 Bytes
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
var tokenizer = require('./tokenizer')
function field (name, definition) {
switch (typeof definition) {
case 'object':
break
case 'string':
var token = tokenizer({ name: name }, definition)
switch (token.type) {
case 'integer':
case 'buffer':
return token
case 'condition':
break
}
break
}
}
function structure (name, definition) {
var fields = []
for (var fieldName in definition) {
fields.push(field(fieldName, definition[fieldName]))
}
return {
name: name,
type: 'structure',
fields: fields
}
}
module.exports = function (definition) {
var definitions = []
for (var name in definition) {
definitions.push(structure(name, definition[name]))
}
return definitions
}
var example = {
'b8': {
'& 0x80': {
name: 'b8z',
value: 'b8z'
},
'default': {
}
}
}