Esempio n. 1
0
        public MCPacket ReadPacket(Stream stream, MCFunction requestFunction)
        {
            var packet = new MCPacket();

            var source = this.CreateDataProcessor(stream);

            source.ForceBigEndian = true;
            var frameId = source.ReadUShort();

            source.ForceBigEndian = false;
            var frame     = MCFrame.Find(frameId);
            var direction = frame.GetDirection(frameId);

            var subHeader = MCSubHeader.Find(frame).CreateInstance();

            subHeader.Read(source);
            packet.SubHeader = subHeader;

            var qHeader = this.CreateQHeader(direction);

            qHeader.ReadPre(source);
            packet.QHeader = qHeader;

            ushort dataLength = (ushort)(source.ReadUShort() / source.LengthPerByte);
            var    data       = source.ReadBytes(dataLength);

            using (var ms = new MemoryStream(data))
            {
                var dataSource = this.CreateDataProcessor(ms);
                dataSource.IgnoreConvert = true;
                qHeader.ReadPost(dataSource);

                var function = this.CreateFucntion(requestFunction, direction, qHeader, dataSource);

                if (function != null)
                {
                    function.Read(dataSource);
                }

                packet.Function = function;
            }

            return(packet);
        }
 public MCSubHeaderRegistration(MCFrame frame, Type instanceType)
 {
     this.Frame        = frame;
     this.InstanceType = instanceType;
 }
Esempio n. 3
0
 public static MCSubHeaderRegistration Find(MCFrame frame)
 {
     FrameRegistrations.TryGetValue(frame, out var registration);
     return(registration);
 }