
var coder = require("./coder");

var tool = require("./tool");
var util = require("util");

exports.ProxyGetMasterReq = ProxyGetMasterReq;
exports.ProxyGetMasterRsp = ProxyGetMasterRsp;

exports.ProxyGetGateReq = ProxyGetGateReq;
exports.ProxyGetGateRsp = ProxyGetGateRsp;


coder.RegistType("TGetFreeMasterReq",ProxyGetMasterReq);
coder.RegistType("TGetFreeMasterRsp",ProxyGetMasterRsp);


coder.RegistType("TGetGateRequest",ProxyGetGateReq);
coder.RegistType("TGetGateResponce",ProxyGetGateRsp);

//------------------------------------------
function ProxyGetMasterReq(appid,num){
	coder.Type.call(this,"TGetFreeMasterReq");
	this.appid_ = appid;
	this.num_ = num;

}
util.inherits(ProxyGetMasterReq, coder.Type);
ProxyGetMasterReq.prototype.BodyLength = function(){
	return Buffer.byteLength(this.appid_) + 1 + 4;
}
ProxyGetMasterReq.prototype.DecodeBody = function(buf_reader){
	this.num_ = buf_reader.ReadUInt32();
	this.appid_ = buf_reader.ReadStringAscii();
}

ProxyGetMasterReq.prototype.EncodeBody = function(buf_writer){
	buf_writer.WriteUInt32(this.num_);
	buf_writer.WriteStringAscii(this.appid_);
}
//------------------------------------------
function ProxyGetMasterRsp(){
	coder.Type.call(this,"TGetFreeMasterRsp");
	this.addr_ = "";

}
util.inherits(ProxyGetMasterRsp, coder.Type);
ProxyGetMasterRsp.prototype.BodyLength = function(){
	return Buffer.byteLength(this.addr_) + 1;
}
ProxyGetMasterRsp.prototype.DecodeBody = function(buf_reader){
	this.addr_ = buf_reader.ReadStringAscii();
}

ProxyGetMasterRsp.prototype.EncodeBody = function(buf_writer){
	buf_writer.WriteStringAscii(this.addr_);
}


//------------------------------------------
function ProxyGetGateReq(appid){
	coder.Type.call(this,"TGetGateRequest");
	this.appid_ = appid;

}
util.inherits(ProxyGetGateReq, coder.Type);
ProxyGetGateReq.prototype.BodyLength = function(){
	return Buffer.byteLength(this.appid_) + 1;
}
ProxyGetGateReq.prototype.DecodeBody = function(buf_reader){
	this.appid_ = buf_reader.ReadStringAscii();
}

ProxyGetGateReq.prototype.EncodeBody = function(buf_writer){
	buf_writer.WriteStringAscii(this.appid_);
}
//------------------------------------------
function ProxyGetGateRsp(){
	coder.Type.call(this,"TGetGateResponce");
	this.addr_list_ = [];

}
util.inherits(ProxyGetGateRsp, coder.Type);
ProxyGetGateRsp.prototype.BodyLength = function(){
	var size = 1;
	for(var i in this.addr_list_){
		size+= Buffer.byteLength(this.addr_list_[i]) + 1;
	}
	return size;
}
ProxyGetGateRsp.prototype.DecodeBody = function(buf_reader){
	var num = buf_reader.ReadUInt8();
	for(var i=0;i<num;i++){
		this.addr_list_.push(buf_reader.ReadStringAscii());
	}
}

ProxyGetGateRsp.prototype.EncodeBody = function(buf_writer){
	buf_writer.WriteUInt8(this.addr_list_.length);
	for(var i in this.addr_list_){
		buf_writer.WriteStringAscii(this.addr_list_[i]);
	}
}




