package cn.net.cpzslibs.prot;

import com.google.gson.Gson;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.SocketTimeoutException;

import cn.net.cpzslibs.prot.bean.Prot104ActBean;

//活动展示详情
public class Prot104Act extends ProtBase {
	private final short iTaskCode104 = 104;
	private String jsonData;

	public void dealProt(SocketCreate create, short iAreaCode) throws SocketTimeoutException,
			IOException {
		sendProt(create.getDos(), iTaskCode104, iAreaCode);
		recProt(create.getDis(), iTaskCode104);
	}

	public String getJsonData() {
		return jsonData;
	}
	
	public Prot104ActBean getActBean(){
		if(jsonData==null||jsonData.isEmpty()){
			return null;
		}
		Gson gson = new Gson();
		Prot104ActBean actBean = gson.fromJson(jsonData, Prot104ActBean.class);
		return actBean;
	}



	private void recProt(DataInputStream dis, short iTaskCode) throws IOException {
		recHeader(dis);
		int jsonLength = getiRecBodySize() - 2;
		jsonData = getUTF8(dis, jsonLength);
		recCheckCode(dis);
	}
	private void sendProt(DataOutputStream dos, short iTaskCode, short iAreaCode) throws SocketTimeoutException,
			IOException {
		short iBodySize = countBodySize(iAreaCode);
		sendHeader(dos, iTaskCode, iBodySize);
		sendiAreaCode(dos, iAreaCode);
		sendCheckCode(dos);
	}

}
