|
928 | 928 | throw(new Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details"))
|
929 | 929 | }
|
930 | 930 | offset = typeof offset != 'undefined' ? offset : (this.offset+=8)-8;
|
931 |
| - if (!(typeof value == 'object' && value instanceof Long)) value = Long.fromNumber(value); |
| 931 | + if (!(typeof value == 'object' && value instanceof Long)) value = Long.fromNumber(value, false); |
932 | 932 | this.ensureCapacity(offset+8);
|
933 | 933 | if (this.littleEndian) {
|
934 | 934 | this.view.setInt32(offset, value.getLowBits(), true);
|
|
958 | 958 | }
|
959 | 959 | var value;
|
960 | 960 | if (this.littleEndian) {
|
961 |
| - value = new Long(this.view.getInt32(offset, true), this.view.getInt32(offset+4, true)); |
| 961 | + value = Long.fromBits(this.view.getInt32(offset, true), this.view.getInt32(offset+4, true), false); |
962 | 962 | } else {
|
963 |
| - value = new Long(this.view.getInt32(offset+4, false), this.view.getInt32(offset, false)); |
| 963 | + value = Long.fromBits(this.view.getInt32(offset+4, false), this.view.getInt32(offset, false), false); |
| 964 | + } |
| 965 | + return value; |
| 966 | + }; |
| 967 | + |
| 968 | + /** |
| 969 | + * Writes a 64bit unsigned integer. Utilizes Long.js to write the low and high 32 bits separately. |
| 970 | + * @function |
| 971 | + * @param {number|Long} value Value to write |
| 972 | + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. |
| 973 | + * @return {ByteBuffer} this |
| 974 | + * @throws {Error} If long support is not available |
| 975 | + * @expose |
| 976 | + */ |
| 977 | + ByteBuffer.prototype.writeUint64 = function(value, offset) { |
| 978 | + if (!Long) { |
| 979 | + throw(new Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details")) |
| 980 | + } |
| 981 | + offset = typeof offset != 'undefined' ? offset : (this.offset+=8)-8; |
| 982 | + if (!(typeof value == 'object' && value instanceof Long)) value = Long.fromNumber(value, true); |
| 983 | + this.ensureCapacity(offset+8); |
| 984 | + if (this.littleEndian) { |
| 985 | + this.view.setUint32(offset, value.getLowBitsUnsigned(), true); |
| 986 | + this.view.setUint32(offset+4, value.getHighBitsUnsigned(), true); |
| 987 | + } else { |
| 988 | + this.view.setUint32(offset, value.getHighBitsUnsigned(), false); |
| 989 | + this.view.setUint32(offset+4, value.getLowBitsUnsigned(), false); |
| 990 | + } |
| 991 | + return this; |
| 992 | + }; |
| 993 | + |
| 994 | + /** |
| 995 | + * Reads a 64bit unsigned integer. Utilizes Long.js to construct a new Long from the low and high 32 bits. |
| 996 | + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. |
| 997 | + * @return {Long} |
| 998 | + * @throws {Error} If offset+8 is larger than the capacity or long support is not available |
| 999 | + * @expose |
| 1000 | + */ |
| 1001 | + ByteBuffer.prototype.readUint64 = function(offset) { |
| 1002 | + if (!Long) { |
| 1003 | + throw(new Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details")) |
| 1004 | + } |
| 1005 | + offset = typeof offset != 'undefined' ? offset : (this.offset+=8)-8; |
| 1006 | + if (this.array == null || offset+8 > this.array.byteLength) { |
| 1007 | + this.offset -= 8; |
| 1008 | + throw(new Error("Cannot read int64 from "+this+": Capacity overflow")); |
| 1009 | + } |
| 1010 | + var value; |
| 1011 | + if (this.littleEndian) { |
| 1012 | + value = Long.fromBits(this.view.getUint32(offset, true), this.view.getUint32(offset+4, true), true); |
| 1013 | + } else { |
| 1014 | + value = Long.fromBits(this.view.getUint32(offset+4, false), this.view.getUint32(offset, false), true); |
964 | 1015 | }
|
965 | 1016 | return value;
|
966 | 1017 | };
|
967 |
| - |
968 |
| - // TODO: Do we need uint64? |
969 | 1018 |
|
970 | 1019 | /**
|
971 | 1020 | * Writes a long. This is an alias of {@link ByteBuffer#writeInt64}.
|
|
0 commit comments