All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openmuc.jdlms.internal.asn1.cosem.InitiateResponse Maven / Gradle / Ivy

/**
 * This class file was automatically generated by the AXDR compiler that is part of jDLMS (http://www.openmuc.org)
 */

package org.openmuc.jdlms.internal.asn1.cosem;

import java.io.IOException;
import java.io.InputStream;

import org.openmuc.jasn1.ber.ReverseByteArrayOutputStream;
import org.openmuc.jdlms.internal.asn1.axdr.AxdrType;
import org.openmuc.jdlms.internal.asn1.axdr.types.AxdrOptional;

public class InitiateResponse implements AxdrType {

    public byte[] code = null;
    public AxdrOptional negotiatedQualityOfService = new AxdrOptional<>(new Integer8(), false);

    public Unsigned8 negotiatedDlmsVersionNumber = null;

    public Conformance negotiatedConformance = null;

    public Unsigned16 serverMaxReceivePduSize = null;

    public Integer16 vaaName = null;

    public InitiateResponse() {
    }

    public InitiateResponse(byte[] code) {
        this.code = code;
    }

    public InitiateResponse(Integer8 negotiatedQualityOfService, Unsigned8 negotiatedDlmsVersionNumber,
            Conformance negotiatedConformance, Unsigned16 serverMaxReceivePduSize, Integer16 vaaName) {
        this.negotiatedQualityOfService.setValue(negotiatedQualityOfService);
        this.negotiatedDlmsVersionNumber = negotiatedDlmsVersionNumber;
        this.negotiatedConformance = negotiatedConformance;
        this.serverMaxReceivePduSize = serverMaxReceivePduSize;
        this.vaaName = vaaName;
    }

    @Override
    public int encode(ReverseByteArrayOutputStream axdrOStream) throws IOException {

        int codeLength;

        if (code != null) {
            codeLength = code.length;
            for (int i = code.length - 1; i >= 0; i--) {
                axdrOStream.write(code[i]);
            }
        }
        else {
            codeLength = 0;
            codeLength += vaaName.encode(axdrOStream);

            codeLength += serverMaxReceivePduSize.encode(axdrOStream);

            codeLength += negotiatedConformance.encode(axdrOStream);

            codeLength += negotiatedDlmsVersionNumber.encode(axdrOStream);

            codeLength += negotiatedQualityOfService.encode(axdrOStream);

        }

        return codeLength;

    }

    @Override
    public int decode(InputStream iStream) throws IOException {
        int codeLength = 0;

        negotiatedQualityOfService = new AxdrOptional<>(new Integer8(), false);
        codeLength += negotiatedQualityOfService.decode(iStream);

        negotiatedDlmsVersionNumber = new Unsigned8();
        codeLength += negotiatedDlmsVersionNumber.decode(iStream);

        negotiatedConformance = new Conformance();
        codeLength += negotiatedConformance.decode(iStream);

        serverMaxReceivePduSize = new Unsigned16();
        codeLength += serverMaxReceivePduSize.decode(iStream);

        vaaName = new Integer16();
        codeLength += vaaName.decode(iStream);

        return codeLength;
    }

    public void encodeAndSave(int encodingSizeGuess) throws IOException {
        ReverseByteArrayOutputStream axdrOStream = new ReverseByteArrayOutputStream(encodingSizeGuess);
        encode(axdrOStream);
        code = axdrOStream.getArray();
    }

    @Override
    public String toString() {
        return "sequence: {" + "negotiatedQualityOfService: " + negotiatedQualityOfService
                + ", negotiatedDlmsVersionNumber: " + negotiatedDlmsVersionNumber + ", negotiatedConformance: "
                + negotiatedConformance + ", serverMaxReceivePduSize: " + serverMaxReceivePduSize + ", vaaName: "
                + vaaName + "}";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy