biketrack-app/node_modules/@ethersphere/bee-js/dist/cjs/utils/uint64.js

30 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-07-11 10:27:11 +02:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readUint64BigEndian = exports.writeUint64BigEndian = exports.writeUint64LittleEndian = void 0;
const bytes_1 = require("./bytes");
// TODO handle bigger values than 32 bit
// For now it's good enough because we only use these functions
// sequential feed indexes.
function writeUint64LittleEndian(value, bytes = (0, bytes_1.makeBytes)(8)) {
const dataView = new DataView(bytes.buffer);
const valueLower32 = value & 0xffffffff;
const littleEndian = true;
dataView.setUint32(0, valueLower32, littleEndian);
dataView.setUint32(4, 0, littleEndian);
return bytes;
}
exports.writeUint64LittleEndian = writeUint64LittleEndian;
function writeUint64BigEndian(value, bytes = (0, bytes_1.makeBytes)(8)) {
const dataView = new DataView(bytes.buffer);
const valueLower32 = value & 0xffffffff;
dataView.setUint32(0, 0);
dataView.setUint32(4, valueLower32);
return bytes;
}
exports.writeUint64BigEndian = writeUint64BigEndian;
function readUint64BigEndian(bytes) {
const dataView = new DataView(bytes.buffer);
return dataView.getUint32(4);
}
exports.readUint64BigEndian = readUint64BigEndian;