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