头文件
#ifndef __MK_BYTE_BUFFER_H__
#define __MK_BYTE_BUFFER_H__
#include <iostream>
const int endian = 1;
#define is_bigendian() ((*(char*) &endian) == 0)
#define is_littlendbian() ((*(char*) &endian) == 1)
// size of data 1M
#define BUFF_SIZE_MAX 1024 * 1024
namespace MK
{
template<typename T> T ConvertDigitToNet(T v);
template<typename T> T ConvertNetToDigit(T v);
class ByteBuffer
{
private:
char *m_cBuffer;
size_t m_rpos;
size_t m_wpos;
size_t m_nSize;
public:
explicit ByteBuffer(size_t size = 0):m_rpos(0), m_wpos(0), m_nSize(size)
{ size_t nSize = size <= 0 ? BUFF_SIZE_MAX:size; m_cBuffer = new char[nSize];}
~ByteBuffer() { delete[] m_cBuffer; }
size_t readNet(int &v);
size_t readNet(short &v);
size_t read(int &v) { return read((char*)&v, 0, sizeof(int)); }
size_t read(char &v) { return read((char*)&v, 0, sizeof(cha