UNPKG

846 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.compactStripLength = void 0;
4const fromU8a_js_1 = require("./fromU8a.js");
5/**
6 * @name compactStripLength
7 * @description Removes the length prefix, returning both the total length (including the value + compact encoding) and the decoded value with the correct length
8 * @example
9 * <BR>
10 *
11 * ```javascript
12 * import { compactStripLength } from '@polkadot/util';
13 *
14 * console.log(compactStripLength(new Uint8Array([2 << 2, 0xde, 0xad]))); // [2, Uint8Array[0xde, 0xad]]
15 * ```
16 */
17function compactStripLength(input) {
18 const [offset, length] = (0, fromU8a_js_1.compactFromU8a)(input);
19 const total = offset + length.toNumber();
20 return [
21 total,
22 input.subarray(offset, total)
23 ];
24}
25exports.compactStripLength = compactStripLength;