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

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

/**
 * Represents a name of file (NOF) information element.
 */
public class IeNameOfFile extends InformationElement {

    private final int value;

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

    static IeNameOfFile decode(DataInputStream is) throws IOException {
        int value = is.readUnsignedByte() | (is.readUnsignedByte() << 8);
        return new IeNameOfFile(value);
    }

    @Override
    int encode(byte[] buffer, int i) {
        buffer[i++] = (byte) value;
        buffer[i] = (byte) (value >> 8);

        return 2;

    }

    public int getValue() {
        return value;
    }

    @Override
    public String toString() {
        return "Name of file: " + value;
    }
}
