package com.imdroid.sideslope.message;

import com.imdroid.common.util.WrongMessageRecorder;
import com.imdroid.sideslope.bd.Gga;
import io.netty.buffer.ByteBuf;

/**
 * @author Layton
 * @date  2023/2/2 20:47
 */
public class D331RtcmMessage extends BaseMessage {
    Gga gga;

    @Override
    public void decodeBody(ByteBuf src) {
        // get操作不会移动指针，这样可以确保整个全转发出去
        this.header = src.getUnsignedShort(0); // flag
        this.len = src.getUnsignedShort(2); // length:11 bits
        this.seq = this.len >> 11;
        this.len = this.len & 0x7FF;
        this.id = String.valueOf(src.getUnsignedInt(4)); //id
        if (src.readableBytes() - 4 < this.len) {
            String msg = String.format("id[%s],长度字段值[%s]效益包的消息体长度[%s]", id, this.len, src.readableBytes() - 4);
            WrongMessageRecorder.INSTANCE.append("receive wrong message," + msg);
        }
        gga = Gga.getFrom(src);
        this.srcData = new byte[src.readableBytes()];
        src.readBytes(this.srcData);
    }

    @Override
    public boolean shouldDecodeHeader() {
        return false;
    }

    public Gga getGga() {return gga;}
}
