[apps/tidep0084.git] / example / iot-gateway / node_modules / bytebuffer / src / methods / reverse.js
1 /**
2 * Reverses this ByteBuffer's contents.
3 * @param {number=} begin Offset to start at, defaults to {@link ByteBuffer#offset}
4 * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}
5 * @returns {!ByteBuffer} this
6 * @expose
7 */
8 ByteBufferPrototype.reverse = function(begin, end) {
9 if (typeof begin === 'undefined') begin = this.offset;
10 if (typeof end === 'undefined') end = this.limit;
11 if (!this.noAssert) {
12 //? ASSERT_RANGE();
13 }
14 if (begin === end)
15 return this; // Nothing to reverse
16 //? if (NODE)
17 Array.prototype.reverse.call(this.buffer.slice(begin, end));
18 //? else if (DATAVIEW) {
19 Array.prototype.reverse.call(new Uint8Array(this.buffer).subarray(begin, end));
20 this.view = new DataView(this.buffer); // FIXME: Why exactly is this necessary?
21 //? } else {
22 Array.prototype.reverse.call(this.view.subarray(begin, end));
23 //? }
24 return this;
25 };