ReadShortAsync() public method

Reads the short async.
public ReadShortAsync ( ) : Task
return Task
コード例 #1
0
ファイル: ResultFrame.cs プロジェクト: reuzel/CqlSharp
        /// <summary>
        /// Reads the CqlType
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>a CqlType</returns>
        private static async Task<CqlType> ReadCqlType(FrameReader reader)
        {
            //read typeCode
            var colType = (CqlTypeCode)await reader.ReadShortAsync().AutoConfigureAwait();
            CqlType type;
            switch(colType)
            {
                case CqlTypeCode.Custom:
                    var colCustom = await reader.ReadStringAsync().AutoConfigureAwait();
                    type = CqlType.CreateType(colCustom);
                    break;

                case CqlTypeCode.List:
                case CqlTypeCode.Set:
                    var colValueType = await ReadCqlType(reader).AutoConfigureAwait();
                    type = CqlType.CreateType(colType, colValueType);
                    break;

                case CqlTypeCode.Map:
                    var colKeyType = await ReadCqlType(reader).AutoConfigureAwait();
                    var colValType = await ReadCqlType(reader).AutoConfigureAwait();
                    type = CqlType.CreateType(colType, colKeyType, colValType);
                    break;

                case CqlTypeCode.UserDefinedType:
                    var keyspace = await reader.ReadStringAsync().AutoConfigureAwait();
                    var name = await reader.ReadStringAsync().AutoConfigureAwait();
                    var fieldCount = await reader.ReadShortAsync().AutoConfigureAwait();
                    var fieldNames = new List<string>(fieldCount);
                    var fieldTypes = new List<CqlType>(fieldCount);
                    for(int i = 0; i < fieldCount; i++)
                    {
                        fieldNames.Add(await reader.ReadStringAsync().AutoConfigureAwait());
                        fieldTypes.Add(await ReadCqlType(reader).AutoConfigureAwait());
                    }

                    type = CqlType.CreateType(colType, keyspace, name, fieldNames, fieldTypes);
                    break;

                case CqlTypeCode.Tuple:
                    var tupleItems = await reader.ReadShortAsync().AutoConfigureAwait();
                    var tupleItemTypes = new object[tupleItems];
                    for(int i = 0; i < tupleItems; i++)
                    {
                        tupleItemTypes[i] = await ReadCqlType(reader).AutoConfigureAwait();
                    }

                    type = CqlType.CreateType(colType, tupleItemTypes);
                    break;

                default:
                    type = CqlType.CreateType(colType);
                    break;
            }
            return type;
        }
コード例 #2
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;
            }
        }
コード例 #3
0
ファイル: ResultFrame.cs プロジェクト: priyaparul/CqlSharp
        internal async Task <CqlSchema> ReadCqlSchemaAsync()
        {
            FrameReader reader = Reader;
            var         flags  = (MetadataFlags)await reader.ReadIntAsync().ConfigureAwait(false);

            bool globalTablesSpec = 0 != (flags & MetadataFlags.GlobalTablesSpec);

            int colCount = await reader.ReadIntAsync().ConfigureAwait(false);

            string keyspace = null;
            string table    = null;

            if (globalTablesSpec)
            {
                keyspace = await reader.ReadStringAsync().ConfigureAwait(false);

                table = await reader.ReadStringAsync().ConfigureAwait(false);
            }

            var columnSpecs = new List <CqlColumn>(colCount);

            for (int colIdx = 0; colIdx < colCount; ++colIdx)
            {
                string colKeyspace = keyspace;
                string colTable    = table;
                if (!globalTablesSpec)
                {
                    colKeyspace = await reader.ReadStringAsync().ConfigureAwait(false);

                    colTable = await reader.ReadStringAsync().ConfigureAwait(false);
                }
                string colName = await reader.ReadStringAsync().ConfigureAwait(false);

                var colType = (CqlType)await reader.ReadShortAsync().ConfigureAwait(false);

                string  colCustom    = null;
                CqlType?colKeyType   = null;
                CqlType?colValueType = null;
                switch (colType)
                {
                case CqlType.Custom:
                    colCustom = await reader.ReadStringAsync().ConfigureAwait(false);

                    break;

                case CqlType.List:
                case CqlType.Set:
                    colValueType = (CqlType)await reader.ReadShortAsync().ConfigureAwait(false);

                    break;

                case CqlType.Map:
                    colKeyType = (CqlType)await reader.ReadShortAsync().ConfigureAwait(false);

                    colValueType = (CqlType)await reader.ReadShortAsync().ConfigureAwait(false);

                    break;
                }

                columnSpecs.Add(new CqlColumn(colIdx, colKeyspace, colTable, colName, colType, colCustom,
                                              colKeyType, colValueType));
            }

            return(new CqlSchema(columnSpecs));
        }