"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeSpan = exports.SPAN_SIZE = void 0; const error_1 = require("../utils/error"); exports.SPAN_SIZE = 8; // we limit the maximum span size in 32 bits to avoid BigInt compatibility issues const MAX_SPAN_LENGTH = Math.pow(2, 32) - 1; /** * Create a span for storing the length of the chunk * * The length is encoded in 64-bit little endian. * * @param length The length of the span */ function makeSpan(length) { if (length <= 0) { throw new error_1.BeeArgumentError('invalid length for span', length); } if (length > MAX_SPAN_LENGTH) { throw new error_1.BeeArgumentError('invalid length (> MAX_SPAN_LENGTH)', length); } const span = new Uint8Array(exports.SPAN_SIZE); const dataView = new DataView(span.buffer); const littleEndian = true; const lengthLower32 = length & 0xffffffff; dataView.setUint32(0, lengthLower32, littleEndian); return span; } exports.makeSpan = makeSpan;