"use strict";
/**
 * This file has been generated
 * DO NOT EDIT, IT MAY BE OVERWRITTEN
 */
Object.defineProperty(exports, "__esModule", { value: true });
var import_adapter_1 = require("./import-adapter");
import_adapter_1.TapStreamReader.prototype.readTapRequest = function () {
    var model = {};
    model.header = this.readTapRequestHeader();
    model.payload = this.readBytesFull();
    return model;
};
import_adapter_1.TapStreamReader.prototype.readTapRequestHeader = function () {
    var model = {};
    model.methodType = /*TapRequest.MethodType[*/ this.readU1();
    model.path = this.readTapRequestPath();
    return model;
};
import_adapter_1.TapStreamReader.prototype.readTapRequestPath = function () {
    var model = {};
    model.objectId = this.readU2();
    model.objectInstanceId = this.readU2();
    model.resourceId = this.readU2();
    return model;
};
import_adapter_1.TapStreamReader.prototype.readTapResponse = function () {
    var model = {};
    model.codeRet = this.readU1();
    model.data = this.readBytesFull();
    return model;
};
import_adapter_1.TapStreamReader.prototype.readApduResponse = function () {
    var model = {};
    model.data = this.readBytes(this.getStreamSize() - 2);
    model.status = this.readU2();
    return model;
};
import_adapter_1.TapStreamReader.prototype.readApduRequest = function () {
    var model = {};
    model.header = this.readApduRequestHeader();
    model.data = this.readBytes(model.header.lc);
    return model;
};
import_adapter_1.TapStreamReader.prototype.readApduRequestHeader = function () {
    var model = {};
    model.cla = this.readU1();
    model.ins = this.readU1();
    model.p1 = this.readU1();
    model.p2 = this.readU1();
    model.lc = this.readU1();
    return model;
};
import_adapter_1.TapStreamReader.prototype.readTapApduRequest = function () {
    var model = {};
    return model;
};
import_adapter_1.TapStreamReader.prototype.readTapEncryptedFrame = function () {
    var model = {};
    model.id = this.readU2();
    model.len = this.readU2();
    model.payload = this.readBytes(model.len);
    model.padding = this.readBytes((16 - ((2 + 2 + model.len + 4) % 16)) % 16);
    model.crc = this.readU4();
    return model;
};
// TapStreamWriter.prototype.write(model: TapRequest) : TapStreamWriter{
//     return this.writeTapRequest(model)
// }
import_adapter_1.TapStreamWriter.prototype.writeTapRequest = function (model) {
    this.writeTapRequestHeader(model.header);
    this.writeBytes(model.payload);
    return this;
};
import_adapter_1.TapStreamWriter.prototype.writeTapRequestHeader = function (model) {
    this.writeBitsInt(/*parseInt(TapRequest.MethodType[*/ model.methodType /*])*/, 8);
    this.writeTapRequestPath(model.path);
    return this;
};
import_adapter_1.TapStreamWriter.prototype.writeTapRequestPath = function (model) {
    this.writeU2(model.objectId);
    this.writeU2(model.objectInstanceId);
    this.writeU2(model.resourceId);
    return this;
};
// TapStreamWriter.prototype.write(model: TapResponse) : TapStreamWriter{
//     return this.writeTapResponse(model)
// }
import_adapter_1.TapStreamWriter.prototype.writeTapResponse = function (model) {
    this.writeU1(model.codeRet);
    this.writeBytes(model.data);
    return this;
};
// TapStreamWriter.prototype.write(model: ApduResponse) : TapStreamWriter{
//     return this.writeApduResponse(model)
// }
import_adapter_1.TapStreamWriter.prototype.writeApduResponse = function (model) {
    this.writeBytes(model.data, this.getStreamSize() - 2);
    this.writeU2(model.status);
    return this;
};
// TapStreamWriter.prototype.write(model: ApduRequest) : TapStreamWriter{
//     return this.writeApduRequest(model)
// }
import_adapter_1.TapStreamWriter.prototype.writeApduRequest = function (model) {
    this.writeApduRequestHeader(model.header);
    this.writeBytes(model.data, model.header.lc);
    return this;
};
import_adapter_1.TapStreamWriter.prototype.writeApduRequestHeader = function (model) {
    this.writeU1(model.cla);
    this.writeU1(model.ins);
    this.writeU1(model.p1);
    this.writeU1(model.p2);
    this.writeU1(model.lc);
    return this;
};
// TapStreamWriter.prototype.write(model: TapApduRequest) : TapStreamWriter{
//     return this.writeTapApduRequest(model)
// }
import_adapter_1.TapStreamWriter.prototype.writeTapApduRequest = function (model) {
    return this;
};
// TapStreamWriter.prototype.write(model: TapEncryptedFrame) : TapStreamWriter{
//     return this.writeTapEncryptedFrame(model)
// }
import_adapter_1.TapStreamWriter.prototype.writeTapEncryptedFrame = function (model) {
    this.writeU2(model.id);
    this.writeU2(model.len);
    this.writeBytes(model.payload, model.len);
    this.writeFunction('padding', null, model.padding, (16 - ((2 + 2 + model.len + 4) % 16)) % 16);
    this.writeFunction('crc32', null, model.crc);
    return this;
};
