UNPKG

@iota/bcs

Version:

BCS - Canonical Binary Serialization implementation for JavaScript

39 lines (38 loc) 592 B
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 }; } export { ulebDecode, ulebEncode }; //# sourceMappingURL=uleb.js.map