private void Serialize(int messageID, MessageCompressType compressType, MessageCryptoType cryptoType, byte[] dataBytes) { byte[] bodyBytes = dataBytes; if (dataBytes != null && dataBytes.Length > 0) { bodyBytes = netHandler.CompressMessage(compressType, bodyBytes); bodyBytes = netHandler.EncodeMessage(cryptoType, bodyBytes); } int messageLen = sizeof(int) + sizeof(byte); if (bodyBytes != null && bodyBytes.Length > 0) { messageLen += sizeof(byte); messageLen += sizeof(byte); messageLen += bodyBytes.Length; } byte[] messageLenBytes = BitConverter.GetBytes(messageLen); sendingMessageStream.Write(messageLenBytes, 0, messageLenBytes.Length); byte[] messageIDBytes = BitConverter.GetBytes(messageID); sendingMessageStream.Write(messageIDBytes, 0, messageIDBytes.Length); sendingMessageStream.WriteByte(sendedMessageSeriousIndex); if (bodyBytes != null && bodyBytes.Length > 0) { sendingMessageStream.WriteByte((byte)compressType); sendingMessageStream.WriteByte((byte)cryptoType); sendingMessageStream.Write(bodyBytes, 0, bodyBytes.Length); } ++sendedMessageSeriousIndex; }