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

com.soento.redis.support.BaseRedisSerializationStrategy Maven / Gradle / Ivy

package com.soento.redis.support;

/**
 * @author soento
 */
public abstract class BaseRedisSerializationStrategy implements RedisSerializationStrategy {

    private static final byte[] EMPTY_ARRAY = new byte[0];

    private static boolean isEmpty(byte[] bytes) {
        return bytes == null || bytes.length == 0;
    }

    @Override
    public  T deserialize(byte[] bytes, Class clazz) {
        if (isEmpty(bytes)) {
            return null;
        }
        return deserializeInternal(bytes, clazz);
    }

    protected abstract  T deserializeInternal(byte[] bytes, Class clazz);

    @Override
    public String deserialize(byte[] bytes) {
        if (isEmpty(bytes)) {
            return null;
        }
        return deserializeInternal(bytes);
    }

    protected abstract String deserializeInternal(byte[] bytes);

    @Override
    public byte[] serialize(Object object) {
        if (object == null) {
            return EMPTY_ARRAY;
        }
        return serializeInternal(object);
    }

    protected abstract byte[] serializeInternal(Object object);

    @Override
    public byte[] serialize(String data) {
        if (data == null) {
            return EMPTY_ARRAY;
        }
        return serializeInternal(data);
    }

    protected abstract byte[] serializeInternal(String data);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy