Completed
Push — master ( 3ac06e...043d26 )
by Rafael S.
01:57
created

externs/byte-data.js   A

Complexity

Total Complexity 12
Complexity/F 1

Size

Lines of Code 131
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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