package com.its.dsrc.xnetudp.protocol;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

@Getter
@Setter
@ToString
public class CENTER_DSRC_RES_CONTROL extends CENTER_COMM_MESSAGE {

	private int  ctlrNmbr;
	private int  reqSeq;
	private byte resCode;
	public CENTER_DSRC_RES_CONTROL() {

	}

	public CENTER_DSRC_RES_CONTROL(byte msgSeq) {
		super(CENTER_COMM_DEFINE.INT_ID_DSRC_SERVER, CENTER_COMM_DEFINE.INT_OP_DSRC_CONTROL_RES, 0, msgSeq);
	}

	@Override
	public ByteBuffer getBuffer() {
		int pktSize = 9;
		setLength(pktSize);

		ByteBuffer byteBuffer = ByteBuffer.allocate(CENTER_HEADER_SIZE + getLength());
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);

		byteBuffer.put(getSendId());
		byteBuffer.put(getRecvId());
		byteBuffer.put(getTotalFrame());
		byteBuffer.put(getCurrentFrame());
		byteBuffer.put(getMsgSeq());
		byteBuffer.put(getOpCode());
		byteBuffer.putShort((short)getLength());

		byteBuffer.putInt(this.ctlrNmbr);
		byteBuffer.putInt(this.reqSeq);
		byteBuffer.put(this.resCode);

		return byteBuffer;
		//return byteBuffer.array();
	}

}
