Esempio n. 1
0
        /// <summary>
        /// Call all setters once to get a feeling for the deserialization overhead
        /// </summary>
        /// <param name="data"></param>
        void TouchFlat(BookShelfFlat data, int nExpectedBooks, int optionalPayloadDataSize)
        {
            if (!VerifyAndTouch)
            {
                return;
            }

            string tmpTitle = null;
            int    tmpId    = 0;

            if (nExpectedBooks != data.BooksLength)
            {
                throw new InvalidOperationException($"Number of deserialized Books was {data.BooksLength} but expected {nExpectedBooks}. This Serializer seem to have lost data.");
            }

            for (int i = 0; i < data.BooksLength; i++)
            {
                var book = data.Books(i);
                tmpTitle = book.Value.Title;
                tmpId    = book.Value.Id;
                if (tmpId != i + 1)
                {
                    throw new InvalidOperationException($"Book Id was {tmpId} but exepcted {i + 1}");
                }
                if (optionalPayloadDataSize > 0 && book.Value.BookDataLength != optionalPayloadDataSize)
                {
                    throw new InvalidOperationException($"BookData length was {book.Value.BookDataLength} but expected {optionalPayloadDataSize}");
                }
            }
        }
Esempio n. 2
0
        BookShelfFlat DataFlat(int nToCreate)
        {
            var builder = new FlatBufferBuilder(1024);

            Offset <BookFlat>[] books = new Offset <BookFlat> [nToCreate];

            for (int i = 1; i <= nToCreate; i++)
            {
                var title = builder.CreateString($"Book {i}");
                builder.StartVector(1, BookDataSize, 0);
                byte[] bytes = CreateAndFillByteBuffer();
                if (bytes.Length > 0)
                {
                    builder.Put(bytes);
                }
                VectorOffset bookbyteArrayOffset = builder.EndVector();
                var          bookOffset          = BookFlat.CreateBookFlat(builder, title, i, bookbyteArrayOffset);
                books[i - 1] = bookOffset;
            }

            var          secretOffset = builder.CreateString("private member value");
            VectorOffset booksVector  = builder.CreateVectorOfTables <BookFlat>(books);
            var          lret         = BookShelfFlat.CreateBookShelfFlat(builder, booksVector, secretOffset);

            builder.Finish(lret.Value);
            var bookshelf = BookShelfFlat.GetRootAsBookShelfFlat(builder.DataBuffer);

            return(bookshelf);
        }
Esempio n. 3
0
        /// <summary>
        /// Call all setters once to get a feeling for the deserialization overhead
        /// </summary>
        /// <param name="data"></param>
        void TouchFlat(BookShelfFlat data)
        {
            if (!IsTouch)
            {
                return;
            }

            string tmpTitle = null;
            int    tmpId    = 0;

            for (int i = 0; i < data.BooksLength; i++)
            {
                var book = data.Books(i);
                tmpTitle = book.Value.Title;
                tmpId    = book.Value.Id;
            }
        }
Esempio n. 4
0
        BookShelfFlat DataFlat(int nToCreate)
        {
            var builder = new FlatBufferBuilder(1024);

            Offset <BookFlat>[] books = new Offset <BookFlat> [nToCreate];

            for (int i = 1; i <= nToCreate; i++)
            {
                var title      = builder.CreateString($"Book {i}");
                var bookOffset = BookFlat.CreateBookFlat(builder, title, i);
                books[i - 1] = bookOffset;
            }

            var          secretOffset = builder.CreateString("private member value");
            VectorOffset booksVector  = builder.CreateVectorOfTables <BookFlat>(books);
            var          lret         = BookShelfFlat.CreateBookShelfFlat(builder, booksVector, secretOffset);

            builder.Finish(lret.Value);
            var bookshelf = BookShelfFlat.GetRootAsBookShelfFlat(builder.DataBuffer);

            return(bookshelf);
        }