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 ShortTag implements PrimitiveTag
{
	short value;
	
	public ShortTag()
	{
	}
	
	public ShortTag(short value)
	{
		this.value = value;
	}

	@Override
	public int getId()
	{
		return 2;
	}
	
	@Override
	public String getTypeName()
	{
		return "Short";
	}
	
	@Override
	public long countBytes(long input)
	{
		return input + 2L;
	}
	
	@Override
	public void write(ExtendedDataOutput output, TagCompressor compressor) throws IOException
	{
		output.writeShort(value);
	}
	
	@Override
	public void read(ExtendedDataInput input, TagDecompressor decompressor, int depthLimit, DataTagLimiter limiter) throws IOException
	{
		value = input.readShort();
		limiter.countBytes(2);
	}
	
	@Override
	public ShortTag copy()
	{
		return new ShortTag(value);
	}
	
	@Override
	public int hashCode()
	{
		return value;
	}

	@Override
	public boolean equals(Object obj)
	{
		return obj instanceof ShortTag && ((ShortTag)obj).value == value;
	}

	@Override
	public String toString()
	{
		return value+"s";
	}
	
	@Override
	public String prettyPrint(String indent, int depth)
	{	
		return new StringBuilder().append(NUMBER_HIGHLIGHT).append(value).append(TYPE_HIGHLIGHT).append("s").append(RESET_HIGHLIGHT).toString();
	}
	
	@Override
	public byte asByte()
	{
		return (byte)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;
	}
	
}
