当前位置: 首页>>代码示例>>C++>>正文


C++ bf_read::ReadBits方法代码示例

本文整理汇总了C++中bf_read::ReadBits方法的典型用法代码示例。如果您正苦于以下问题:C++ bf_read::ReadBits方法的具体用法?C++ bf_read::ReadBits怎么用?C++ bf_read::ReadBits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bf_read的用法示例。


在下文中一共展示了bf_read::ReadBits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ParseUpdate

//-----------------------------------------------------------------------------
// Purpose: Parse string update
//-----------------------------------------------------------------------------
void CNetworkStringTable::ParseUpdate( bf_read &buf, int entries )
{
	int lastEntry = -1;

	CUtlVector< StringHistoryEntry > history;

	for (int i=0; i<entries; i++)
	{
		int entryIndex = lastEntry + 1;

		if ( !buf.ReadOneBit() )
		{
			entryIndex = buf.ReadUBitLong( GetEntryBits() );
		}

		lastEntry = entryIndex;
		
		if ( entryIndex < 0 || entryIndex >= GetMaxStrings() )
		{
			Host_Error( "Server sent bogus string index %i for table %s\n", entryIndex, GetTableName() );
		}

		const char *pEntry = NULL;
		char entry[ 1024 ]; 
		char substr[ 1024 ];

		if ( buf.ReadOneBit() )
		{
			bool substringcheck = buf.ReadOneBit() ? true : false;

			if ( substringcheck )
			{
				int index = buf.ReadUBitLong( 5 );
				int bytestocopy = buf.ReadUBitLong( SUBSTRING_BITS );
				Q_strncpy( entry, history[ index ].string, bytestocopy + 1 );
				buf.ReadString( substr, sizeof(substr) );
				Q_strncat( entry, substr, sizeof(entry), COPY_ALL_CHARACTERS );
			}
			else
			{
				buf.ReadString( entry, sizeof( entry ) );
			}

			pEntry = entry;
		}
		
		// Read in the user data.
		unsigned char tempbuf[ CNetworkStringTableItem::MAX_USERDATA_SIZE ];
		memset( tempbuf, 0, sizeof( tempbuf ) );
		const void *pUserData = NULL;
		int nBytes = 0;

		if ( buf.ReadOneBit() )
		{
			if ( IsUserDataFixedSize() )
			{
				// Don't need to read length, it's fixed length and the length was networked down already.
				nBytes = GetUserDataSize();
				Assert( nBytes > 0 );
				tempbuf[nBytes-1] = 0; // be safe, clear last byte
				buf.ReadBits( tempbuf, GetUserDataSizeBits() );
			}
			else
			{
				nBytes = buf.ReadUBitLong( CNetworkStringTableItem::MAX_USERDATA_BITS );
				ErrorIfNot( nBytes <= sizeof( tempbuf ),
					("CNetworkStringTableClient::ParseUpdate: message too large (%d bytes).", nBytes)
				);

				buf.ReadBytes( tempbuf, nBytes );
			}

			pUserData = tempbuf;
		}

		// Check if we are updating an old entry or adding a new one
		if ( entryIndex < GetNumStrings() )
		{
			SetStringUserData( entryIndex, nBytes, pUserData );
#ifdef _DEBUG
			if ( pEntry )
			{
				Assert( !Q_strcmp( pEntry, GetString( entryIndex ) ) ); // make sure string didn't change
			}
#endif
			pEntry = GetString( entryIndex ); // string didn't change
		}
		else
		{
			// Grow the table (entryindex must be the next empty slot)
			Assert( (entryIndex == GetNumStrings()) && (pEntry != NULL) );
				
			if ( pEntry == NULL )
			{
				Msg("CNetworkStringTable::ParseUpdate: NULL pEntry, table %s, index %i\n", GetTableName(), entryIndex );
				pEntry = "";// avoid crash because of NULL strings
			}
//.........这里部分代码省略.........
开发者ID:Axitonium,项目名称:SourceEngine2007,代码行数:101,代码来源:networkstringtable.cpp

示例2: HandleMessage


//.........这里部分代码省略.........

		char name[500];
		msg.ReadString(name, sizeof(name));

		short maxentries = msg.ReadWord();

		unsigned int size = (int)(log2(maxentries) + 1);
		int entries = msg.ReadUBitLong(size);

		int bits = msg.ReadVarInt32();
		int userdata = msg.ReadOneBit();

		//if (m_bUserDataFixedSize)
		//{
		//	buffer.WriteUBitLong(m_nUserDataSize, 12);
		//	buffer.WriteUBitLong(m_nUserDataSizeBits, 4);
		//}

		if (userdata == 1)
		{
			int userdatasize = msg.ReadUBitLong(12);

			int userdatabits = msg.ReadUBitLong(4);
		}

		int compressed = msg.ReadOneBit();

		if (bits < 1) return true;

		unsigned int sz = (bits / 8) + 2;

		unsigned char* data = new unsigned char[sz*8]; //TODO: why is 8x the space required. (heap corruption otherwise)

		msg.ReadBits(data, bits);
		bool really_compressed = false;
		unsigned int actual_size;
		CLZSS s;
		printf("\n");
		{
			unsigned int remaining = sz;
			unsigned char* ptr = data;
			
			ptr += + 8; // unknown data

			remaining -= 8;
			really_compressed = s.IsCompressed(ptr);
			actual_size = really_compressed?s.GetActualSize(ptr):0;
			if (really_compressed) {
				unsigned char* data_dec = new unsigned char[actual_size];

				s.Uncompress(ptr, data_dec);

				// probably reuses the substring system used by old stringtable implementation. Shift the data by a bit or two to see the first entry of modelprecache for example.
				hexdump(data_dec, actual_size);

				delete[] data_dec;
				printf("\n");
			}
		}

		hexdump(data, bits / 8);
		

		delete[] data;

开发者ID:Python1320,项目名称:source1_client,代码行数:65,代码来源:leyfakeclient.cpp


注:本文中的bf_read::ReadBits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。