-
Notifications
You must be signed in to change notification settings - Fork 55
/
CborInitialByte.ts
61 lines (53 loc) · 1.49 KB
/
CborInitialByte.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* eslint-disable no-bitwise */
/* eslint-disable unicorn/number-literal-case */
import { CborAdditionalInfo } from './CborAdditionalInfo';
import { CborMajorType } from './CborMajorType';
/** Represents a CBOR initial byte. */
export class CborInitialByte {
static readonly IndefiniteLengthBreakByte = 0xff;
static readonly AdditionalInformationMask = 0b0001_1111;
#initialByte: number;
/**
* Initializes a new instance of the CborInitialByte class.
*
* @param majorType The initial byte major type.
* @param additionalInfo The initial byte additional info.
*/
CborInitialByte(majorType: CborMajorType, additionalInfo: CborAdditionalInfo) {
this.#initialByte = (majorType << 5) | additionalInfo;
}
/**
* Creates a CborInitialByte class from a packed initialByte.
*
* @param initialByte The initial.
*/
static from(initialByte: number) {
const init = new CborInitialByte();
init.#initialByte = initialByte;
return init;
}
/**
* Gets the packed initial byte.
*
* @returns The packed initial byte.
*/
getInitialByte(): number {
return this.#initialByte;
}
/**
* Gets the initial type major type.
*
* @returns The major type.
*/
getMajorType(): CborMajorType {
return this.#initialByte >> 5;
}
/**
* Gets initial type the additional info.
*
* @returns The additional info.
*/
getAdditionalInfo(): CborAdditionalInfo {
return this.#initialByte & CborInitialByte.AdditionalInformationMask;
}
}