package com.gyee.edge.protocol.iec60870.infoelement;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * Represents a fixed test bit pattern (FBP) information element.
 */
public class IeFixedTestBitPattern extends InformationElement {

    public IeFixedTestBitPattern() {
    }

    IeFixedTestBitPattern(DataInputStream is) throws IOException {
        if ((is.readByte() & 0xff) != 0x55 || (is.readByte() & 0xff) != 0xaa) {
            throw new IOException("Incorrect bit pattern in Fixed Test Bit Pattern.");
        }
    }

    @Override
    int encode(byte[] buffer, int i) {

        buffer[i++] = 0x55;
        buffer[i] = (byte) 0xaa;
        return 2;
    }

    @Override
    public String toString() {
        return "Fixed test bit pattern";
    }
}
