|
371 | 371 | return bb; |
372 | 372 | }; |
373 | 373 |
|
| 374 | + /** |
| 375 | + * Reads the specified number of bytes. |
| 376 | + * @param {number} length Number of bytes to read |
| 377 | + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `length` if omitted. |
| 378 | + * @returns {!ByteBuffer} |
| 379 | + * @expose |
| 380 | + */ |
| 381 | + ByteBufferPrototype.readBytes = function(length, offset) { |
| 382 | + var relative = typeof offset === 'undefined'; |
| 383 | + if (relative) offset = this.offset; |
| 384 | + if (!this.noAssert) { |
| 385 | + if (typeof offset !== 'number' || offset % 1 !== 0) |
| 386 | + throw TypeError("Illegal offset: "+offset+" (not an integer)"); |
| 387 | + offset >>>= 0; |
| 388 | + if (offset < 0 || offset + length > this.buffer.byteLength) |
| 389 | + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+length+") <= "+this.buffer.byteLength); |
| 390 | + } |
| 391 | + var slice = this.slice(offset, offset + length); |
| 392 | + if (relative) this.offset += length; |
| 393 | + return slice; |
| 394 | + }; |
| 395 | + |
| 396 | + /** |
| 397 | + * Writes a payload of bytes. This is an alias of {@link ByteBuffer#append}. |
| 398 | + * @function |
| 399 | + * @param {!ByteBuffer|!ArrayBuffer|!Uint8Array|string} source Data to write. If `source` is a ByteBuffer, its offsets |
| 400 | + * will be modified according to the performed read operation. |
| 401 | + * @param {(string|number)=} encoding Encoding if `data` is a string ("base64", "hex", "binary", defaults to "utf8") |
| 402 | + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
| 403 | + * written if omitted. |
| 404 | + * @returns {!ByteBuffer} this |
| 405 | + * @expose |
| 406 | + */ |
| 407 | + ByteBufferPrototype.writeBytes = ByteBufferPrototype.append; |
| 408 | + |
374 | 409 | // types/ints/int8 |
375 | 410 |
|
376 | 411 | /** |
|
1152 | 1187 | */ |
1153 | 1188 |
|
1154 | 1189 | /** |
1155 | | - * Reads an IEEE754 float from an array. |
| 1190 | + * Reads an IEEE754 float from a byte array. |
1156 | 1191 | * @param {!Array} buffer |
1157 | 1192 | * @param {number} offset |
1158 | 1193 | * @param {boolean} isLE |
|
1195 | 1230 | } |
1196 | 1231 |
|
1197 | 1232 | /** |
1198 | | - * Writes an IEEE754 float to an array. |
| 1233 | + * Writes an IEEE754 float to a byte array. |
1199 | 1234 | * @param {!Array} buffer |
1200 | 1235 | * @param {number} value |
1201 | 1236 | * @param {number} offset |
|
2266 | 2301 | * will be modified according to the performed read operation. |
2267 | 2302 | * @param {(string|number)=} encoding Encoding if `data` is a string ("base64", "hex", "binary", defaults to "utf8") |
2268 | 2303 | * @param {number=} offset Offset to append at. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
2269 | | - * read if omitted. |
| 2304 | + * written if omitted. |
2270 | 2305 | * @returns {!ByteBuffer} this |
2271 | 2306 | * @expose |
2272 | 2307 | * @example A relative `<01 02>03.append(<04 05>)` will result in `<01 02 04 05>, 04 05|` |
|
0 commit comments