-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord_header.ts
42 lines (35 loc) · 1.03 KB
/
record_header.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
import { BinaryReader } from "./deps.ts";
import { readBit, readBits } from "./bits.ts";
export class RecordHeader {
headerType: number;
messageType: number | undefined;
messageTypeSpecific: number | undefined;
reserved: number | undefined;
localMesssageType: number;
timeOffset: number | undefined;
constructor(io: BinaryReader) {
const byte = io.readUint8();
this.headerType = readBit(byte, 7);
if (this.headerType === 0) {
this.messageType = readBit(byte, 6);
this.messageTypeSpecific = readBit(byte, 5);
this.reserved = readBit(byte, 4);
this.localMesssageType = readBits(byte, [3, 0]);
} else {
this.localMesssageType = readBits(byte, [6, 5]);
this.timeOffset = readBits(byte, [4, 0]);
}
}
isDefinition() {
return this.headerType === 0 && this.messageType == 1;
}
isData() {
return this.headerType === 0 && this.messageType == 0;
}
hasDevDefs() {
return this.messageTypeSpecific === 1;
}
hasTimestamp() {
return this.headerType === 1;
}
}