public void ProcessMessage()
        {
            while (_queue.Count > 0)
            {
                lock (_stream)
                {
                    //var binaryWriter = MyBinaryWriter.Allocate(_stream);
                    _stream.Position = 0;

                    NetworkMessageRecoder.RecodMessageItem item = (NetworkMessageRecoder.RecodMessageItem)_queue.Dequeue();
                    try
                    {
                        var serializeInfo = _messageTypeInfo.GetSerializeInfo(item.MessageType);
                        if (serializeInfo != null)
                        {
                            item.Write(serializeInfo, _stream, _fileAppender);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.ErrorFormat("NetworkMessageRecoder thread{0}", e);
                    }
                    finally
                    {
                        item.ReleaseReference();
                    }
                }
            }
        }
Пример #2
0
        public long Serialize(Stream outStream, int messageType, object message)
        {
            var info = _messageTypeInfo.GetSerializeInfo(messageType);

            if (info != null)
            {
                long start = outStream.Position;
                info.Serialize(outStream, message);
                info.Statistics.OnSerialize((int)(outStream.Position - start));
                return(outStream.Position - start);
            }
            else
            {
                _logger.ErrorFormat("don't know how to serialize messageType {0}, type {1}", messageType, message.GetType());
                return(0);
            }
        }
Пример #3
0
            public bool ReadFrom(BinaryFileReader filerReader, IMessageTypeInfo messageTypeInfo)
            {
                try
                {
                    var readerReader = filerReader.Reader;
                    Stage       = readerReader.ReadInt32();
                    ProcessSeq  = readerReader.ReadInt32();
                    ChannelId   = readerReader.ReadInt32();
                    MessageType = readerReader.ReadInt32();

                    int Lenght = readerReader.ReadInt32();
                    //_logger.InfoFormat("ReadFrom:{0}, {1} ,{2}",this, Lenght,filerReader.Offset);
                    VNetPacketMemSteam memoryStream = VNetPacketMemSteam.Allocate();
                    try
                    {
                        var b = readerReader.ReadBytes(Lenght);
                        memoryStream.Stream.Write(b, 0, b.Length);
                        memoryStream.Stream.Seek(0, SeekOrigin.Begin);
                        var serializeInfo = messageTypeInfo.GetSerializeInfo(MessageType);
                        if (serializeInfo != null)
                        {
                            try
                            {
                                MessageBody = serializeInfo.Deserialize(memoryStream.Stream);
                                return(true);
                            }
                            catch (Exception e)
                            {
                                _logger.ErrorFormat("{0} {1}", memoryStream.Stream.Position, e);
                            }
                        }
                    }
                    finally
                    {
                        memoryStream.ReleaseReference();
                    }
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("{0}", e);
                }

                return(false);
            }