public bool readArchiveFileHeader(FileStream fileHandle, ByteBuffer pMByteBuffer) { pMByteBuffer.clear (); fileHandle.Read(pMByteBuffer.dynBuff.buff, 0, 4); pMByteBuffer.length = 4; string magic = ""; pMByteBuffer.readMultiByte(ref magic, 4, Encoding.UTF8); if (magic != "asdf") // 检查 magic { return false; } pMByteBuffer.clear (); fileHandle.Read(pMByteBuffer.dynBuff.buff, 0, (int)calcArchiveHeaderSizeNoFileHeader() - 4); pMByteBuffer.length = calcArchiveHeaderSizeNoFileHeader() - 4; // 读取 endian pMByteBuffer.readUnsignedInt8(ref m_endian); pMByteBuffer.setEndian((Endian)m_endian); // 读取头部大小 pMByteBuffer.readUnsignedInt32(ref m_headerSize); // 读取版本 pMByteBuffer.readUnsignedInt32(ref m_version); // 读取文件数量 pMByteBuffer.readUnsignedInt32(ref m_fileCount); // 读取整个头 pMByteBuffer.clear (); fileHandle.Read(pMByteBuffer.dynBuff.buff, 0, (int)(m_headerSize - calcArchiveHeaderSizeNoFileHeader())); pMByteBuffer.length = m_headerSize - calcArchiveHeaderSizeNoFileHeader (); return true; }
public void testZipMsg() { byte[] outBytes = null; uint outSize = 0; byte[] inBytes = null; uint inSize = 0; ByteBuffer pByteBuffer = new ByteBuffer(); UnitTestStrCmd pUnitTestCmd = new UnitTestStrCmd(); // 发送第一个数据包 pUnitTestCmd.testStr = "测试数据"; pByteBuffer.clear(); pUnitTestCmd.serialize(pByteBuffer); Compress.CompressData(pByteBuffer.dynBuff.buff, 0, pByteBuffer.length, ref outBytes, ref outSize); Compress.DecompressData(outBytes, 0, outSize, ref inBytes, ref inSize); pByteBuffer.clear(); pByteBuffer.writeBytes(inBytes, 0, inSize); pByteBuffer.position = 0; pUnitTestCmd.derialize(pByteBuffer); UAssert.DebugAssert(pUnitTestCmd.testStr != "测试数据"); }
public bool readArchiveFileHeader(FileStream fileHandle, ByteBuffer pMByteBuffer) { pMByteBuffer.clear(); fileHandle.Read(pMByteBuffer.dynBuff.buff, 0, 4); pMByteBuffer.length = 4; string magic = ""; pMByteBuffer.readMultiByte(ref magic, 4, Encoding.UTF8); if (magic != "asdf") // 检查 magic { return(false); } pMByteBuffer.clear(); fileHandle.Read(pMByteBuffer.dynBuff.buff, 0, (int)calcArchiveHeaderSizeNoFileHeader() - 4); pMByteBuffer.length = calcArchiveHeaderSizeNoFileHeader() - 4; // 读取 endian pMByteBuffer.readUnsignedInt8(ref m_endian); pMByteBuffer.setEndian((Endian)m_endian); // 读取头部大小 pMByteBuffer.readUnsignedInt32(ref m_headerSize); // 读取版本 pMByteBuffer.readUnsignedInt32(ref m_version); // 读取文件数量 pMByteBuffer.readUnsignedInt32(ref m_fileCount); // 读取整个头 pMByteBuffer.clear(); fileHandle.Read(pMByteBuffer.dynBuff.buff, 0, (int)(m_headerSize - calcArchiveHeaderSizeNoFileHeader())); pMByteBuffer.length = m_headerSize - calcArchiveHeaderSizeNoFileHeader(); return(true); }
// 加载一个表完成 public void onLoadEventHandle(IDispatchObject dispObj) { m_res = dispObj as ResItem; if (m_res.refCountResLoadResultNotify.resLoadState.hasSuccessLoaded()) { Ctx.m_instance.m_logSys.debugLog_1(LangItemID.eItem0, m_res.GetPath()); byte[] bytes = m_res.getBytes(""); if (bytes != null) { m_byteArray = Ctx.m_instance.m_factoryBuild.buildByteBuffer(); m_byteArray.clear(); m_byteArray.writeBytes(bytes, 0, (uint)bytes.Length); m_byteArray.setPos(0); readTable(getTableIDByPath(m_res.GetPath()), m_byteArray); } } else if (m_res.refCountResLoadResultNotify.resLoadState.hasFailed()) { Ctx.m_instance.m_logSys.debugLog_1(LangItemID.eItem1, m_res.GetPath()); } // 卸载资源 Ctx.m_instance.m_resLoadMgr.unload(m_res.GetPath(), onLoadEventHandle); }
// 仅仅是获取数据,并不删除 public void frontBA(ByteBuffer bytearray, uint len) { bytearray.clear(); // 设置数据为初始值 if (m_dynBuffer.m_size >= len) // 头部占据 4 个字节 { if (isLinearized()) // 在一段连续的内存 { bytearray.writeBytes(m_dynBuffer.m_buff, m_first, len); } else if (m_dynBuffer.m_iCapacity - m_first >= len) { bytearray.writeBytes(m_dynBuffer.m_buff, m_first, len); } else { bytearray.writeBytes(m_dynBuffer.m_buff, m_first, m_dynBuffer.m_iCapacity - m_first); bytearray.writeBytes(m_dynBuffer.m_buff, 0, len - (m_dynBuffer.m_iCapacity - m_first)); } } bytearray.position = 0; // 设置数据读取起始位置 }
protected void testMsgBuffer() { ClientBuffer pDataBuffer = new ClientBuffer(); UnitTestStrCmd pUnitTestCmd = new UnitTestStrCmd(); UnitTestNumCmd pUnitTesNumtCmd = new UnitTestNumCmd(); // 发送第一个数据包 pUnitTestCmd.testStr = "测试数据"; pDataBuffer.sendData.clear(); pUnitTestCmd.serialize(pDataBuffer.sendData); //pDataBuffer.sendData.position = 0; //pUnitTestCmd.derialize(pDataBuffer.sendData); pDataBuffer.send(); // 发送第二个数据包 pUnitTestCmd.testStr = "成功返回"; pDataBuffer.sendData.clear(); pUnitTestCmd.serialize(pDataBuffer.sendData); pDataBuffer.send(); // 发送第三个数据包 pUnitTesNumtCmd = new UnitTestNumCmd(); pUnitTesNumtCmd.num = 2001; pDataBuffer.sendData.clear(); pUnitTesNumtCmd.serialize(pDataBuffer.sendData); pDataBuffer.send(); pDataBuffer.getSocketSendData(); ByteBuffer cryptLenBA = new ByteBuffer(); cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length); pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA); // 自己补上消息头 pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer); // 直接放到接收原始消息缓冲区 pDataBuffer.moveRaw2Msg(); ByteBuffer bu; bu = pDataBuffer.getMsg(); UAssert.DebugAssert(bu != null); pUnitTestCmd.derialize(bu); UAssert.DebugAssert(pUnitTestCmd.testStr.Substring(0, 4) == "测试数据"); pDataBuffer.getSocketSendData(); if (pDataBuffer.sendBuffer.length > 0) { cryptLenBA.clear(); cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length); pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA); // 自己补上消息头 pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer); // 直接放到接收原始消息缓冲区 pDataBuffer.moveRaw2Msg(); } bu = pDataBuffer.getMsg(); UAssert.DebugAssert(bu != null); pUnitTestCmd.derialize(bu); UAssert.DebugAssert(pUnitTestCmd.testStr.Substring(0, 4) == "成功返回"); pDataBuffer.getSocketSendData(); if (pDataBuffer.sendBuffer.length > 0) { cryptLenBA.clear(); cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length); pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA); // 自己补上消息头 pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer); // 直接放到接收原始消息缓冲区 pDataBuffer.moveRaw2Msg(); } bu = pDataBuffer.getMsg(); UAssert.DebugAssert(bu != null); pUnitTesNumtCmd.derialize(bu); UAssert.DebugAssert(pUnitTesNumtCmd.num == 2001); Ctx.m_instance.m_netDispList.clearOneRevMsg(); Ctx.m_instance.m_netDispList.clearOneHandleMsg(); }
// 仅仅是获取数据,并不删除 public void frontBA(ByteBuffer bytearray, uint len) { bytearray.clear(); // 设置数据为初始值 if (m_dynBuffer.m_size >= len) // 头部占据 4 个字节 { if (isLinearized()) // 在一段连续的内存 { bytearray.writeBytes(m_dynBuffer.m_buff, m_first, len); } else if (m_dynBuffer.m_iCapacity - m_first >= len) { bytearray.writeBytes(m_dynBuffer.m_buff, m_first, len); } else { bytearray.writeBytes(m_dynBuffer.m_buff, m_first, m_dynBuffer.m_iCapacity - m_first); bytearray.writeBytes(m_dynBuffer.m_buff, 0, len - (m_dynBuffer.m_iCapacity - m_first)); } } bytearray.position = 0; // 设置数据读取起始位置 }
// 加载一个表完成 public void onLoadEventHandle(IDispatchObject dispObj) { m_res = dispObj as ResItem; if (m_res.refCountResLoadResultNotify.resLoadState.hasSuccessLoaded()) { Ctx.m_instance.m_logSys.debugLog_1(LangItemID.eItem0, m_res.GetPath()); byte[] bytes = m_res.getBytes(""); if (bytes != null) { m_byteArray = Ctx.m_instance.m_factoryBuild.buildByteBuffer(); m_byteArray.clear(); m_byteArray.writeBytes(bytes, 0, (uint)bytes.Length); m_byteArray.setPos(0); readTable(getTableIDByPath(m_res.GetPath()), m_byteArray); } } else if (m_res.refCountResLoadResultNotify.resLoadState.hasFailed()) { Ctx.m_instance.m_logSys.debugLog_1(LangItemID.eItem1, m_res.GetPath()); } // 卸载资源 Ctx.m_instance.m_resLoadMgr.unload(m_res.GetPath(), onLoadEventHandle); }