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

club.pizzalord.shire.serializer.protostuff.ProtostuffSerializer Maven / Gradle / Ivy

There is a newer version: 0.0.14
Show newest version
package club.pizzalord.shire.serializer.protostuff;

import club.pizzalord.shire.sdk.exceptions.ShireException;
import club.pizzalord.shire.serializer.core.Serializer;
import io.protostuff.LinkedBuffer;
import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;

/**
 * Protostuff serializer
 *
 * @author Xpizza
 * @since shire1.0
 */
public class ProtostuffSerializer implements Serializer {
    @Override
    public  byte[] serialize(T object) {
        LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
        try {
            Schema schema = SchemaManager.getSchema((Class) object.getClass());
            return ProtostuffIOUtil.toByteArray(object, schema, buffer);
        } catch (Exception e) {
            throw new ShireException("Failure to serialize with protostuff", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy