package com.mq.mylibrary.rfid.io.service;

public class PayLoad {

	static String MB = "0"; //说明这是末记录01010001
	static String ME = "1";//说明这是末记录(说明消息只有一个记录)
	static String CF = "0"; //说明记录未被切块
	static String SR = "1";//说明这是短记录，PAYLOAD_LENGTH 占1字节
	static String IL = "0";//说明没有 ID_LENGTH 和 ID 域
	static String TNF = "001"; //TNf占三个位
	static String endStr = "B";
	
	
	private byte FirstByte = Tools.hexStringToBytes(Integer.toHexString(Integer.parseInt(MB+ME+CF+SR+IL+TNF, 2)))[0];
	private byte TYPE_LENGTH;// 类型的长度
	private byte PAYLOAD_LENGTH;  //payload的长度
	private byte TYPE;  //payload的类型
	private byte[] payLoadContent; //payload的内容
	private byte httpType = 0x01;
	
	
	public PayLoad(String strUri){
		this.payLoadContent = Tools.hexStringToBytes(Tools.str2HexStr(strUri));
		this.PAYLOAD_LENGTH = (byte)(payLoadContent.length+1);
		this.TYPE = 0x55;
		this.TYPE_LENGTH = 0x01;
	}
	/**
	 * 获取payload的字节数组
	 * @return
	 */
	public byte[] getPayLoad(){
		
		byte[] payload = new byte[payLoadContent.length+5];
		payload[0] = FirstByte;
		payload[1] = TYPE_LENGTH;
		payload[2] = PAYLOAD_LENGTH;
		payload[3] = TYPE;
		payload[4] = httpType;
		for(int i = 0;i<payLoadContent.length;i++){
			payload[i+5] = payLoadContent[i];
		}
		return payload;
	}
}
