示例#1
0
 protected override void Dispose(bool disposing)
 {
     if (_ReadBuffer != null)
     {
         _ReadBuffer.Dispose();
         _ReadBuffer = null;
     }
 }
示例#2
0
        protected void FireReceiveBlock(NativeBufferStream buffer, int size, uint type, uint flags, uint seq, uint sseq)
        {
#if DEBUG_PERSIST_CONNECT
            PlatDependant.LogInfo(string.Format("Data Received, length {0}, type {1}, flags {2:x}, seq {3}, sseq {4}. (from {5})", size, type, flags, seq, sseq, this.GetType().Name));
#endif
            //buffer.Seek(0, SeekOrigin.Begin);
            OnReceiveBlock(buffer, size, type, flags, seq, sseq);
        }
 protected void OnReceiveBlock(NativeBufferStream buffer, int size, uint type, uint flags, uint seq, uint sseq)
 {
     _LastReceiveTick = System.Environment.TickCount;
     if (buffer != null && size >= 0 && size <= buffer.Length)
     {
         var processors = _SerConfig.PostProcessors;
         for (int i = processors.Count - 1; i >= 0; --i)
         {
             var processor = processors[i];
             var pack      = processor.Deprocess(buffer, 0, size, flags, type, seq, sseq, _IsServer);
             flags = pack.t1;
             size  = Math.Max(Math.Min(pack.t2, size), 0);
         }
         _PendingRead.Type = type;
         _PendingRead.Obj  = _SerConfig.ReaderWriter.Read(type, buffer, 0, size);
         _PendingRead.Seq  = seq;
         _PendingRead.SSeq = sseq;
     }
 }
示例#4
0
 public override object Read(uint type, NativeBufferStream buffer, int offset, int cnt)
 {
     Google.Protobuf.MessageParser parser;
     DataParsers.TryGetValue(type, out parser);
     if (parser != null)
     {
         try
         {
             buffer.Seek(offset, SeekOrigin.Begin);
             buffer.SetLength(offset + cnt);
             var rv = parser.ParseFrom(buffer);
             return(rv);
         }
         catch (Exception e)
         {
             PlatDependant.LogError(e);
         }
     }
     return(null);
 }
示例#5
0
        public void Write(NativeBufferStream buffer, int offset, int count)
        {
            if (_Con != null)
            {
                buffer.Seek(0, SeekOrigin.Begin);
                int cntwrote = 0;
                while (cntwrote < count)
                {
                    var sbuffer = BufferPool.GetBufferFromPool();
                    int scnt    = count - cntwrote;
                    if (sbuffer.Length < scnt)
                    {
                        scnt = sbuffer.Length;
                    }
                    buffer.Read(sbuffer, 0, scnt);
                    _Con.Send(sbuffer, scnt);

                    cntwrote += scnt;
                }
            }
        }
示例#6
0
 public override NativeBufferStream Write(object data)
 {
     Google.Protobuf.IMessage message = data as Google.Protobuf.IMessage;
     if (message != null)
     {
         var ostream = CodedStream;
         var stream  = ostream.OutputStream as NativeBufferStream;
         if (stream == null)
         {
             stream = new NativeBufferStream();
         }
         else
         {
             stream.Clear();
         }
         ostream.Reinit(stream);
         message.WriteTo(ostream);
         ostream.Flush();
         return(stream);
     }
     return(null);
 }
示例#7
0
 public override void PrepareBlock(NativeBufferStream data, uint type, uint flags, uint seq, uint sseq)
 {
     if (data != null)
     {
         var size        = data.Count;
         var codedstream = GetCodedOutputStream();
         codedstream.Reinit(data);
         data.InsertMode = true;
         data.Seek(0, SeekOrigin.Begin);
         codedstream.WriteTag(1, Google.Protobuf.WireFormat.WireType.Varint);
         codedstream.WriteUInt32(type);
         codedstream.WriteTag(2, Google.Protobuf.WireFormat.WireType.Varint);
         codedstream.WriteUInt32(flags);
         codedstream.WriteTag(3, Google.Protobuf.WireFormat.WireType.Varint);
         codedstream.WriteUInt32(seq);
         codedstream.WriteTag(4, Google.Protobuf.WireFormat.WireType.Varint);
         codedstream.WriteUInt32(sseq);
         codedstream.WriteTag(5, Google.Protobuf.WireFormat.WireType.LengthDelimited);
         codedstream.WriteLength(size);
         codedstream.Flush();
         ReturnCodedOutputStream(codedstream);
     }
 }
示例#8
0
 public abstract object Read(uint type, NativeBufferStream buffer, int offset, int cnt);
示例#9
0
 public virtual Pack <uint, int> Deprocess(NativeBufferStream data, int offset, int cnt, uint flags, uint type, uint seq, uint sseq, bool isServer)
 {
     return(new Pack <uint, int>(flags, cnt));
 }
示例#10
0
 public virtual uint Process(NativeBufferStream data, int offset, uint flags, uint type, uint seq, uint sseq, bool isServer)
 {
     return(flags);
 }
示例#11
0
 public abstract void PrepareBlock(NativeBufferStream data, uint type, uint flags, uint seq, uint sseq);