import {AxdrType} from "../asn1.axdr/AxdrType"; import {ReverseByteArrayInputStream} from "../ReverseByteArrayInputStream"; import {ReverseByteArrayOutputStream} from "../ReverseByteArrayOutputStream"; import {Buffer} from "buffer"; import {OAD} from "./OAD"; import {Data} from "./Data"; import {Unsigned8} from "./Unsigned8"; export class ProxySetGetOAD implements AxdrType{ dataCode : Buffer | null = null; soad : OAD | null = null; param : Data | null = null; road : OAD | null = null; delayTimeRead : Unsigned8 | null = null; constructor() { } set_dataCode(dataCode : Buffer){ this.dataCode = dataCode; } set_all(soad : OAD, param : Data, road : OAD, delayTimeRead : Unsigned8){ this.soad = soad; this.param = param; this.road = road; this.delayTimeRead = delayTimeRead; } setSoad(soad : OAD){ this.soad = soad; } setParam(param : Data){ this.param = param; } setRoad(road : OAD){ this.road = road; } setDelayTimeRead(delayTimeRead : Unsigned8){ this.delayTimeRead = delayTimeRead; } decode(input: ReverseByteArrayInputStream): number { let codeLength = 0; this.soad = new OAD(); codeLength += this.soad.decode(input); this.param = new Data(); codeLength += this.param.decode(input); this.road = new OAD(); codeLength += this.road.decode(input); this.delayTimeRead = new Unsigned8(); this.delayTimeRead.set_const(); codeLength += this.delayTimeRead.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.delayTimeRead != null && this.road != null && this.param != null && this.soad != null){ codeLength = 0; codeLength += this.delayTimeRead.encode(output); codeLength += this.road.encode(output); codeLength += this.param.encode(output); codeLength += this.soad.encode(output); }else{ throw new Error("delayTime || road || param || soad 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.delayTimeRead != null && this.road != null && this.param != null && this.soad != null) { return "sequence: {"+ "soad: " + this.soad + ", param: " + this.param + ", road: " + this.road + ", delaytimeread: " + this.delayTimeRead + "}"; } else { return "delayTime || road || param || soad is null"; } } }