import {Buffer} from "buffer"; import {PIID} from "./PIID"; import {Unsigned16} from "./Unsigned16"; import {ProtocolConformance} from "./ProtocolConformance"; import {FunctionConformance} from "./FunctionConformance"; import {Unsigned8} from "./Unsigned8"; import {Unsigned32} from "./Unsigned32"; import {ConnectMechanismInfo} from "./ConnectMechanismInfo"; import {AxdrType} from "../asn1.axdr/AxdrType"; import {ReverseByteArrayInputStream} from "../ReverseByteArrayInputStream"; import {ReverseByteArrayOutputStream} from "../ReverseByteArrayOutputStream"; export class Connect_Request implements AxdrType{ dataCode : Buffer | null = null; piid : PIID | null = null; wver : Unsigned16 | null = null; wpro : ProtocolConformance | null = null; wfun : FunctionConformance | null = null; wSendSize : Unsigned16 | null = null; wRecvSize : Unsigned16 | null = null; wRecvWnd : Unsigned8 | null = null; wMaxApdu : Unsigned16 | null = null; wMaxIdle : Unsigned32 | null = null; wConnObj : ConnectMechanismInfo | null = null constructor() { } setDataCode(dataCode : Buffer){ this.dataCode = dataCode; } set_all(piid : PIID, wver : Unsigned16, wpro : ProtocolConformance, wfun : FunctionConformance, wSendSize : Unsigned16, wRecvSize : Unsigned16, wRecvWnd : Unsigned8, wMaxApdu : Unsigned16, wMaxIdle : Unsigned32, wConnObj : ConnectMechanismInfo){ this.piid = piid; this.wver = wver; this.wpro = wpro; this.wfun = wfun; this.wSendSize = wSendSize; this.wRecvSize = wRecvSize; this.wRecvWnd = wRecvWnd; this.wMaxApdu = wMaxApdu; this.wMaxIdle = wMaxIdle; this.wConnObj = wConnObj; } setPIID(piid : PIID){ this.piid = piid; } setWver(wver : Unsigned16){ this.wver = wver; } setWpro(wpro : ProtocolConformance){ this.wpro = wpro; } setWfun(wfun : FunctionConformance){ this.wfun = wfun; } setWSendSize(wSendSize : Unsigned16){ this.wSendSize = wSendSize; } setWRecvSize(wRecvSize : Unsigned16){ this.wRecvSize = wRecvSize; } setWRecvWnd(wRecvWnd : Unsigned8){ this.wRecvWnd = wRecvWnd; } setWMaxApdu(wMaxApdu : Unsigned16){ this.wMaxApdu = wMaxApdu; } setWMaxIdle(wMaxIdle : Unsigned32){ this.wMaxIdle = wMaxIdle; } setWConnObj(wConnObj : ConnectMechanismInfo){ this.wConnObj = wConnObj; } decode(input: ReverseByteArrayInputStream): number { let codeLength = 0; this.piid = new PIID(); this.piid.setNumBit(8); codeLength += this.piid.decode(input); this.wver = new Unsigned16(); this.wver.set_const(); codeLength += this.wver.decode(input); this.wpro = new ProtocolConformance(); codeLength += this.wpro.decode(input); this.wfun = new FunctionConformance(); codeLength += this.wfun.decode(input); this.wSendSize = new Unsigned16(); this.wSendSize.set_const(); codeLength += this.wSendSize.decode(input); this.wRecvSize = new Unsigned16(); this.wRecvSize.set_const(); codeLength += this.wRecvSize.decode(input); this.wRecvWnd = new Unsigned8(); this.wRecvWnd.set_const(); codeLength += this.wRecvWnd.decode(input); this.wMaxApdu = new Unsigned16(); this.wMaxApdu.set_const(); codeLength += this.wMaxApdu.decode(input); this.wMaxIdle = new Unsigned32(); this.wMaxIdle.set_const(); codeLength += this.wMaxIdle.decode(input); this.wConnObj = new ConnectMechanismInfo(); codeLength += this.wConnObj.decode(input); return codeLength; } encode(output: ReverseByteArrayOutputStream): number { let codeLength; if (this.dataCode != null) { codeLength = this.dataCode.length; for (let i = this.dataCode.length - 1; i >= 0; i--) { output.write(this.dataCode[i]); } } else { if(this.wConnObj != null && this.wMaxIdle != null && this.wMaxApdu != null && this.wRecvWnd != null && this.wRecvSize != null && this.wSendSize != null && this.wfun != null && this.wpro != null && this.wver != null && this.piid != null){ codeLength = 0; codeLength += this.wConnObj.encode(output); codeLength += this.wMaxIdle.encode(output); codeLength += this.wMaxApdu.encode(output); codeLength += this.wRecvWnd.encode(output); codeLength += this.wRecvSize.encode(output); codeLength += this.wSendSize.encode(output); codeLength += this.wfun.encode(output); codeLength += this.wpro.encode(output); codeLength += this.wver.encode(output); codeLength += this.piid.encode(output); }else{ throw new Error("wConnObj || wMaxIdle || wMaxApdu || wRecvWnd || wRecvSize || wSendSize || wfun || wpro || wver || piid is null"); } } return codeLength; } encodeAndSave(encodingSizeGuess: number) { let revOStream = new ReverseByteArrayOutputStream(); revOStream.setBufSize(encodingSizeGuess); this.encode(revOStream); this.dataCode = revOStream.getArray(); } toString(): string { if (this.wConnObj != null && this.wMaxIdle != null && this.wMaxApdu != null && this.wRecvWnd != null && this.wRecvSize != null && this.wSendSize != null && this.wfun != null && this.wpro != null && this.wver != null && this.piid != null) { return "sequence: {"+ "piid: " + this.piid + ", wver: " + this.wver + ", wpro: " + this.wpro + ", wfun: " + this.wfun + ", wsendsize: " + this.wSendSize + ", wrecvsize: " + this.wRecvSize + ", wrecvwnd: " + this.wRecvWnd + ", wmaxapdu: " + this.wMaxApdu + ", wmaxidle: " + this.wMaxIdle + ", wconnobj: " + this.wConnObj + "}"; } else { return "wConnObj || wMaxIdle || wMaxApdu || wRecvWnd || wRecvSize || wSendSize || wfun || wpro || wver || piid is null "; } } }