data-struct 0.0.11-n → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +164 -83
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +86 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -17
- package/.npmignore +0 -3
- package/benchmark/benchmark.js +0 -52
- package/gruntfile.js +0 -36
- package/src/dataReader.js +0 -128
- package/src/dataTypes.js +0 -15
- package/src/dataWriter.js +0 -141
- package/src/index.js +0 -3
- package/test/tests.js +0 -219
package/test/tests.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TODO: tests for compatibility with other rsa libraries
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var assert = require("chai").assert;
|
|
6
|
-
DataTypes = require("../src/index").DataTypes;
|
|
7
|
-
DataReader = require("../src/index").DataReader;
|
|
8
|
-
DataWriter = require("../src/index").DataWriter;
|
|
9
|
-
|
|
10
|
-
suite("DataStruct", function(){
|
|
11
|
-
|
|
12
|
-
var dataBundle = {
|
|
13
|
-
'basic types': {
|
|
14
|
-
object: 42,
|
|
15
|
-
scheme: DataTypes.uint16,
|
|
16
|
-
buffer: new Buffer([0x00, 0x2a])
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
'flat structure (basic types)': {
|
|
20
|
-
object: {
|
|
21
|
-
boolean: true,
|
|
22
|
-
int8: -126,
|
|
23
|
-
uint8: 255,
|
|
24
|
-
int16: -1000,
|
|
25
|
-
uint16: 65535,
|
|
26
|
-
int32: -100000,
|
|
27
|
-
uint32: 100000,
|
|
28
|
-
float: 1230000,
|
|
29
|
-
double: -123.456
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
scheme: {
|
|
33
|
-
boolean: DataTypes.boolean,
|
|
34
|
-
int8: DataTypes.int8,
|
|
35
|
-
uint8: DataTypes.uint8,
|
|
36
|
-
int16: DataTypes.int16,
|
|
37
|
-
uint16: DataTypes.uint16,
|
|
38
|
-
int32: DataTypes.int32,
|
|
39
|
-
uint32: DataTypes.uint32,
|
|
40
|
-
float: DataTypes.float,
|
|
41
|
-
double: DataTypes.double
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
buffer: new Buffer([
|
|
45
|
-
0x01, // boolean
|
|
46
|
-
0x82, // int8
|
|
47
|
-
0xff, // uint8
|
|
48
|
-
0xfc, 0x18, // int16
|
|
49
|
-
0xff, 0xff, // uint16
|
|
50
|
-
0xff, 0xfe, 0x79, 0x60, // int32
|
|
51
|
-
0x00, 0x01, 0x86, 0xa0, // uint32
|
|
52
|
-
0x49, 0x96, 0x25, 0x80, // float
|
|
53
|
-
0xc0, 0x5e, 0xdd, 0x2f, 0x1a, 0x9f, 0xbe, 0x77, // double
|
|
54
|
-
])
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
'flat structure (composite types)': {
|
|
58
|
-
object: {
|
|
59
|
-
string: 'Some text + юникод',
|
|
60
|
-
shortBuffer: new Buffer([1,2,3]),
|
|
61
|
-
buffer: new Buffer([0xaa,0xbb,0xcc])
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
scheme: {
|
|
65
|
-
string: DataTypes.string,
|
|
66
|
-
shortBuffer: DataTypes.shortBuffer,
|
|
67
|
-
buffer: DataTypes.buffer
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
buffer: new Buffer([
|
|
71
|
-
0x00, 0x18, // string length (uint16 BE)
|
|
72
|
-
0x53, 0x6f, 0x6d, 0x65, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x2b, 0x20, 0xd1, 0x8e, 0xd0, 0xbd, 0xd0, 0xb8, 0xd0, 0xba, 0xd0, 0xbe, 0xd0, 0xb4, // string
|
|
73
|
-
0x00, 0x03, // short buffer length (uint16 BE)
|
|
74
|
-
0x01, 0x02, 0x03, // shortBuffer
|
|
75
|
-
0x00, 0x00, 0x00, 0x03, // buffer length (uint16 BE)
|
|
76
|
-
0xaa, 0xbb, 0xcc // buffer
|
|
77
|
-
])
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
'list of strings': {
|
|
81
|
-
object: {
|
|
82
|
-
values: [
|
|
83
|
-
'string1',
|
|
84
|
-
'string20',
|
|
85
|
-
'string300'
|
|
86
|
-
]
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
scheme: {
|
|
90
|
-
values: [DataTypes.string]
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
buffer: new Buffer([
|
|
94
|
-
0x00, 0x03, // list length (uint16 BE)
|
|
95
|
-
0x00, 0x07, // string length (uint16 BE)
|
|
96
|
-
0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, // string1
|
|
97
|
-
0x00, 0x08, // string length (uint16 BE)
|
|
98
|
-
0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x30, // string20
|
|
99
|
-
0x00, 0x09, // string length (uint16 BE)
|
|
100
|
-
0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x33, 0x30, 0x30 // string300
|
|
101
|
-
])
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
'list of objects': {
|
|
105
|
-
object: {
|
|
106
|
-
friends: [
|
|
107
|
-
{
|
|
108
|
-
name: 'Alice',
|
|
109
|
-
age: 21
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: 'Bob',
|
|
113
|
-
age: 17
|
|
114
|
-
}
|
|
115
|
-
],
|
|
116
|
-
numbers: [
|
|
117
|
-
0x10, 0x26, 0x61, 0xff
|
|
118
|
-
]
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
scheme: {
|
|
122
|
-
friends: [{
|
|
123
|
-
name: DataTypes.string,
|
|
124
|
-
age: DataTypes.uint32
|
|
125
|
-
}],
|
|
126
|
-
numbers:[DataTypes.uint8]
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
buffer: new Buffer([
|
|
130
|
-
0x00, 0x02, // friends list length (uint16 BE)
|
|
131
|
-
0x00, 0x05, // string length (uint16 BE)
|
|
132
|
-
0x41, 0x6c, 0x69, 0x63, 0x65, // string
|
|
133
|
-
0x00, 0x00, 0x00, 0x15, //uint32
|
|
134
|
-
0x00, 0x03, // string length (uint16 BE)
|
|
135
|
-
0x42, 0x6f, 0x62, // string
|
|
136
|
-
0x00, 0x00, 0x00, 0x11, //uint32
|
|
137
|
-
0x00, 0x04, // numbers list length (uint16 BE)
|
|
138
|
-
0x10, 0x26, 0x61, 0xff // numbers
|
|
139
|
-
])
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
var dataBundleExtend = {
|
|
145
|
-
nested: {
|
|
146
|
-
|
|
147
|
-
object: { nested: { nested2: { nested3: { nested4: { nested5: 42 } } } } },
|
|
148
|
-
|
|
149
|
-
scheme: { nested: { nested2: { nested3: { nested4: { nested5: DataTypes.uint8 } } } } }
|
|
150
|
-
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
'list of list': {
|
|
154
|
-
object: [
|
|
155
|
-
[90,10,101],
|
|
156
|
-
[20,30,400],
|
|
157
|
-
[100,110,1]
|
|
158
|
-
],
|
|
159
|
-
|
|
160
|
-
scheme: [[DataTypes.int16]]
|
|
161
|
-
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
'list of list of list of list of object': {
|
|
165
|
-
object: {
|
|
166
|
-
list: [
|
|
167
|
-
[[
|
|
168
|
-
[{i: 1},{i: 2},{i: 3}],[{i: 1}]
|
|
169
|
-
],
|
|
170
|
-
[
|
|
171
|
-
[{i: 1}]
|
|
172
|
-
]]
|
|
173
|
-
]
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
scheme: {
|
|
177
|
-
list: [[[[{i: DataTypes.int16}]]]]
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
suite("Buffer to Object convert", function(){
|
|
184
|
-
for(var suite in dataBundle) {
|
|
185
|
-
var data = dataBundle[suite];
|
|
186
|
-
(function(suite, data) {
|
|
187
|
-
test("should return buffer for '" + suite + "' suite", function () {
|
|
188
|
-
var res = DataReader(data.buffer, data.scheme);
|
|
189
|
-
assert.deepEqual(res, data.object);
|
|
190
|
-
});
|
|
191
|
-
})(suite, data);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
suite("Object to Buffer convert", function(){
|
|
196
|
-
for(var suite in dataBundle) {
|
|
197
|
-
var data = dataBundle[suite];
|
|
198
|
-
(function(suite, data) {
|
|
199
|
-
test("should return buffer for '" + suite + "' suite", function () {
|
|
200
|
-
var res = DataWriter(data.object, data.scheme);
|
|
201
|
-
assert.deepEqual(res, data.buffer);
|
|
202
|
-
});
|
|
203
|
-
})(suite, data);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
suite("Object to Buffer to Object convert", function() {
|
|
208
|
-
for(var suite in dataBundleExtend) {
|
|
209
|
-
var data = dataBundleExtend[suite];
|
|
210
|
-
(function(suite, data) {
|
|
211
|
-
test("should convert to buffer and read same for '" + suite + "' suite", function () {
|
|
212
|
-
var buf = DataWriter(data.object, data.scheme);
|
|
213
|
-
var obj = DataReader(buf, data.scheme);
|
|
214
|
-
assert.deepEqual(obj, data.object);
|
|
215
|
-
});
|
|
216
|
-
})(suite, data);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
});
|