private IColumnInfo GetColumnInfo(FrameReader reader, ColumnTypeCode code)
        {
            ColumnTypeCode innercode;

            switch (code)
            {
            case ColumnTypeCode.List:
                innercode = (ColumnTypeCode)reader.ReadUInt16();
                return(new ListColumnInfo
                {
                    ValueTypeCode = innercode,
                    ValueTypeInfo = GetColumnInfo(reader, innercode)
                });

            case ColumnTypeCode.Map:
                innercode = (ColumnTypeCode)reader.ReadUInt16();
                IColumnInfo kci        = GetColumnInfo(reader, innercode);
                var         vinnercode = (ColumnTypeCode)reader.ReadUInt16();
                IColumnInfo vci        = GetColumnInfo(reader, vinnercode);
                return(new MapColumnInfo
                {
                    KeyTypeCode = innercode,
                    KeyTypeInfo = kci,
                    ValueTypeCode = vinnercode,
                    ValueTypeInfo = vci
                });

            case ColumnTypeCode.Set:
                innercode = (ColumnTypeCode)reader.ReadUInt16();
                return(new SetColumnInfo
                {
                    KeyTypeCode = innercode,
                    KeyTypeInfo = GetColumnInfo(reader, innercode)
                });

            case ColumnTypeCode.Custom:
                return(new CustomColumnInfo {
                    CustomTypeName = reader.ReadString()
                });

            case ColumnTypeCode.Udt:
                var udtInfo     = new UdtColumnInfo(reader.ReadString() + "." + reader.ReadString());
                var fieldLength = reader.ReadInt16();
                for (var i = 0; i < fieldLength; i++)
                {
                    var dataType = new ColumnDesc
                    {
                        Name     = reader.ReadString(),
                        TypeCode = (ColumnTypeCode)reader.ReadUInt16(),
                    };

                    dataType.TypeInfo = GetColumnInfo(reader, dataType.TypeCode);
                    udtInfo.Fields.Add(dataType);
                }
                return(udtInfo);

            case ColumnTypeCode.Tuple:
            {
                var tupleInfo     = new TupleColumnInfo();
                var elementLength = reader.ReadInt16();
                for (var i = 0; i < elementLength; i++)
                {
                    var dataType = new ColumnDesc
                    {
                        TypeCode = (ColumnTypeCode)reader.ReadUInt16(),
                    };
                    dataType.TypeInfo = GetColumnInfo(reader, dataType.TypeCode);
                    tupleInfo.Elements.Add(dataType);
                }
                return(tupleInfo);
            }

            default:
                return(null);
            }
        }
        internal RowSetMetadata(FrameReader reader, bool parsePartitionKeys = false)
        {
            if (reader == null)
            {
                //Allow to be created for unit tests
                return;
            }
            var flags        = (RowSetMetadataFlags)reader.ReadInt32();
            var columnLength = reader.ReadInt32();

            if (parsePartitionKeys)
            {
                PartitionKeys = new int[reader.ReadInt32()];
                for (var i = 0; i < PartitionKeys.Length; i++)
                {
                    PartitionKeys[i] = reader.ReadInt16();
                }
            }

            string gKsname    = null;
            string gTablename = null;

            if ((flags & RowSetMetadataFlags.HasMorePages) == RowSetMetadataFlags.HasMorePages)
            {
                PagingState = reader.ReadBytes();
            }
            if ((flags & RowSetMetadataFlags.NoMetadata) == RowSetMetadataFlags.NoMetadata)
            {
                return;
            }
            if ((flags & RowSetMetadataFlags.GlobalTablesSpec) == RowSetMetadataFlags.GlobalTablesSpec)
            {
                gKsname    = reader.ReadString();
                gTablename = reader.ReadString();
            }

            Columns       = new CqlColumn[columnLength];
            ColumnIndexes = new Dictionary <string, int>(columnLength);
            for (var i = 0; i < columnLength; i++)
            {
                var col = new CqlColumn {
                    Index = i
                };
                if ((flags & RowSetMetadataFlags.GlobalTablesSpec) == 0)
                {
                    col.Keyspace = reader.ReadString();
                    col.Table    = reader.ReadString();
                }
                else
                {
                    col.Keyspace = gKsname;
                    col.Table    = gTablename;
                }
                col.Name                = reader.ReadString();
                col.TypeCode            = (ColumnTypeCode)reader.ReadUInt16();
                col.TypeInfo            = GetColumnInfo(reader, col.TypeCode);
                col.Type                = reader.Serializer.GetClrType(col.TypeCode, col.TypeInfo);
                Columns[i]              = col;
                ColumnIndexes[col.Name] = i;
            }
            Keyspace = gKsname ?? (columnLength > 0 ? Columns[0].Keyspace : null);
        }