UNPKG

electr0lysis

Version:

Simple framework for data serialization and interchange.

25 lines 827 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const DecoderError_1 = require("../DecoderError"); class VintDecoder { decode(type, view, offset, context) { let position = offset; let value = 0; let shift = 0; while (true) { if (shift == 5 * 7) { throw new DecoderError_1.default(); } let byte = context.decode({ name: "Uint8" }, view, position); position += 1; value |= (byte.value & 0x7f) << shift; shift += 7; if ((byte.value & 0x80) == 0x00) { const size = position - offset; return { value, size }; } } } } exports.default = VintDecoder; //# sourceMappingURL=VintDecoder.js.map