"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var apdu_response_1 = require("./apdu-response");
/**
 *
 *
 * Encoder/Decoder for an APDUResponse.
 *
 * Encode to bytes and decode from bytes
 */
var APDUResponseConverter = /** @class */ (function () {
    function APDUResponseConverter() {
    }
    APDUResponseConverter.prototype.encode = function (apduResponse) {
        var dataLength = apduResponse.getData().length;
        var buffer = new Uint8Array(dataLength + apduResponse.getStatus().length);
        var offset = 0;
        buffer.set(apduResponse.getData(), offset);
        offset += dataLength;
        buffer.set(apduResponse.getStatus(), offset);
        return buffer;
    };
    APDUResponseConverter.prototype.decode = function (buffer) {
        var response = new apdu_response_1.APDUResponse();
        response
            .setStatus(buffer.subarray(-APDUResponseConverter.STATUS_WORD_LENGTH))
            .setData(buffer.subarray(0, -APDUResponseConverter.STATUS_WORD_LENGTH));
        return response;
    };
    APDUResponseConverter.STATUS_WORD_LENGTH = 2;
    return APDUResponseConverter;
}());
exports.APDUResponseConverter = APDUResponseConverter;
