isoxml-angular
Version:
JavaScript library to parse and generate ISOXML (ISO11783-10) files
40 lines (39 loc) • 1.04 kB
JavaScript
;
// A modified version of https://github.com/villadora/node-buffer-reader
Object.defineProperty(exports, "__esModule", { value: true });
const types = {
'Int8': 1,
'Uint8': 1,
'Int16': 2,
'Uint16': 2,
'Int32': 4,
'Uint32': 4,
'Float': 4,
'Double': 8,
};
const BufferReader = function (buffer) {
buffer = buffer || new ArrayBuffer(0);
this.buf = buffer;
this.view = new DataView(this.buf);
this.offset = 0;
};
BufferReader.prototype.tell = function () {
return this.offset;
};
BufferReader.prototype.seek = function (pos) {
this.offset = pos;
};
BufferReader.prototype.move = function (diff) {
this.offset += diff;
};
function MAKE_NEXT_READER(valueName, size) {
BufferReader.prototype['next' + valueName] = function () {
const val = this.view['get' + valueName](this.offset, true);
this.offset += size;
return val;
};
}
Object.keys(types).forEach(type => {
MAKE_NEXT_READER(type, types[type]);
});
exports.default = BufferReader;