g_cmdpacket.h

来自「PC网络游戏的编程」· C头文件 代码 · 共 66 行

H
66
字号
/*
g_CmdPacket.h: interface for the CG_CmdPacket class.
*/

#ifndef __CG_CMD_PACKET_H__
#define __CG_CMD_PACKET_H__

#include "g_platform.h"

/* define default packet buffer size */
const int DEFAULT_CMD_PACKET_SIZE = 1024;
/* define max packet buffer size */
const int MAX_CMD_PACKET_SIZE	  = 1024 * 16;

/* define some length used in packet class */
const int BYTE_SIZE  = 1;
const int LONG_SIZE  = 4;
const int SHORT_SIZE = 2;
const int FLOAT_SIZE = 4;

class CG_CmdPacket  
{
public:
	CG_CmdPacket();
	virtual ~CG_CmdPacket();

	void BeginWrite();
	void BeginRead(char *p,int len);
	void BeginRead();

	bool ReadBinary(char **data,int *len);
	bool ReadString(char **str);
	bool ReadFloat(float *f);
	bool ReadLong(long *l);
	bool ReadShort(short *s);
	bool ReadByte(char *c);
	
	bool WriteBinary(char *data,int len);
	bool WriteString(char *str);
	bool WriteFloat(float f);
	bool WriteLong(long l);
	bool WriteShort(short s);
	bool WriteByte(char c);
	
	char *GetData();
	int   GetDataSize();
	int   GetMaxSize();
	
	bool  SetSize(int len);
	bool  CloneFrom(CG_CmdPacket *packet);

private :
	bool  CopyData(char *buf,int len);
	bool  WriteData(void *data,int len);
	bool  ReadData(void *data,int len);
		
	char *m_pData;
	char *m_pReadData;
	int   m_nLen;
	int   m_nReadOffset;
	int   m_nWriteOffset;
	int   m_nMaxSize; 
};

#endif
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?