var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
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 e_1, _a;
        var result = new Uint8Array(this.options.sizeOfItem * items.length);
        var offset = 0;
        try {
            for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
                var item = items_1_1.value;
                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;
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        return result;
    };
    return ArrayConverter;
}());
export { ArrayConverter };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJyYXktY29udmVydGVyLmpzIiwic291cmNlUm9vdCI6Im5nOi8vQGlvdGl6ZS90YXAvY2xpZW50L2ltcGwvIiwic291cmNlcyI6WyJsaWIvY29udmVydGVyL2JvZHkvYXJyYXktY29udmVydGVyLnRzIl0sIm5hbWVzIjpbXSwibWF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