-
Notifications
You must be signed in to change notification settings - Fork 44
/
TypedData.ts
134 lines (115 loc) · 2.59 KB
/
TypedData.ts
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import {SyscallInOutInfo, SyscallOutInfo, SyscallOutMap, T} from "./Types.js";
import {IStringIndex} from "../utilities/IStringIndex.js";
export enum VAL_TYPE {
CONSTANT,
INOUT,
OUTPUT
}
/**
* @class
*/
export class TypedData implements SyscallInOutInfo {
/**
* Data type
* See T
* @field {string}
*/
t:T = T.UINT32;
/**
* Type or arg name
* @field {string}
*/
n = "";
/**
* Register number holding extra value required to
* interpret current data
* @field {number}
*/
r? = -1;
/**
* Meaning of the value (conceptually) : file descriptor, pointer to struct, flags, ...
* @field {Types.L}
*/
l?=-1;
/**
* Optional. If the mean of the data is specified, an extra value to help to parse
* or the parser
* @field {any}
*/
f?:any;
/**
* A flag if the value is constant ('const' keyword).
* Non-constant value can be updated bue the syscall.
*
* Default is FALSE
* @field {boolean}
*/
c? = false;
/**
* Optional. The list of error codes which can be hold by this data.
* It helps to define the type of return value.
* @field {any}
*/
e?:any;
/**
* The length of the data if the data is an array or a L.BUFFER
* @type {number}
* @field
*/
len?:number; // size if l => BUFFER
/**
* The raw value
* @type {number}
* @field
*/
v?:number;
/**
*
* @param pCfg
* @constructor
*/
constructor(pCfg:any = null) {
if(pCfg != null){
for(const i in pCfg) (this as any)[i] = pCfg[i];
}
}
/**
*
* @param pCfg {any} Config
* @return {TypedData} An instance of TypedData
* @method
* @static
*/
static from(pCfg:any){
return new TypedData(pCfg);
}
static buffer(pType:TypedData, pSize =-1){
return this; //pType.copy();
}
out(){
return this.copy().update({ v: VAL_TYPE.OUTPUT });
}
update( pCfg:IStringIndex){
for(const i in pCfg){
(this as any)[i] = pCfg[i];
}
return this;
}
copy( pName=""){
const t:TypedData = new TypedData(this);
if(pName!="") t.n = pName;
return t;
}
constant(pConst = true){
this.c = pConst;
return this;
}
asReturn( pError:any[]=[]):SyscallOutInfo{
const t = new TypedData(this);
t.e = pError;
return t as SyscallOutInfo;
}
}
export interface TypedDataMap {
[type:string] :TypedData;
}