|
1163 | 1163 | * @param {boolean=} le Whether little or big endian, defaults to big endian
|
1164 | 1164 | * @returns {!Array.<number>} Byte representation
|
1165 | 1165 | */
|
1166 |
| - LongPrototype.toBytes = function(le) { |
| 1166 | + LongPrototype.toBytes = function toBytes(le) { |
1167 | 1167 | return le ? this.toBytesLE() : this.toBytesBE();
|
1168 |
| - } |
| 1168 | + }; |
1169 | 1169 |
|
1170 | 1170 | /**
|
1171 | 1171 | * Converts this Long to its little endian byte representation.
|
1172 | 1172 | * @returns {!Array.<number>} Little endian byte representation
|
1173 | 1173 | */
|
1174 |
| - LongPrototype.toBytesLE = function() { |
| 1174 | + LongPrototype.toBytesLE = function toBytesLE() { |
1175 | 1175 | var hi = this.high,
|
1176 | 1176 | lo = this.low;
|
1177 | 1177 | return [
|
|
1184 | 1184 | (hi >>> 16) & 0xff,
|
1185 | 1185 | (hi >>> 24) & 0xff
|
1186 | 1186 | ];
|
1187 |
| - } |
| 1187 | + }; |
1188 | 1188 |
|
1189 | 1189 | /**
|
1190 | 1190 | * Converts this Long to its big endian byte representation.
|
1191 | 1191 | * @returns {!Array.<number>} Big endian byte representation
|
1192 | 1192 | */
|
1193 |
| - LongPrototype.toBytesBE = function() { |
| 1193 | + LongPrototype.toBytesBE = function toBytesBE() { |
1194 | 1194 | var hi = this.high,
|
1195 | 1195 | lo = this.low;
|
1196 | 1196 | return [
|
|
1203 | 1203 | (lo >>> 8) & 0xff,
|
1204 | 1204 | lo & 0xff
|
1205 | 1205 | ];
|
| 1206 | + }; |
| 1207 | + |
| 1208 | + /** |
| 1209 | + * @param {!Array.<number>} arrBytes |
| 1210 | + * @param {number=} offset |
| 1211 | + * @param {boolean=} unsigned |
| 1212 | + * @param {boolean=} le |
| 1213 | + * @returns {!Long} |
| 1214 | + * @inner |
| 1215 | + */ |
| 1216 | + function fromBytes(arrBytes, offset, unsigned, le) { |
| 1217 | + if (typeof(offset)!=='number') offset=0; |
| 1218 | + if (le) { |
| 1219 | + var lo = arrBytes[offset++]; |
| 1220 | + lo |= (arrBytes[offset++] << 8); |
| 1221 | + lo |= (arrBytes[offset++] << 16); |
| 1222 | + lo |= (arrBytes[offset++] << 24); |
| 1223 | + var hi = arrBytes[offset++]; |
| 1224 | + hi |= (arrBytes[offset++] << 8); |
| 1225 | + hi |= (arrBytes[offset++] << 16); |
| 1226 | + hi |= (arrBytes[offset] << 24); |
| 1227 | + } |
| 1228 | + else { |
| 1229 | + var hi = (arrBytes[offset++] << 24); |
| 1230 | + hi |= (arrBytes[offset++] << 16); |
| 1231 | + hi |= (arrBytes[offset++] << 8); |
| 1232 | + hi |= arrBytes[offset++]; |
| 1233 | + var lo = (arrBytes[offset++] << 24); |
| 1234 | + lo |= (arrBytes[offset++] << 16); |
| 1235 | + lo |= (arrBytes[offset++] << 8); |
| 1236 | + lo |= arrBytes[offset]; |
| 1237 | + } |
| 1238 | + return Long.fromBits(lo, hi, unsigned); |
1206 | 1239 | }
|
1207 | 1240 |
|
| 1241 | + /** |
| 1242 | + * Returns a Long representing the 64 bit integer that comes by concatenating the given bytes. |
| 1243 | + * @function |
| 1244 | + * @param {!Array.<number>} arrBytes Byte representation in an array of at least offset+8 bytes |
| 1245 | + * @param {number=} offset The starting index from which to read 8 elements of the array, defaults to zero |
| 1246 | + * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed |
| 1247 | + * @param {boolean=} le Whether little or big endian, defaults to big endian |
| 1248 | + * @returns {!Long} The corresponding Long value |
| 1249 | + */ |
| 1250 | + Long.fromBytes = fromBytes; |
| 1251 | + |
1208 | 1252 | return Long;
|
1209 | 1253 | });
|
0 commit comments