package com.yeejoin.amos.iec104.tcp.entity;

import io.netty.buffer.ByteBuf;

import java.io.IOException;

public class IeInteger extends InformationElement {

    private final int value;

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

    public IeInteger(ByteBuf is) throws IOException {
        value = (is.readByte() & 0xff) | ((is.readByte() & 0xff) << 8);
    }

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

        int tempVal = value;
        buffer[i++] = (byte) tempVal;
        buffer[i] = (byte) (tempVal >> 8);

        return 2;
    }

    public float getValue() {
        return value;
    }

    @Override
    public String toString() {
        return "归一化数值: " + value;
    }
}
