-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathunpack.ts
More file actions
32 lines (29 loc) · 889 Bytes
/
unpack.ts
File metadata and controls
32 lines (29 loc) · 889 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
import { Field } from "./field";
/** Options for `code.unpack()` */
export enum Endianess {
Little = 0,
Big = 1
};
/** Helps with making unpacking protocols.
* It unpacks variables via left & right shifting
* based on a given endianness argument
*/
export class Unpack extends Field {
public readonly bigEndian:boolean;
/**
* @param field Name of the property that should be unpacked to
* @param endianness determines how to unpack the value provided
* Default Value: `Endianess.Little`.
*/
constructor (field: string, endianness?:Endianess){
if (endianness === undefined){
endianness = Endianess.Little;
}
super(
'match',
endianness == Endianess.Little ? 'unpack_le' : 'unpack_be',
field
);
this.bigEndian = endianness == Endianess.Big;
}
}