"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ArrayConverter = /** @class */ (function () {
    function ArrayConverter(_itemConverter, options) {
        this._itemConverter = _itemConverter;
        this.options = options;
    }
    ArrayConverter.prototype.decode = function (bytes) {
        var items = [];
        var sizeOfItem = this.options.sizeOfItem;
        for (var offset = 0; offset < bytes.length; offset += sizeOfItem) {
            var slice = bytes.subarray(offset, offset + sizeOfItem);
            var item = this._itemConverter.decode(slice);
            items.push(item);
        }
        return items;
    };
    ArrayConverter.prototype.encode = function (items) {
        var result = new Uint8Array(this.options.sizeOfItem * items.length);
        var offset = 0;
        for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
            var item = items_1[_i];
            var encodedItem = this._itemConverter.encode(item); // TODO
            if (encodedItem.length > this.options.sizeOfItem) {
                throw new Error("Encoded item size overflow: " + encodedItem.length + " (max is " + this.options.sizeOfItem + ")");
            }
            result.set(encodedItem, offset);
            offset += this.options.sizeOfItem;
        }
        return result;
    };
    return ArrayConverter;
}());
exports.ArrayConverter = ArrayConverter;
