001package jmri.jmrix.mqtt;
002
003import javax.annotation.Nonnull;
004import jmri.NamedBean;
005
006/**
007 * Interface defining a content parser, which translates to and from the MQTT payload
008 * content.
009 * 
010 * @author Bob Jacobsen
011 */
012public interface MqttContentParser<T extends NamedBean> {
013    /**
014     * Load a bean's state from a received MQTT payload.
015     * @param bean The particular item receiving the payload
016     * @param payload The entire string received via MQTT
017     * @param topic MQTT topic.
018     * @throws IllegalArgumentException if the payload is unparsable.
019     */
020    void beanFromPayload(@Nonnull T bean, @Nonnull String payload, @Nonnull String topic);
021    
022    /**
023     * Create the payload for a particular state transformation on 
024     * a particular bean.
025     * @param bean The particular item sending the payload
026     * @param newState The value to be sent to the layout; this is not yet present in the bean
027     * @return String payload to transfer via MQTT.
028     */
029    @Nonnull String payloadFromBean(@Nonnull T bean, int newState);
030     
031}