1 | const HexStream = require('../util/HexStream');
|
2 |
|
3 | class BaseCoder {
|
4 | static from(component) {}
|
5 |
|
6 | constructor({ type, name }) {
|
7 | this.type = type;
|
8 | this.name = name;
|
9 | this.dynamic = false;
|
10 | }
|
11 |
|
12 | |
13 |
|
14 |
|
15 | encode(value) {
|
16 | throw new Error(`${this.constructor.name}.encode not implemented`);
|
17 | }
|
18 |
|
19 | |
20 |
|
21 |
|
22 |
|
23 | decode(stream) {
|
24 | throw new Error(`${this.constructor.name}.decode not implemented`);
|
25 | }
|
26 |
|
27 | encodeIndex(value) {
|
28 | return this.encode(value);
|
29 | }
|
30 |
|
31 | decodeIndex(hex) {
|
32 | const stream = new HexStream(hex);
|
33 | return this.decode(stream);
|
34 | }
|
35 | }
|
36 |
|
37 | module.exports = BaseCoder;
|