1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using SuperSocket.ProtoBase;
- using System.Collections.Generic;
- using System;
- using System.Text;
- namespace ET.Server
- {
- [ChildOf(typeof(FastStreamComponent))]
- public class FastStreamMessageDecoder : FixedHeaderReceiveFilter<FastStreamBuffer>
- {
- public const int LEN_HEAD = 5;
- private int uidLen;
- private int msgLen;
- public FastStreamMessageDecoder(int headerSize) : base(headerSize)
- {
- }
- public override FastStreamBuffer ResolvePackage(IBufferStream bufferStream)
- {
- bufferStream.Skip(LEN_HEAD);
- var uid = bufferStream.ReadString(uidLen, Encoding.UTF8);
- var data = new byte[msgLen];
- bufferStream.Read(data, 0, msgLen);
- return new FastStreamBuffer(Convert.ToUInt64(uid, 10), ref data);
- }
- protected override int GetBodyLengthFromHeader(IBufferStream buffer, int headerSize)
- {
- uidLen = buffer.ReadByte();
- msgLen = (int)buffer.ReadUInt32(true);
- return uidLen + msgLen;
- }
- }
- public class FastStreamBuffer : IPackageInfo<ulong>
- {
- public ulong Key { get; private set; }
- public byte[] Data;
- public FastStreamBuffer(ulong key, ref byte[] data)
- {
- this.Key = key;
- this.Data = data;
- }
- }
- }
|