⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gblob.h

📁 一个非常有用的开源代码
💻 H
字号:
/*	Copyright (C) 2006, Mike Gashler	This library is free software; you can redistribute it and/or	modify it under the terms of the GNU Lesser General Public	License as published by the Free Software Foundation; either	version 2.1 of the License, or (at your option) any later version.	see http://www.gnu.org/copyleft/lesser.html*/#ifndef __GBLOB_H__#define __GBLOB_H__#include <string.h>#include "GMacros.h"// This class is for serializing and deserializing objects. It takes care of// Endianness issues and protects against buffer overruns. This class would// be particularly useful for writing a network protocol.class GBlob{protected:	int m_nInBufferSize;	int m_nOutBufferSize;	int m_nInBufferPos;	int m_nOutBufferPos;	unsigned char* m_pInBuffer;	unsigned char* m_pOutBuffer;	bool m_bDeleteInBuffer;	bool m_bOkToResizeOutBuffer;public:	GBlob(int nOutBufferSize, bool bOkToResizeOutBuffer);	~GBlob();	void ResetOutBuffer() { m_nOutBufferPos = 0; }	void ResetInBuffer() { m_nInBufferPos = 0; }	unsigned char* GetOutBlob() { return m_pOutBuffer; }	int GetOutBlobSize() { return m_nOutBufferPos; }	int GetInBlobSize() { return m_nInBufferSize; }	void SetInBuffer(unsigned char* pInBuffer, int nSize, bool bDeleteBuffer);	// Pushes a blob into the output blob	void Push(const unsigned char* pData, int nSize);	// Pushes a wide char into the output blob	void Push(const wchar_t wc);	// Pushes a char into the output blob	void Push(const char c);	// Pushes an int into the output blob	void Push(const int n);	// Pushes an unsigned int into the output blob	void Push(const unsigned int n);	// Pushes an unsigned char into the output blob	void Push(const unsigned char uc);	// Pushes a float into the output blob	void Push(const float f);	// Pushes a double into the output blob	void Push(const double d);	// Pushes a null-terminated string into the output blob	void Push(const char* szString);	// Pops a blob from the input buffer	void Pop(unsigned char* pData, int nSize);	// Pops a single wide char from the input buffer	void Pop(wchar_t* pwc);	// Pops a single char from the input buffer	void Pop(char* pc);	// Pops an int from the input buffer	void Pop(int* pn);	// Pops an unsigned int from the input buffer	void Pop(unsigned int* pui);	// Pops an unsigned char from the input buffer	void Pop(unsigned char* puc);	// Pops a float from the input buffer	void Pop(float* pf);	// Pops a double from the input buffer	void Pop(double* pd);	// This allocates a char[] buffer of the appropriate size and fills it with	// a null-terminated string popped from the buffer.	void Pop(char** pszString);	// Retrieves bytes from within the input buffer	void Peek(int nIndex, unsigned char* pData, int nSize);	// Puts bytes into the output buffer (overwriting existing data)	void Poke(int nIndex, const unsigned char* pData, int nSize);	// Puts an int into the output buffer (overwriting existing data)	void Poke(int nIndex, const int n);protected:	void ResizeOutBuffer(int nRequiredSize);};#endif // __GBLOB_H__

⌨️ 快捷键说明

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