-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.html
More file actions
51 lines (40 loc) · 801 Bytes
/
example.html
File metadata and controls
51 lines (40 loc) · 801 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
50
51
<script src="build/build.js"></script>
<script>
var struct = require('struct');
// buffer big enough for all 3 structs
var buf = new Uint8Array(3 * (32 + 5 + 16));
var Pet = struct({
id: 'uint32',
name: 'string',
age: 'uint16'
});
// write
var tobi = new Pet({
id: 1,
name: 'Tobi',
age: 2
});
var loki = new Pet({
id: 2,
name: 'Loki',
age: 2
});
var jane = new Pet({
id: 3,
name: 'Jane',
age: 6
});
var off = 0;
var pets = [tobi, loki, jane];
for (var i = 0; i < pets.length; i++) {
off = pets[i].write(buf, off);
}
// read
var n = 3;
var off = 0;
var pet = new Pet;
while (n--) {
off = pet.read(buf, off);
console.log('%s (%s) is %s years old', pet.name, pet.id, pet.age);
}
</script>