예제 #1
0
        /// <summary>Deserializes a foreign table.</summary>
        /// <remarks>
        ///     This can only deserialize rows written with layout. (Requires use of <see cref="Flags.WithLayout" /> when
        ///     serializing.)
        /// </remarks>
        /// <param name="reader">The reader to read from.</param>
        /// <returns>The deserialized table instance.</returns>
        public static ITable DeserializeForeignTable(this DataReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var flags = (Flags)reader.Read7BitEncodedInt32();

            if ((flags & Flags.WithLayout) == 0)
            {
                throw new NotSupportedException(
                          "For DeserializeForeignX() functions the layout has to be written by the sender! The current decoded data does not contain a layout!");
            }

            var layout = RowLayout.Load(reader);
            var result = MemoryTable.Create(layout);
            var count  = reader.Read7BitEncodedInt64();

            for (long l = 0; l < count; l++)
            {
                var row = DeserializeData(reader, layout);
                result.Insert(row);
            }

            return(result);
        }
예제 #2
0
        /// <summary>Deserializes a row.</summary>
        /// <param name="reader">The reader.</param>
        /// <param name="layout">The layout.</param>
        /// <returns>The deserialized row.</returns>
        public static Row DeserializeRow(this DataReader reader, RowLayout layout)
        {
            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var flags = (Flags)reader.Read7BitEncodedInt32();

            if ((flags & Flags.WithLayout) != 0)
            {
                var otherLayout = RowLayout.Load(reader);
                RowLayout.CheckLayout(layout, otherLayout);
            }

            var count = reader.Read7BitEncodedInt32();

            if (count != 1)
            {
                throw new InvalidDataException($"Got {count} Rows at the stream but want to read exactly one!");
            }

            return(DeserializeData(reader, layout));
        }
예제 #3
0
        /// <summary>Deserializes a foreign row.</summary>
        /// <remarks>
        ///     This can only deserialize rows written with layout. (Requires use of <see cref="Flags.WithLayout" /> when
        ///     serializing.)
        /// </remarks>
        /// <param name="reader">The reader to read from.</param>
        /// <returns>The deserialized row instance.</returns>
        public static Row DeserializeForeignRow(this DataReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var flags = (Flags)reader.Read7BitEncodedInt32();

            if ((flags & Flags.WithLayout) == 0)
            {
                throw new NotSupportedException(
                          "For DeserializeForeignX() functions the layout has to be written by the sender! The current decoded data does not contain a layout!");
            }

            var layout = RowLayout.Load(reader);
            var count  = reader.Read7BitEncodedInt32();

            if (count != 1)
            {
                throw new InvalidDataException($"Got {count} Rows at the stream but want to read exactly one!");
            }

            return(DeserializeData(reader, layout));
        }
예제 #4
0
        /// <summary>Deserializes an item array.</summary>
        /// <typeparam name="TStruct">Structure type.</typeparam>
        /// <param name="reader">The reader.</param>
        /// <returns>The deserialized structures.</returns>
        /// <exception cref="ArgumentNullException">Reader.</exception>
        public static TStruct[] DeserializeItems <TStruct>(this DataReader reader)
            where TStruct : struct
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var flags  = (Flags)reader.Read7BitEncodedInt32();
            var layout = RowLayout.CreateTyped(typeof(TStruct));

            if ((flags & Flags.WithLayout) != 0)
            {
                var otherLayout = RowLayout.Load(reader);
                RowLayout.CheckLayout(layout, otherLayout);
            }

            var results = new TStruct[reader.Read7BitEncodedInt32()];

            for (var i = 0; i < results.Length; i++)
            {
                var row = DeserializeData(reader, layout);
                results[i] = row.GetStruct <TStruct>(layout);
            }

            return(results);
        }