--与YY通讯的协议读取与发送的封装类
PacketBase = {
	CreateRecv = function( self, nObject, nIndex ) --创建一个对象，用于读取结构
		local Packet = { obj=nObject,  idx=nIndex,
			     GetInteger        = self.GetInteger,
			     GetInteger32	   = self.GetInteger32,	
			     GetAcharString    = self.GetAcharString,
			     GetAcharFromWchar = self.GetAcharFromWchar }
		return Packet
	end; --函数结束
	CreateTeamSend = function( self )   --创建一个对象，用来发送队伍的消息
		local nObject = CUIControl:getSingleton():GetTeamObject()
		if( nObject == 0 ) then return nil end
		local nIndex = CUIControl:getSingleton():CreatePacket( nObject )
		if( nIndex == -1 ) then return nil end
		local Packet = { obj=nObject, idx=nIndex,
			     PutInteger=self.PutInteger, PutAchar=self.PutAchar,
			     PutAcharToWchar=self.PutAcharToWchar, SendToYY=self.SendToYY }
		return Packet
	end; --函数结束
	CreateChannelSend = function( self )   --创建一个对象，用来发送频道的消息
		local nObject = CUIControl:getSingleton():GetChannelObject()
		if( nObject == 0 ) then return nil end
		local nIndex = CUIControl:getSingleton():CreatePacket( nObject )
		if( nIndex == -1 ) then return nil end
		local Packet = { obj=nObject, idx=nIndex,
			     PutInteger=self.PutInteger, PutAchar=self.PutAchar,
			     PutAcharToWchar=self.PutAcharToWchar, SendToYY=self.SendToYY  }
		return Packet
	end; --函数结束

	--------------------------------------------------------------------------------------
	PutInteger = function( self, Value ) --向包中写入一个数字
		CUIControl:getSingleton():PutIntToPacket( self.obj, self.idx, Value, 4 )
	end; --函数结束
	PutAchar = function( self, astring )       --直接将Ascii字符串写入包中
		CUIControl:getSingleton():PutAcharToPacket( self.obj, self.idx, astring, #astring)
	end;
	PutAcharToWchar = function( self, astring ) --将Ascii字符串转为Unicode写入包中
		CUIControl:getSingleton():PutAcharToWchar( self.obj, self.idx, astring, #astring )
	end; --函数结束
	SendToYY = function( self )  --把包中的数据发送到YY客户端
		CUIControl:getSingleton():SendToYYIPC( self.obj, self.idx )
	end; --函数结束
	--------------------------------------------------------------------------------------
	GetInteger = function( self, Size )  --从包中获得一个数字
		return CUIControl:getSingleton():GetIntFromPacket( self.obj, self.idx, Size )
	end; --函数结束
	GetInteger32 = function( self, Size )  --获取负数返回值专用
		return CUIControl:getSingleton():GetInt32FromPacket( self.obj, self.idx, Size )
	end; --函数结束
	GetAcharString = function( self, len )    --从包中获得Ascii字符串
		-- smartYY的协议字符串长度为4
		-- lol语音的字符串长度为2
		if len == nil or len == 0 then
			len = 2
		end

		local size = CUIControl:getSingleton():GetIntFromPacket( self.obj, self.idx, len )
		return CUIControl:getSingleton():GetAsciiCharFromPacket( self.obj, self.idx, size )
	end;
	GetAcharFromWchar = function( self, len, flag ) --从包中获得Unicode转为Ascii的字符串
		-- smartYY的协议字符串长度为4
		-- lol语音的字符串长度为2
		if len == nil or len == 0 then
			len = 2
		end

		local size = CUIControl:getSingleton():GetIntFromPacket( self.obj, self.idx, len )

		-- smartYY的wide char长度为实际字节长度
		-- lol语音的wide char长度为字符串长度,实际长度需要*2
		-- 代码内部对lol语音的wide char长度*2,所以smartYY长度需要/2
		if flag == true then
			size = size / 2
		end

		return CUIControl:getSingleton():GetAsciiFromWidePacket( self.obj, self.idx, size )
	end; --函数结束
} --end table