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

	@Override
	public int getId()
	{
		return 5;
	}
	
	@Override
	public String getTypeName()
	{
		return "Long";
	}
	
	@Override
	public long countBytes(long input)
	{
		return input + 8L;
	}
	
	@Override
	public void write(ExtendedDataOutput output, TagCompressor compressor) throws IOException
	{
		output.writeLong(value);
	}
	
	@Override
	public void read(ExtendedDataInput input, TagDecompressor decompressor, int depthLimit, DataTagLimiter limiter) throws IOException
	{
		value = input.readLong();
		limiter.countBytes(8);
	}
	
	@Override
	public DataTag copy()
	{
		return new LongTag(value);
	}
	
	@Override
	public int hashCode()
	{
		return Long.hashCode(value);
	}

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

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