CqlSharp.Protocol.FrameReader.ReadByteAsync C# (CSharp) Method

ReadByteAsync() public method

Reads the byte async.
public ReadByteAsync ( ) : Task
return Task
        public Task<byte> ReadByteAsync()
        {
            if(TryGetSegmentFromBuffer(1))
            {
                byte b = _lastReadSegment.Array[_lastReadSegment.Offset];

                //return task from cache
                return b.AsTask();
            }

            //byte could not be obtained from cache, go the long route
            return ReadByteInternalAsync();
        }

Usage Example

示例#1
0
        protected override async Task InitializeAsync()
        {
            FrameReader stream = Reader;
            var         code   = (ErrorCode)await stream.ReadIntAsync().ConfigureAwait(false);

            string msg = await stream.ReadStringAsync().ConfigureAwait(false);

            switch (code)
            {
            case ErrorCode.Unavailable:
            {
                var cl = (CqlConsistency)await stream.ReadShortAsync().ConfigureAwait(false);

                int required = await stream.ReadIntAsync().ConfigureAwait(false);

                int alive = await stream.ReadIntAsync().ConfigureAwait(false);

                Exception = new UnavailableException(msg, cl, required, alive);
                break;
            }

            case ErrorCode.WriteTimeout:
            {
                var cl = (CqlConsistency)await stream.ReadShortAsync().ConfigureAwait(false);

                int received = await stream.ReadIntAsync().ConfigureAwait(false);

                int blockFor = await stream.ReadIntAsync().ConfigureAwait(false);

                string writeType = await stream.ReadStringAsync().ConfigureAwait(false);

                Exception = new WriteTimeOutException(msg, cl, received, blockFor, writeType);
                break;
            }

            case ErrorCode.ReadTimeout:
            {
                var cl = (CqlConsistency)await stream.ReadShortAsync().ConfigureAwait(false);

                int received = await stream.ReadIntAsync().ConfigureAwait(false);

                int blockFor = await stream.ReadIntAsync().ConfigureAwait(false);

                bool dataPresent = 0 != await stream.ReadByteAsync().ConfigureAwait(false);

                Exception = new ReadTimeOutException(msg, cl, received, blockFor, dataPresent);
                break;
            }

            case ErrorCode.Syntax:
                Exception = new SyntaxException(msg);
                break;

            case ErrorCode.Unauthorized:
                Exception = new UnauthorizedException(msg);
                break;

            case ErrorCode.Invalid:
                Exception = new InvalidException(msg);
                break;

            case ErrorCode.AlreadyExists:
                string keyspace = await stream.ReadStringAsync().ConfigureAwait(false);

                string table = await stream.ReadStringAsync().ConfigureAwait(false);

                Exception = new AlreadyExistsException(msg, keyspace, table);
                break;

            case ErrorCode.Unprepared:
                byte[] unknownId = await stream.ReadShortBytesAsync().ConfigureAwait(false);

                Exception = new UnpreparedException(msg, unknownId);
                break;

            default:
                Exception = new ProtocolException(code, msg);
                break;
            }
        }