Beispiel #1
0
        public static bool ReadResult(ProtoReaderContext context)
        {
            if (context.ReadFieldHeader() == NoneFieldHeader)
            {
                return(false);
            }

            if (context.CurrentFieldHeader != ResultFieldHeader)
            {
                throw new InvalidDataException($"Field header '{ResultFieldHeader}' expected, actual '{context.CurrentFieldHeader}'.");
            }

            context.StartSubItem();

            if (context.ReadFieldHeader() == NoneFieldHeader)
            {
                // TODO: Clear buffer and reset columns.
                context.ReachedEndOfCurrentResult = true;
                context.EndSubItem();

                return(true);
            }

            ColumnsReader.ReadColumns(context);

            context.ReachedEndOfCurrentResult = false;

            return(true);
        }
        public static void ReadColumns(ProtoReaderContext context)
        {
            if (context.CurrentFieldHeader != ColumnFieldHeader)
            {
                throw new InvalidDataException($"Field header '{ColumnFieldHeader}' expected, actual '{context.CurrentFieldHeader}'.");
            }

            context.Columns = new List <ProtoDataColumn>(ReadColumnsImpl(context));
        }
        private static IEnumerable <ProtoDataColumn> ReadColumnsImpl(ProtoReaderContext context)
        {
            do
            {
                context.StartSubItem();

                var name          = ReadColumnName(context);
                var protoDataType = ReadColumnType(context);

                // Backwards compatibility or unnecessary?
                while (context.ReadFieldHeader() != NoneFieldHeader)
                {
                    context.Reader.SkipField();
                }

                context.EndSubItem();

                yield return(new ProtoDataColumn(name: name, dataType: TypeHelper.GetType(protoDataType), protoBufDataType: protoDataType));
            }while (context.ReadFieldHeader() == ColumnFieldHeader);
        }
        private static ProtoDataType ReadColumnType(ProtoReaderContext context)
        {
            context.ReadExpectedFieldHeader(ColumnTypeFieldHeader);

            return((ProtoDataType)context.Reader.ReadInt32());
        }
        private static string ReadColumnName(ProtoReaderContext context)
        {
            context.ReadExpectedFieldHeader(ColumnNameFieldHeader);

            return(context.Reader.ReadString());
        }