package com.imdroid.ntripproxy.executor;

import com.imdroid.ntripproxy.message.D333RtcmMessage;
import com.imdroid.ntripproxy.service.OnlineChannels;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * @author Layton
 * @date 2023/2/2 20:49
 */
@Component
public class D333RtcmMessageExecutor implements Executor<D333RtcmMessage, Void> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public Void execute(D333RtcmMessage message) {
        String id = message.getId();
        // 补齐tenantId
        if (logger.isDebugEnabled()) {
            logger.debug("receive d333 message of device: "+id+", seq:"+message.getSeq()+", len:"+message.getLen());
        }
        // 推送基站数据
        OnlineChannels.INSTANCE.get(id).ifPresent(deviceChannel -> {
            deviceChannel.writeAndFlush(message.getTransBuf());
        });

        return null;
    }

    @Override
    public Class<?> getMessageType() {
        return D333RtcmMessage.class;
    }
}
