protected override int GetBodyLengthFromHeader(IBufferStream stream, int size)
        {
            var reader = new BinaryReader(stream.GetCurrentStream());
            var pSize  = reader.ReadInt32();

            return(pSize - DouyuPackageInfo.HeaderSize);
        }
        public override DouyuPackageInfo ResolvePackage(IBufferStream stream)
        {
            var reader  = new BinaryReader(stream.GetCurrentStream());
            var buffer  = reader.ReadBytes((int)stream.Length);
            var package = new DouyuPackageInfo();

            package.Decode(buffer);

            return(package);
        }
Exemplo n.º 3
0
        //public override BinaryRequestInfo ResolvePackage(IBufferStream bufferStream)
        //{
        //    //bufferStream.
        //    //bufferStream.

        //    byte[] b = new byte[bufferStream.Length];
        //    bufferStream.Read(b, 0, b.Length);
        //    //string content = Encoding.UTF8.GetString(b);
        //    var model = b.BytesToObject<DataPackage>();
        //    return new BinaryRequestInfo(model.Name, model.Other, null);
        //    //return base.ResolvePackage(bufferStream);
        //}

        // other code you need implement according yoru protocol details
        public override CommonRequestInfo ResolvePackage(IBufferStream bufferStream)
        {
            //var info = new CommonRequestInfo();
            var stream = bufferStream.GetCurrentStream();

            byte[] content = new byte[stream.Length];
            stream.Read(content, 0, (int)stream.Length);

            byte[] ary = new byte[stream.Length - HeaderSize];
            Array.Copy(content, HeaderSize, ary, 0, ary.Length);
            //stream.Read(ary, 0, (int)stream.Length - 8);
            //var package= ary.BytesToStruct<DataPackage>();
            //info.Body = package.Body;
            //info.Key = package.Name;
            //info.Length = package.Length;
            //info.Total = package.Total;
            var info = new CommonRequestInfo(content);

            return(info.IsValid ? info : null);

            //return new CommonRequestInfo(Encoding.UTF8.GetString(header.Array, header.Offset, 4), bodyBuffer.CloneRange(offset, length));
        }