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

com.jn.agileway.codec.serialization.fst.FstCodec Maven / Gradle / Ivy

Go to download

Provide an unified codec API for hession, kryo, protostuff, fst, fes, xson, cbor, jackson, json, etc....

There is a newer version: 3.1.12
Show newest version
package com.jn.agileway.codec.serialization.fst;

import com.jn.agileway.codec.AbstractCodec;
import com.jn.langx.annotation.Nullable;
import com.jn.langx.codec.CodecException;
import org.nustaq.serialization.FSTConfiguration;

public class FstCodec extends AbstractCodec {
    @Nullable
    private FSTConfiguration fst = Fsts.fstFactory.get();


    @Override
    protected byte[] doEncode(T t, boolean withSchema) throws CodecException {
        try {
            return Fsts.serialize(fst, t);
        } catch (Throwable ex) {
            throw new CodecException(ex.getMessage(), ex);
        }
    }

    @Override
    protected T doDecode(byte[] bytes, boolean withSchema, Class targetType) throws CodecException {
        try {
            return Fsts.deserialize(fst, bytes, targetType);
        } catch (Throwable ex) {
            throw new CodecException(ex.getMessage(), ex);
        }
    }


    public FSTConfiguration getFst() {
        return fst;
    }

    public void setFst(FSTConfiguration fst) {
        if (fst != null) {
            this.fst = fst;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy