package com.imdroid.ntripproxy.message;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author Layton
 * @date 2023/2/2 20:50
 */
@Data
@EqualsAndHashCode(callSuper=true)
public class D333RtcmMessage extends NtripMessage {
    @Override
    public void decodeBody(ByteBuf src) {
        fromDevice = false;
        // d3 42 length(2048+6) device_id(4bytes) seq(2bytes) data
        int transMsgLen = src.readableBytes() + NON_NTRIP_HEAD_LEN-DEVICE_ID_OFFSET;
        byte[] padding = new byte[NON_NTRIP_HEAD_LEN];

        // 修改d341为d332
        transBuf = Unpooled.buffer();
        transBuf.writeShort(0xd331);//head
        transBuf.writeShort(transMsgLen);//length
        transBuf.writeBytes(src,DEVICE_ID_OFFSET,4);//id
        transBuf.writeBytes(padding);
        transBuf.writeBytes(src,DEVICE_ID_OFFSET+4,src.readableBytes()-(DEVICE_ID_OFFSET+4));
    }

}
