<commit_before>#ifndef __NetStream_H__
#define __NetStream_H__

#ifdef WIN32
#include<Winsock2.h>
#else
#include <arpa/inet.h>
#endif // WIN32


enum ENetStreamType
{
	ENetStreamType_None,
	ENetStreamType_Read,
	ENetStreamType_Write,
};

class CNetStream
{
public:
	CNetStream(ENetStreamType eType, char* pData, unsigned int dwLen)
		:m_eType(eType)
		,m_pData(pData)
		,m_dwLen(dwLen)
	{
	}

	CNetStream(const char* pData, unsigned int dwLen)
		:m_eType(ENetStreamType_Read)
		,m_pData(const_cast<char*>(pData))
		,m_dwLen(dwLen)
	{
	}
	~CNetStream() {}

	unsigned int GetDataLength() { return m_dwLen; }

	char* ReadData(unsigned int dwLen)
	{
		assert(m_eType == ENetStreamType_Read);
		if (dwLen <= m_dwLen)
		{
			char* pTemp = m_pData;
			m_pData += dwLen;
			m_dwLen -= dwLen;
			return pTemp;
		}
		return NULL;
	}

	bool ReadByte(char& cData)
	{
		char* pData = ReadData(sizeof(cData));
		if (pData)
		{
			memcpy(&cData, pData, sizeof(cData));
			return true;
		}
		return false;
	}

	bool ReadByte(unsigned char& cData)
	{
		char* pData = ReadData(sizeof(cData));
		if (pData)
		{
			memcpy(&cData, pData, sizeof(cData));
			return true;
		}
		return false;
	}

	bool ReadShort(short& wData)
	{
		char* pData = ReadData(sizeof(wData));
		if (pData)
		{
			memcpy(&wData, pData, sizeof(wData));
			wData = ntohs(wData);
			return true;
		}
		return false;
	}

	bool ReadShort(unsigned short& wData)
	{
		char* pData = ReadData(sizeof(wData));
		if (pData)
		{
			memcpy(&wData, pData, sizeof(wData));
			wData = ntohs(wData);
			return true;
		}
		return false;
	}

	bool ReadInt(int& dwData)
	{
		char* pData = ReadData(sizeof(dwData));
		if (pData)
		{
			memcpy(&dwData, pData, sizeof(dwData));
			dwData = ntohl(dwData);
			return true;
		}
		return false;
	}

	bool ReadInt(unsigned int& dwData)
	{
		char* pData = ReadData(sizeof(dwData));
		if (pData)
		{
			memcpy(&dwData, pData, sizeof(dwData));
			dwData = ntohl(dwData);
			return true;
		}
		return false;
	}

	bool ReadFloat(float& fData)
	{
		int dwFloat = 0;
		if (ReadInt(dwFloat))
		{
			fData = dwFloat / 256.0f;
			return true;
		}
		return false;
	}

	//ֻܻȡͷǶ ȡϢͷ //
	const char* GetData(unsigned int dwLen)
	{
		assert(m_eType == ENetStreamType_Read);
		if (dwLen <= m_dwLen)
		{
			return m_pData;
		}
		return NULL;
	}

	bool WriteData(char* pData, unsigned int dwLen)
	{
		assert(m_eType == ENetStreamType_Write);
		if (dwLen <= m_dwLen)
		{
			memcpy(m_pData, pData, dwLen);
			m_pData += dwLen;
			m_dwLen -= dwLen;
			return true;
		}<commit_msg>头文件包含<commit_after>#ifndef __NetStream_H__
#define __NetStream_H__

#ifdef WIN32
#include<Winsock2.h>
#else
#include <arpa/inet.h>
#endif // WIN32

#include <string.h>


enum ENetStreamType
{
	ENetStreamType_None,
	ENetStreamType_Read,
	ENetStreamType_Write,
};

class CNetStream
{
public:
	CNetStream(ENetStreamType eType, char* pData, unsigned int dwLen)
		:m_eType(eType)
		,m_pData(pData)
		,m_dwLen(dwLen)
	{
	}

	CNetStream(const char* pData, unsigned int dwLen)
		:m_eType(ENetStreamType_Read)
		,m_pData(const_cast<char*>(pData))
		,m_dwLen(dwLen)
	{
	}
	~CNetStream() {}

	unsigned int GetDataLength() { return m_dwLen; }

	char* ReadData(unsigned int dwLen)
	{
		assert(m_eType == ENetStreamType_Read);
		if (dwLen <= m_dwLen)
		{
			char* pTemp = m_pData;
			m_pData += dwLen;
			m_dwLen -= dwLen;
			return pTemp;
		}
		return NULL;
	}

	bool ReadByte(char& cData)
	{
		char* pData = ReadData(sizeof(cData));
		if (pData)
		{
			memcpy(&cData, pData, sizeof(cData));
			return true;
		}
		return false;
	}

	bool ReadByte(unsigned char& cData)
	{
		char* pData = ReadData(sizeof(cData));
		if (pData)
		{
			memcpy(&cData, pData, sizeof(cData));
			return true;
		}
		return false;
	}

	bool ReadShort(short& wData)
	{
		char* pData = ReadData(sizeof(wData));
		if (pData)
		{
			memcpy(&wData, pData, sizeof(wData));
			wData = ntohs(wData);
			return true;
		}
		return false;
	}

	bool ReadShort(unsigned short& wData)
	{
		char* pData = ReadData(sizeof(wData));
		if (pData)
		{
			memcpy(&wData, pData, sizeof(wData));
			wData = ntohs(wData);
			return true;
		}
		return false;
	}

	bool ReadInt(int& dwData)
	{
		char* pData = ReadData(sizeof(dwData));
		if (pData)
		{
			memcpy(&dwData, pData, sizeof(dwData));
			dwData = ntohl(dwData);
			return true;
		}
		return false;
	}

	bool ReadInt(unsigned int& dwData)
	{
		char* pData = ReadData(sizeof(dwData));
		if (pData)
		{
			memcpy(&dwData, pData, sizeof(dwData));
			dwData = ntohl(dwData);
			return true;
		}
		return false;
	}

	bool ReadFloat(float& fData)
	{
		int dwFloat = 0;
		if (ReadInt(dwFloat))
		{
			fData = dwFloat / 256.0f;
			return true;
		}
		return false;
	}

	//ֻ�ܻ�ȡ��ͷ���Ƕ���� ������ȡ��Ϣͷ �������������//
	const char* GetData(unsigned int dwLen)
	{
		assert(m_eType == ENetStreamType_Read);
		if (dwLen <= m_dwLen)
		{
			return m_pData;
		}
		return NULL;
	}

	bool WriteData(char* pData, unsigned int dwLen)
	{
		assert(m_eType == ENetStreamType_Write);
		if (dwLen <= m_dwLen)
		{
			memcpy(m_pData, pData, dwLen);
			m_pData += dwLen;
			m_dwLen -= dwLen;
			return true;
		}
{'fraction_non_alphanumeric': 0.14120868374731077, 'fraction_numerical': 0.003911597887737141, 'mean_word_length': 3.6113615870153293, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2814462', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2180, 'n_words': 437}