示例#1
0
文件: Control.cs 项目: lulzzz/Port
        internal new static async ValueTask <ReadResult <Control> > TryReadAsync(
            IFrameReader frameReader,
            CancellationToken cancellation = default)
        {
            var version =
                (ushort)(await frameReader.ReadUShortAsync(cancellation)
                         .ConfigureAwait(false) & 0x7FFF);

            if (version != Version)
            {
                // todo: What stream id should be specified here?
                return(ReadResult <Control> .Error(RstStream.UnsupportedVersion(UInt31.From(0))));
            }

            var type = await frameReader.ReadUShortAsync(cancellation)
                       .ConfigureAwait(false);

            var flags = await frameReader.ReadByteAsync(cancellation)
                        .ConfigureAwait(false);

            var length = await frameReader.ReadUInt24Async(cancellation)
                         .ConfigureAwait(false);

            return(type switch
            {
                SynStream.Type => (await SynStream.TryReadAsync(
                                       flags, length, frameReader, cancellation)
                                   .ConfigureAwait(false)).AsControl(),
                SynReply.Type => (await SynReply.TryReadAsync(
                                      flags, length, frameReader, cancellation)
                                  .ConfigureAwait(false)).AsControl(),
                RstStream.Type => (await RstStream.TryReadAsync(
                                       flags, length, frameReader, cancellation)
                                   .ConfigureAwait(false)).AsControl(),
                Settings.Type => (await Settings.TryReadAsync(
                                      flags, length, frameReader, cancellation)
                                  .ConfigureAwait(false)).AsControl(),
                Ping.Type => (await Ping.TryReadAsync(
                                  flags, length, frameReader, cancellation)
                              .ConfigureAwait(false)).AsControl(),
                GoAway.Type => (await GoAway.TryReadAsync(
                                    flags, length, frameReader, cancellation)
                                .ConfigureAwait(false)).AsControl(),
                Headers.Type => (await Headers.TryReadAsync(
                                     flags, length, frameReader, cancellation)
                                 .ConfigureAwait(false)).AsControl(),
                WindowUpdate.Type => (await WindowUpdate.TryReadAsync(
                                          flags, length, frameReader, cancellation)
                                      .ConfigureAwait(false)).AsControl(),
                _ => throw new ArgumentOutOfRangeException(
                    nameof(type), $"Unknown control frame type {type} received")
            });
示例#2
0
文件: Data.cs 项目: lulzzz/Port
        internal new static async ValueTask <ReadResult <Data> > TryReadAsync(
            IFrameReader frameReader,
            CancellationToken cancellation = default)
        {
            // Since bit 31 is the control bit which is 0 for data frames,
            // there is no need to blank it out
            var streamId = UInt31.From(
                await frameReader.ReadUInt32Async(cancellation)
                .ConfigureAwait(false));
            var flags = await frameReader.ReadByteAsync(cancellation)
                        .ConfigureAwait(false);

            var length = await frameReader.ReadUInt24Async(cancellation)
                         .ConfigureAwait(false);

            var payload = await frameReader.ReadBytesAsync(
                (int)length.Value, cancellation)
                          .ConfigureAwait(false);

            return(ReadResult.Ok(new Data(streamId, flags.ToEnum <Options>(), payload)));
        }