All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jfirer.fse.serializer.base.BooleanSerializer Maven / Gradle / Ivy

The newest version!
package com.jfirer.fse.serializer.base;

import com.jfirer.fse.*;

public class BooleanSerializer extends CycleFlagSerializer implements FseSerializer
{
    @Override
    public void init(Class type, SerializerFactory serializerFactory)
    {
    }

    @Override
    public void writeToBytes(Object o, int classIndex, InternalByteArray byteArray, FseContext fseContext, int depth)
    {
        byteArray.writeVarInt(classIndex);
        if (((Boolean) o))
        {
            byteArray.put((byte) 1);
        }
        else
        {
            byteArray.put((byte) 2);
        }
    }


    @Override
    public Object readBytes(InternalByteArray byteArray, FseContext fseContext)
    {
        byte flag = byteArray.get();
        if (flag == 0)
        {
            return null;
        }
        else if (flag == 1)
        {
            return Boolean.TRUE;
        }
        else
        {
            return Boolean.FALSE;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy