com.jn.agileway.codec.serialization.protostuff.ProtostuffCodec Maven / Gradle / Ivy
package com.jn.agileway.codec.serialization.protostuff;
import com.jn.agileway.codec.AbstractCodec;
import com.jn.langx.codec.CodecException;
public class ProtostuffCodec extends AbstractCodec {
public ProtostuffCodec() {
}
public ProtostuffCodec(Class targetType) {
setTargetType(targetType);
}
@Override
protected byte[] doEncode(T t, boolean withSchema) throws CodecException {
try {
return withSchema ? Protostuffs.serializeWithSchema(t) : Protostuffs.serialize(t);
} catch (Throwable ex) {
throw new CodecException(ex.getMessage(), ex);
}
}
@Override
protected T doDecode(byte[] bytes, boolean withSchema, Class targetType) throws CodecException {
try {
return withSchema ? Protostuffs.deserializeWithSchema(bytes) : Protostuffs.deserialize(bytes, targetType);
} catch (Throwable ex) {
throw new CodecException(ex.getMessage(), ex);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy