package com.its.vds.xnettcp.center.protocol;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;

@Slf4j
@Getter
public class CenterReqFrameHead {

    public static int SIZE = 10;
    public static int OPCODE_POS = 6;

    private byte sender;
    private byte receiver;
    private byte total;
    private byte current;
    private byte reserved;
    private byte opCode;
    private int  length;

    public CenterReqFrameHead(byte[] headBytes) {
        if (headBytes != null && headBytes.length >= SIZE) {
            ByteBuffer byteBuffer = ByteBuffer.wrap(headBytes);
            byteBuffer.order(CenterProtocol.byteOrder);
            this.sender = byteBuffer.get();
            this.receiver = byteBuffer.get();
            this.total = byteBuffer.get();
            this.current = byteBuffer.get();
            this.reserved = byteBuffer.get();
            this.opCode = byteBuffer.get();
            this.length = byteBuffer.getInt();
        }
        else {
            log.error("CenterReqFrameHead: create failed, headBytes error");
        }
    }

}
