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

io.atleon.protobuf.ProtobufRabbitMQBodyDeserializer Maven / Gradle / Ivy

package io.atleon.protobuf;

import com.google.protobuf.Message;
import io.atleon.rabbitmq.BodyDeserializer;
import io.atleon.rabbitmq.SerializedBody;

import java.util.Map;
import java.util.function.Function;

public final class ProtobufRabbitMQBodyDeserializer implements BodyDeserializer {

    /**
     * Qualified class name of the type of {@link Message} to deserialize into
     */
    public static final String MESSAGE_TYPE_CONFIG = "protobuf.message.type";

    private Function parser;

    @Override
    public void configure(Map properties) {
        this.parser = ProtobufMessages.loadParserOrThrow(properties, MESSAGE_TYPE_CONFIG, byte[].class);
    }

    @Override
    public T deserialize(SerializedBody data) {
        return parser.apply(data.bytes());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy