package com.imdroid.sideslope.message;

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

/**
 * @author Layton
 * @date 2023/2/2 20:47
 */
public class D31xConfigAckMessage extends BaseMessage {

    @Override
    public void decodeBody(ByteBuf src) {
        //srcData需要完整的消息，所以解析头用get方法
        this.header = src.getUnsignedShort(0); // flag
        this.len = src.getUnsignedShort(2); // length:11bit
        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);
        }
        this.srcData = new byte[src.readableBytes()];
        src.readBytes(this.srcData);
    }

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