UNPKG

@iota/bcs

Version:

BCS - Canonical Binary Serialization implementation for JavaScript

59 lines (58 loc) 1.51 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var uleb_exports = {}; __export(uleb_exports, { ulebDecode: () => ulebDecode, ulebEncode: () => ulebEncode }); module.exports = __toCommonJS(uleb_exports); function ulebEncode(num) { const arr = []; let len = 0; if (num === 0) { return [0]; } while (num > 0) { arr[len] = num & 127; if (num >>= 7) { arr[len] |= 128; } len += 1; } return arr; } function ulebDecode(arr) { let total = 0; let shift = 0; let len = 0; while (true) { const byte = arr[len]; len += 1; total |= (byte & 127) << shift; if ((byte & 128) === 0) { break; } shift += 7; } return { value: total, length: len }; } //# sourceMappingURL=uleb.js.map