This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
66 lines (58 loc) · 3.44 KB
/
README
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
jspack-arraybuffer
==================
A reimplementation of jspack (http://code.google.com/p/jspack) which uses native
typed arrays, whilst maintaining a (mostly) compatible API.
May be buggy/incomplete. Built for and tested with lfswsrelay.js
(https://github.com/theangryangel/lfswsrelay.js). Patches, etc. welcome.
lfswsrelay.js is a good example of usage.
If you're used to using the Python struct module, or PHP's pack and unpack, you
might prefer this over natively using the ArrayBuffer & DataView APIs.
struct.unpack(format, ArrayBuffer, offset);
Returns an array containing values unpacked from the ArrayBuffer, into their
native types, begining at offset. If offset is not supplied, it is assumed
from offset of 0.
struct.pack(format, values);
Returns an ArrayBuffer with packed values. The ArrayBuffer size is
automatically calculated from the supplied format.
struct.calcLength(format);
Returns the necessary size required to fit packed values, according to the
supplied format.
Format is a string, made up of the following table
Format | C Type | JavaScript Type | Size (bytes)
----------------------------------------------------------------------------
< | N/A | N/A | 0
| | | Signifies little endian.
| | | Must be first value in format
| | | string. If not supplied big
| | | endian is assumed
----------------------------------------------------------------------------
A | char[] | Array | Length
----------------------------------------------------------------------------
x | pad byte | N/A | 1
----------------------------------------------------------------------------
c | char | string (length 1) | 1
----------------------------------------------------------------------------
b | signed char | number | 1
----------------------------------------------------------------------------
B | unsigned char | number | 1
----------------------------------------------------------------------------
h | signed short | number | 2
----------------------------------------------------------------------------
H | unsigned short | number | 2
----------------------------------------------------------------------------
i | signed long | number | 4
----------------------------------------------------------------------------
I | unsigned long | number | 4
----------------------------------------------------------------------------
l | signed long | number | 4
----------------------------------------------------------------------------
L | unsigned long | number | 4
----------------------------------------------------------------------------
s | char[] | string | Length
----------------------------------------------------------------------------
f | float | number | 4
----------------------------------------------------------------------------
d | double | number | 8
For example, to pack a little endian, 32 character string, and 2 unsigned
char, the following format will work:
"<32sBB"