-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexampleLayer.js
100 lines (90 loc) · 2.18 KB
/
exampleLayer.js
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
const { OsiModelLayers } = require('./osi');
const mixins = require('#lib/layers/mixins');
/**
* Interface for classes that protocol layers.
*
* @interface
*/
class Layer {
/**
* @param {Buffer|Object} data - Input buffer or object with protocol fields.
* @param {Object} opts - Options for the layer.
*/
constructor(data = {}, opts = {}) {
/**
* Underlying buffer synced with the properties.
* @type {Buffer}
*/
this.buffer;
//best to use existing mixins
mixins.ctor(this, data, opts);
/**
* Number of bytes occupied by the layer.
* @type {number}
*/
this.length = opts.allocated ?? 0;
/**
* @private
* Should be the same as the class name.
* @type {string}
*/
this.name = 'Layer';
/**
* Respective protocol OSI layer.
* @type {OsiModelLayers}
*/
this.osi = OsiModelLayers.Unknown;
/**
* @private
* Previous layer.
* @type {Layer}
*/
this.prev;
/**
* @private
* Next layer.
* @type {Layer}
*/
this.next;
}
/**
* @private
*/
static toAlloc = () => 0;
/**
* @private
* Sets default properties for the layer based on user input and existing layers.
* @param {Object} obj - User-defined properties.
* @param {Object} layers - All available protocol layers.
*/
defaults(obj, layers) {
// Implementation
}
/**
* @private
* Receives an object with input properties
* @param {Object} obj - User-defined properties.
*/
merge(obj) {
// Implementation
}
/**
* @private
* Determines the next protocol based on the current layer and existing layers.
* @param {Object} layers - All available protocol layers.
* @returns {Layer} The next layer's protocol.
*/
nextProto(layers) {
// Implementation
return new Layer(this.buffer.subarray(this.length)); // Placeholder return
}
/**
* Returns an object with all protcol fields without owning the underlying buffer.
* Useful to read all the data and use it without having to deal with binary representation.
* @returns {Object} - All protocol fields
*/
toObject() {
return {};
}
}
module.exports = { Layer };