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

import java.io.IOException;

import speiger.src.coreengine.utils.io.dataTag.DataTag;
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 MediumTag implements PrimitiveTag
{
	int value;
	
	public MediumTag()
	{
	}
	
	public MediumTag(int value)
	{
		this.value = value;
	}

	@Override
	public int getId()
	{
		return 3;
	}
	
	@Override
	public String getTypeName()
	{
		return "Medium";
	}
	
	@Override
	public long countBytes(long input)
	{
		return input + 3L;
	}
	
	@Override
	public void write(ExtendedDataOutput output, TagCompressor compressor) throws IOException
	{
		output.writeMedium(value);
	}
	
	@Override
	public void read(ExtendedDataInput input, TagDecompressor decompressor, int depthLimit, DataTagLimiter limiter) throws IOException
	{
		value = input.readMedium();
		limiter.countBytes(3);
	}
	
	@Override
	public DataTag copy()
	{
		return new MediumTag(value);
	}
	
	@Override
	public int hashCode()
	{
		return value;
	}

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

	@Override
	public String toString()
	{
		return value+"m";
	}
	
	@Override
	public String prettyPrint(String indent, int depth)
	{	
		return new StringBuilder().append(NUMBER_HIGHLIGHT).append(value).append(TYPE_HIGHLIGHT).append("m").append(RESET_HIGHLIGHT).toString();
	}

	@Override
	public byte asByte()
	{
		return (byte)value;
	}
	
	@Override
	public short asShort()
	{
		return (short)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;
	}
}
