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

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

/**
 * Represents a checksum (CHS) information element.
 */
public class IeChecksum extends InformationElement {

    private final int value;

    public IeChecksum(int value) {
        this.value = value;
    }

    static IeChecksum decode(DataInputStream is) throws IOException {
        return new IeChecksum(is.readUnsignedByte());
    }

    @Override
    int encode(byte[] buffer, int i) {
        buffer[i] = (byte) value;
        return 1;
    }

    public int getValue() {
        return value;
    }

    @Override
    public String toString() {
        return "Checksum: " + value;
    }
}
