import {AxdrType} from "../asn1.axdr/AxdrType"; import {Buffer} from "buffer"; import {Date_time_s} from "./Date_time_s"; import {MS} from "./MS"; import {ReverseByteArrayInputStream} from "../ReverseByteArrayInputStream"; import {ReverseByteArrayOutputStream} from "../ReverseByteArrayOutputStream"; export class Selector5 implements AxdrType{ dataCode : Buffer | null = null; dts : Date_time_s | null = null; ms : MS | null = null; constructor() { } set_dataCode(dataCode : Buffer){ this.dataCode = dataCode; } set_all(dts : Date_time_s, ms : MS){ this.dts = dts; this.ms = ms; } decode(input: ReverseByteArrayInputStream): number { let codeLength = 0; this.dts = new Date_time_s(); codeLength += this.dts.decode(input); this.ms = new MS(); codeLength += this.ms.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.dts != null && this.ms != null){ codeLength = 0; codeLength += this.ms.encode(output); codeLength += this.dts.encode(output); }else{ throw new Error("dts or ms 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.dts != null && this.ms != null) { return "sequence: {"+ "dts: " + this.dts + ", ms: " + this.ms + "}"; } else { return "dts or ms is null"; } } }