예제 #1
0
	int32 onPacketAppend(int32 addsize, bool inseparable = true)
	{
		if(pCurrPacket_ == NULL)
		{
			newPacket();
		}

		int32 packetmaxsize = PACKET_MAX_CHUNK_SIZE();
		int32 totalsize = (int32)pCurrPacket_->totalSize();
		int32 fwpos = (int32)pCurrPacket_->wpos();

		if(inseparable)
			fwpos += addsize;

		if(fwpos >= packetmaxsize)
		{
			TRACE_BUNDLE_DATA(false, pCurrPacket_, pCurrMsgHandler_, totalsize);
			packets_.push_back(pCurrPacket_);
			currMsgPacketCount_++;
			newPacket();
			totalsize = 0;
		}

		int32 remainsize = packetmaxsize - totalsize;
		int32 taddsize = addsize;

		// 如果 当前包剩余空间小于要添加的字节则本次填满此包
		if(remainsize < addsize)
			taddsize = remainsize;
		
		currMsgLength_ += taddsize;
		return taddsize;
	}
예제 #2
0
	Bundle &assign(const char *str, int n)
	{
		int32 len = (int32)n;
		int32 i = 0;
		int32 packetmaxsize = PACKET_MAX_CHUNK_SIZE();

		while(true)
		{
			len = onPacketAppend(len);
			if(len > 0)
			{
				pCurrPacket_->append((uint8*)str + (i++ * packetmaxsize), packetmaxsize);
			}
			else
			{
				pCurrPacket_->append((uint8*)str + (i++ * packetmaxsize), packetmaxsize + len);
				break;
			}
		}
		return *this;
	}
예제 #3
0
    Bundle &operator<<(const char *str)
    {
		int32 len = (int32)strlen(str) + 1;
		int32 i = 0;
		int32 packetmaxsize = PACKET_MAX_CHUNK_SIZE();

		while(true)
		{
			len = onPacketAppend(len);
			if(len > 0)
			{
				pCurrPacket_->append(str + (i++ * packetmaxsize), packetmaxsize);
			}
			else
			{
				pCurrPacket_->append(str + (i++ * packetmaxsize), packetmaxsize + len);
				break;
			}
		}

        return *this;
    }
예제 #4
0
    Bundle &operator<<(const std::string &value)
    {
		int32 len = (int32)value.size() + 1;
		int32 i = 0;
		int32 packetmaxsize = PACKET_MAX_CHUNK_SIZE();

		while(true)
		{
			len = onPacketAppend(len);
			if(len > 0)
			{
				pCurrPacket_->append(value.c_str() + (i++ * packetmaxsize), packetmaxsize);
			}
			else
			{
				pCurrPacket_->append(value.c_str() + (i++ * packetmaxsize), packetmaxsize + len);
				break;
			}
		}

        return *this;
    }