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

top.netkit.redis.client.codec.CustomCodec Maven / Gradle / Ivy

The newest version!
package top.netkit.redis.client.codec;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.codec.TypedJsonJacksonCodec;

import java.io.IOException;

/**
 * 自定义customCodec
 * @author shixinke
 */
public class CustomCodec extends TypedJsonJacksonCodec {

    private final Decoder decoder = new Decoder() {
        @Override
        public Object decode(ByteBuf buf, State state) throws IOException {
            String str = buf.toString(CharsetUtil.UTF_8);
            buf.readerIndex(buf.readableBytes());
            return str;
        }
    };

    public CustomCodec(Class valueClass) {
        super(valueClass);
    }

    public CustomCodec(Class valueClass, ObjectMapper mapper) {
        super(valueClass, mapper);
    }

    public CustomCodec(Class mapKeyClass, Class mapValueClass) {
        super(mapKeyClass, mapValueClass);
    }

    public CustomCodec(Class mapKeyClass, Class mapValueClass, ObjectMapper mapper) {
        super(mapKeyClass, mapValueClass, mapper);
    }

    public CustomCodec(Class valueClass, Class mapKeyClass, Class mapValueClass) {
        super(valueClass, mapKeyClass, mapValueClass);
    }

    public CustomCodec(Class valueClass, Class mapKeyClass, Class mapValueClass, ObjectMapper mapper) {
        super(valueClass, mapKeyClass, mapValueClass, mapper);
    }

    public CustomCodec(TypeReference valueTypeReference) {
        super(valueTypeReference);
    }

    public CustomCodec(TypeReference valueTypeReference, ObjectMapper mapper) {
        super(valueTypeReference, mapper);
    }

    public CustomCodec(TypeReference mapKeyTypeReference, TypeReference mapValueTypeReference) {
        super(mapKeyTypeReference, mapValueTypeReference);
    }

    public CustomCodec(TypeReference mapKeyTypeReference, TypeReference mapValueTypeReference, ObjectMapper mapper) {
        super(mapKeyTypeReference, mapValueTypeReference, mapper);
    }

    public CustomCodec(TypeReference valueTypeReference, TypeReference mapKeyTypeReference, TypeReference mapValueTypeReference) {
        super(valueTypeReference, mapKeyTypeReference, mapValueTypeReference);
    }

    public CustomCodec(TypeReference valueTypeReference, TypeReference mapKeyTypeReference, TypeReference mapValueTypeReference, ObjectMapper mapper) {
        super(valueTypeReference, mapKeyTypeReference, mapValueTypeReference, mapper);
    }

    public CustomCodec(ClassLoader classLoader, TypedJsonJacksonCodec codec) {
        super(classLoader, codec);
    }

    @Override
    public Decoder getMapKeyDecoder() {
        return decoder;
    }


}