package speiger.src.coreengine.utils.io.dataTag.simple;

import java.io.IOException;

import speiger.src.coreengine.utils.io.dataTag.compression.DataTagLimiter;
import speiger.src.coreengine.utils.io.dataTag.compression.TagCompressor;
import speiger.src.coreengine.utils.io.dataTag.compression.TagDecompressor;
import speiger.src.coreengine.utils.io.streams.ExtendedDataInput;
import speiger.src.coreengine.utils.io.streams.ExtendedDataOutput;

public class ByteTag implements PrimitiveTag
{
	byte value;
	
	public ByteTag()
	{
	}
	
	public ByteTag(byte value)
	{
		this.value = value;
	}

	@Override
	public int getId()
	{
		return 1;
	}
	
	@Override
	public String getTypeName()
	{
		return "Byte";
	}
	
	@Override
	public long countBytes(long input)
	{
		return input + 1L;
	}
	
	@Override
	public void write(ExtendedDataOutput output, TagCompressor compressor) throws IOException
	{
		output.writeByte(value);
	}
	
	@Override
	public void read(ExtendedDataInput input, TagDecompressor decompressor, int depthLimit, DataTagLimiter limiter) throws IOException
	{
		value = input.readByte();
		limiter.countBytes(1);
	}
	
	@Override
	public ByteTag copy()
	{
		return new ByteTag(value);
	}
	
	@Override
	public boolean equals(Object obj)
	{
		return obj instanceof ByteTag && ((ByteTag)obj).value == value;
	}

	@Override
	public int hashCode()
	{
		return value;
	}

	@Override
	public String toString()
	{
		return value+"b";
	}
	
	@Override
	public String prettyPrint(String indent, int depth)
	{	
		return new StringBuilder().append(NUMBER_HIGHLIGHT).append(value).append(TYPE_HIGHLIGHT).append("b").append(RESET_HIGHLIGHT).toString();
	}
	
	@Override
	public byte asByte()
	{
		return value;
	}
	
	@Override
	public short asShort()
	{
		return value;
	}
	
	@Override
	public int asInt()
	{
		return value;
	}
	
	@Override
	public long asLong()
	{
		return value;
	}
	
	@Override
	public float asFloat()
	{
		return value;
	}
	
	@Override
	public double asDouble()
	{
		return value;
	}
}
