1
|
|
|
/* |
2
|
|
|
* byte-data: Pack and unpack binary data. |
3
|
|
|
* https://github.com/rochars/byte-data |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017-2018 Rafael da Silva Rocha. |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining |
8
|
|
|
* a copy of this software and associated documentation files (the |
9
|
|
|
* "Software"), to deal in the Software without restriction, including |
10
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, |
11
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to |
12
|
|
|
* permit persons to whom the Software is furnished to do so, subject to |
13
|
|
|
* the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be |
16
|
|
|
* included in all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
19
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
20
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
21
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
22
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
23
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
24
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @fileoverview Externs for byte-data 13.0.0 |
30
|
|
|
* |
31
|
|
|
* @see https://github.com/rochars/byte-data |
32
|
|
|
* @externs |
33
|
|
|
*/ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Read a string from a byte buffer. |
37
|
|
|
* @param {!Uint8Array} bytes A byte buffer. |
38
|
|
|
* @param {number=} index The index to read. |
39
|
|
|
* @param {?number=} len The number of bytes to read. |
40
|
|
|
* @return {string} |
41
|
|
|
*/ |
42
|
|
|
function unpackString(bytes, index=0, len=null) {} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Write a string as a byte buffer. |
46
|
|
|
* @param {string} str The string to pack. |
47
|
|
|
* @return {!Array<number>} The next index to write on the buffer. |
48
|
|
|
*/ |
49
|
|
|
function packString(str) {} |
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Write a string to a byte buffer. |
53
|
|
|
* @param {string} str The string to pack. |
54
|
|
|
* @param {!Uint8Array} bytes A byte buffer. |
55
|
|
|
* @param {number=} index The index to write in the buffer. |
56
|
|
|
* @return {number} The next index to write in the buffer. |
57
|
|
|
*/ |
58
|
|
|
function packStringTo(str, bytes, index=0) {} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Pack a number as a byte buffer. |
62
|
|
|
* @param {number} value The number. |
63
|
|
|
* @param {!Object} theType The type definition. |
64
|
|
|
* @return {!Array<number>} The packed value. |
65
|
|
|
* @throws {Error} If the type definition is not valid. |
66
|
|
|
* @throws {Error} If the value is not valid. |
67
|
|
|
*/ |
68
|
|
|
function pack(value, theType) {} |
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Pack an array of numbers as a byte buffer. |
72
|
|
|
* @param {!Array<number>} values The values. |
73
|
|
|
* @param {!Object} theType The type definition. |
74
|
|
|
* @return {!Array<number>} The packed values. |
75
|
|
|
* @throws {Error} If the type definition is not valid. |
76
|
|
|
* @throws {Error} If any of the values are not valid. |
77
|
|
|
*/ |
78
|
|
|
function packArray(values, theType) {} |
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Pack a number to a byte buffer. |
82
|
|
|
* @param {number} value The value. |
83
|
|
|
* @param {!Object} theType The type definition. |
84
|
|
|
* @param {!Uint8Array} buffer The output buffer. |
85
|
|
|
* @param {number=} index The index to write. |
86
|
|
|
* @return {number} The next index to write. |
87
|
|
|
* @throws {Error} If the type definition is not valid. |
88
|
|
|
* @throws {Error} If the value is not valid. |
89
|
|
|
*/ |
90
|
|
|
function packTo(value, theType, buffer, index=0) {} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Pack a array of numbers to a byte buffer. |
94
|
|
|
* @param {!Array<number>} values The value. |
95
|
|
|
* @param {!Object} theType The type definition. |
96
|
|
|
* @param {!Uint8Array} buffer The output buffer. |
97
|
|
|
* @param {number=} index The buffer index to write. |
98
|
|
|
* @return {number} The next index to write. |
99
|
|
|
* @throws {Error} If the type definition is not valid. |
100
|
|
|
* @throws {Error} If the value is not valid. |
101
|
|
|
*/ |
102
|
|
|
function packArrayTo(values, theType, buffer, index=0) {} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Unpack a number from a byte buffer. |
106
|
|
|
* @param {!Uint8Array} buffer The byte buffer. |
107
|
|
|
* @param {!Object} theType The type definition. |
108
|
|
|
* @return {number} |
109
|
|
|
* @throws {Error} If the type definition is not valid |
110
|
|
|
*/ |
111
|
|
|
function unpack(buffer, theType) {} |
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Unpack an array of numbers from a byte buffer. |
115
|
|
|
* @param {!Uint8Array} buffer The byte buffer. |
116
|
|
|
* @param {!Object} theType The type definition. |
117
|
|
|
* @return {!Array<number>} |
118
|
|
|
* @throws {Error} If the type definition is not valid. |
119
|
|
|
*/ |
120
|
|
|
function unpackArray(buffer, theType) {} |
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Unpack a number from a byte buffer by index. |
124
|
|
|
* @param {!Uint8Array} buffer The byte buffer. |
125
|
|
|
* @param {!Object} theType The type definition. |
126
|
|
|
* @param {number=} index The buffer index to read. |
127
|
|
|
* @return {number} |
128
|
|
|
* @throws {Error} If the type definition is not valid |
129
|
|
|
*/ |
130
|
|
|
function unpackFrom(buffer, theType, index=0) {} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Unpack a array of numbers from a byte buffer by index. |
134
|
|
|
* @param {!Uint8Array} buffer The byte buffer. |
135
|
|
|
* @param {!Object} theType The type definition. |
136
|
|
|
* @param {number=} start The start index. Assumes 0. |
137
|
|
|
* @param {?number=} end The end index. Assumes the buffer length. |
138
|
|
|
* @return {!Array<number>} |
139
|
|
|
* @throws {Error} If the type definition is not valid |
140
|
|
|
*/ |
141
|
|
|
function unpackArrayFrom(buffer, theType, start=0, end=null) {} |
142
|
|
|
|
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.