UNPKG

electr0lysis

Version:

Simple framework for data serialization and interchange.

25 lines 799 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class VintEncoder { calculateSize(value, type, context) { for (let size = 1; size < 5; size++) { if ((value & -1 << size * 7) == 0) { return size; } } return 5; } encode(value, type, view, offset, context) { let shifted = value; let position = offset; while (shifted >= 0x80) { const byte = shifted | 0x80; context.encode(byte, { name: "Uint8" }, view, position); position += 1; shifted >>= 7; } context.encode(shifted, { name: "Uint8" }, view, position); } } exports.default = VintEncoder; //# sourceMappingURL=VintEncoder.js.map