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