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

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

package club.pizzalord.shire.serializer.protostuff;

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

/**
 * Protostuff deserializer
 *
 * @author Xpizza
 * @since shire1.0
 */
public class ProtostuffDeserializer implements Deserializer {
    @Override
    public  T deserializeBytes(byte[] bytes, Class clazz) {
        try {
            Schema schema = SchemaManager.getSchema(clazz);
            T object = schema.newMessage();
            ProtostuffIOUtil.mergeFrom(bytes, object, schema);
            return object;
        } catch (Exception e) {
            throw new ShireException("fatal: deserialize data with protostuff", e);
        }
    }

    @Override
    public  T deserializeString(String string, Class clazz) {
        return deserializeBytes(string.getBytes(), clazz);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy