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