package com.its.dsrc.xnetudp.protocol;

import com.its.app.utils.SysUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

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

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

	private String cmdTime;
	private String operId;
	private String ctlrNmbr;
	private byte[] body;

	public CENTER_DSRC_REQ_COMMON(byte buffer[]) {
		ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);

		byte cmdTime[] = new byte[CENTER_COMM_DEFINE.INT_DSRC_MAX_DATETIME];
		byte operId[]  = new byte[CENTER_COMM_DEFINE.INT_DSRC_MAX_OPER_ID];
		int  nmbr;
		
		byteBuffer.get(cmdTime);
		byteBuffer.get(operId);
		nmbr = byteBuffer.getInt();

		this.cmdTime  = new String(cmdTime).trim();
		this.operId   = SysUtils.byteArrayToString(operId);
		this.ctlrNmbr = Integer.toString(nmbr);

		if (byteBuffer.remaining() > 0) {
			body = new byte[byteBuffer.remaining()];
			byteBuffer.get(body);
		}
		else {
			body = null;
		}
	}

	public byte[] getBody() {
		return body;
	}
	public void setBody(byte[] body) {
		this.body = body;
	}

}
