/// <summary> /// 消息发送时的内部方法,将逻辑结构体数据存放到ls中 /// 子类无需重载 /// </summary> public void SetByte <T>(T t, ref LusuoStream ls) { ls.WriteInt(0); // 预留总字节数 ls.WriteUShort(msgID); // 写消息编号 ls.WriteInt(eno); // 写eno byte[] bytes = ProtobufHelper.Serialize <T>(t); ls.Write(ref bytes); // 写具体结构体 ls.Seek(0); // 内容字节数 int contentLen = StringHelper.s_ShortSize + StringHelper.s_IntSize + bytes.Length; ls.WriteInt(contentLen); // 再次写内容长度 msgMaxLen = StringHelper.s_IntSize + contentLen; // 长度字节数 + 内容字节数 }
public void SendMessage <T>(ushort msgID, T t) { LusuoStream stream = new LusuoStream(new byte[m_uBufferSize]); stream.WriteInt(0); // 预留总字节数 stream.WriteUShort(msgID); // 写消息编号 stream.WriteInt(1); byte[] bytes = ProtobufHelper.Serialize <T>(t); stream.Write(ref bytes); // 写具体结构体 stream.Seek(0); // 内容字节数 int contentLen = StringHelper.s_ShortSize + StringHelper.s_IntSize + bytes.Length; stream.WriteInt(contentLen); // 再次写内容长度 stream.m_byteLen = StringHelper.s_IntSize + contentLen; // 长度字节数 + 内容字节数 _m_listMsg.Add(stream); }
private static bool ProcessCsvFile(DirectoryInfo folder) { DirectoryInfo[] dirInfo = folder.GetDirectories(); foreach (DirectoryInfo item in dirInfo) { if (item.Name.Contains(".svn")) { continue; } ProcessCsvFile(item); } FileInfo[] fileInfo = folder.GetFiles(); foreach (FileInfo item in fileInfo) { string postfix = ".csv"; int iPos = item.Name.IndexOf(postfix, 0); if (iPos != -1 && iPos + postfix.Length == item.Name.Length) { string csvName = item.Name.ToLower().Replace(".csv", ""); // 如果这个表没有写入到LogicSystem中,就不需要打包 if (CsvManager.Inst.GetType(csvName) == (int)eAllCSV.eAC_None) { Debug.LogWarning(item.Name + " 没有写入到LogicSystem中,是否为客户端不需要的表格?"); continue; } FileStream file; try { file = new FileStream(item.FullName, FileMode.Open); if (file == null) { Debug.LogError(item.Name + "处理失败。"); } } catch (IOException ioe) { Debug.LogError("处理csv失败,检查是否已经打开:" + item.FullName + " " + ioe); EditorUtility.DisplayDialog( "打包配置错误", "请关闭配置表,重新打包: " + item.FullName, "确定"); file = null; m_csvStream = null; return(false); } m_csvNums++; // 这里存csv的id效率更好 //m_csvStream.WriteString(ref csvName); int type = (int)CsvManager.Inst.GetType(csvName); m_csvStream.WriteInt(type); byte[] readData = new byte[file.Length]; file.Read(readData, 0, (int)file.Length); // 转码并写入到流 readData = Encoding.Convert(Encoding.Default, Encoding.UTF8, readData); m_csvStream.WriteInt((int)readData.Length); m_csvStream.Write(ref readData); Debug.Log("处理配置表:" + item.Name); } } return(true); }