import {AxdrType} from "../asn1.axdr/AxdrType"; import {ReverseByteArrayInputStream} from "../ReverseByteArrayInputStream"; import {ReverseByteArrayOutputStream} from "../ReverseByteArrayOutputStream"; import {Buffer} from "buffer"; import {PIID} from "./PIID"; import {Unsigned16} from "./Unsigned16"; import {TSA} from "./TSA"; import {OAD} from "./OAD"; import {RSD} from "./RSD"; import {RCSD} from "./RCSD"; export class ProxyGetRequestRecord implements AxdrType{ dataCode : Buffer | null = null; piid : PIID | null = null; waitTime : Unsigned16 | null = null; tsa : TSA | null = null; oad : OAD | null = null; rsd : RSD | null = null; rcsd : RCSD | null = null; constructor() { } set_dataCode(dataCode : Buffer){ this.dataCode = dataCode; } set_all(piid : PIID, waitTime : Unsigned16, tsa : TSA, oad : OAD, rsd : RSD, rcsd : RCSD){ this.piid = piid; this.waitTime = waitTime; this.tsa = tsa; this.oad = oad; this.rsd = rsd; this.rcsd = rcsd; } setPIID(piid : PIID){ this.piid = piid; } setWaitTime(waitTime : Unsigned16){ this.waitTime = waitTime; } setTsa(tsa : TSA){ this.tsa = tsa; } setOAD(oad : OAD){ this.oad = oad; } setRSD(rsd : RSD){ this.rsd = rsd; } setRCSD(rcsd : RCSD){ this.rcsd = rcsd; } decode(input: ReverseByteArrayInputStream): number { let codeLength = 0; this.piid = new PIID(); this.piid.setNumBit(8); codeLength += this.piid.decode(input); this.waitTime = new Unsigned16(); this.waitTime.set_const(); codeLength += this.waitTime.decode(input); this.tsa = new TSA(); codeLength += this.tsa.decode(input); this.oad = new OAD(); codeLength += this.oad.decode(input); this.rsd = new RSD(); codeLength += this.rsd.decode(input); this.rcsd = new RCSD(); codeLength += this.rcsd.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.rcsd != null && this.rsd != null && this.oad != null && this.tsa != null && this.waitTime != null && this.piid != null){ codeLength = 0; codeLength += this.rcsd.encode(output); codeLength += this.rsd.encode(output); codeLength += this.oad.encode(output); codeLength += this.tsa.encode(output); codeLength += this.waitTime.encode(output); codeLength += this.piid.encode(output); }else{ throw new Error("rcsd || rsd || oad || tsa || waittime || 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.piid != null && this.waitTime != null && this.tsa != null && this.oad != null && this.rsd != null && this.rcsd != null) { return "sequence: {"+ "piid: " + this.piid + ", waittime: " + this.waitTime + ", tas: " + this.tsa + ", oad: " + this.oad + ", rsd: " + this.rsd + ", rcsd: " + this.rcsd + "}"; } else { return "rcsd || rsd || oad || tsa || waittime || piid is null"; } } }