package com.imdroid.ntripproxy.executor;

import com.imdroid.ntripproxy.message.D331RtcmMessage;
import com.imdroid.ntripproxy.service.UDPClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


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

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    UDPClient rtcmClient;
    @Override
    public Void execute(D331RtcmMessage message) {
        String id = message.getId();
        // 补齐tenantId
        if (logger.isDebugEnabled()) {
            logger.debug("receive d331 message of device: "+id+", seq:"+message.getSeq()+", len:"+message.getLen());
        }
        // 推送基站数据
        byte[] srcData = new byte[message.getSrcBuf().readableBytes()];
        message.getSrcBuf().getBytes(0,srcData);
        rtcmClient.send(srcData);

        return null;
    }

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