--һ׼Lua PassTcpű
--ṩ¼ķװͽյ¼ķװ
--֯ķݺ֤
--ӿƣҪǿǵ̲߳ٲҪ߳
--ݿ鲻Ҫڽű㲻ͷ
--Ŀǰ֧100KݿС
--add by freeeyes

--Ҫݵ¼PassTCPãʵķݷ
--ڲnThreadIDǵǰ߳IDszDataϢ(char* )nLenǻ󳤶ȣnSendIndexǵǰӵķʹ
function PassTcp_CreateSendData(szData, nLen, nThreadID, nSendIndex)
    --
	--szDataΪchar* ҪĻ顣
	--nLenǵǰ󳤶
	--nNextIndex-1˵ֵ,򷵻һεʼλ
	
	--4ֽڰͷ
	nPacketSize = 10
	nStartIndex  = 0
	nNextIndex  = 0
	nNextIndex = Lua_Tcp_Buffer_In_Int32(szData, nPacketSize, nStartIndex, nLen)
	
	--2ֽڵ
	nCommandID = 4096
	nNextIndex = Lua_Tcp_Buffer_In_Int16(szData, nCommandID, nNextIndex, nLen)
	
	--ݿ
	szBuff = '12345678'
	nNextIndex = Lua_Tcp_Buffer_In_Block(szData, szBuff, 8, nNextIndex, nLen)
	
	--뷵ݿĳȣPassTCP֪ܳ
	return nNextIndex
end

--յ¼
--ڲnThreadIDǵǰ߳IDszDataǽյ(char* )nLenǵǰյĳȣnSendIndexǵǰӵķʹ
function PassTcp_GetRecvData(szData, nLen, nThreadID)
    --õ
	--szDataǵǰյݿ
	--nLenյݿ鳤
	--ķأһint
	--Ŀǰô壬   0ݰɹ֤Ϸɹݰ+1
	--                 1յİûн
	--                 2ݰ֤ʧܣǴݰ+1
	
	--жϽݰĳ
	nCurrIndex = 0;
	nPacketLength = Lua_Tcp_Buffer_Out_Int32(szData, nCurrIndex, nLen, nSendIndex);
	if nPacketLength ~= 10 then
		return 2;
	end
	
	--жϽյķIDǷȷ
	nCurrIndex = 4
	nCommandID = Lua_Tcp_Buffer_Out_Int16(szData, nCurrIndex, nLen);
	if nCommandID ~= 4096 then
		return 2;
	end
	
	--֤ɹ
	return 0;
end


