public void Test001()
        {
            // UTF-8 でビルダ・ローダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);
            var binLoader  = new PropBinaryLoader(encoding);

            // セクションの定義
            var sections = new PropSectionCollection()
            {
                // 0 件
            };

            // セクション テーブルを生成
            var ms = new MemoryStream(binBuilder.CreateSectionTable(sections, new ulong[sections.Count]));

            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    var sectionTable = binLoader.LoadSectionTable(br);

                    // 0 件のセクション情報が格納されていることを確認
                    Assert.AreEqual(0, sectionTable.Count);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
Esempio n. 2
0
        public void Test051()
        {
            // UTF-8 でビルダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);

            // セクションの定義
            var sections = new PropSectionCollection()
            {
                new PropSection("DEBUG01"),
            };

            // 処理実行
            Exception thrown = null;

            try
            {
                var bufResult = binBuilder.CreateSectionTable(sections, new ulong[0]);
            }
            catch (Exception ex)
            {
                thrown = ex;

                this.TestContext.WriteLine("Thrown: {0}", ex);
            }

            Assert.IsTrue(thrown is ArgumentException);
        }
Esempio n. 3
0
        public void Test003()
        {
            // UTF-8 でビルダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);

            // セクションの定義
            var sections = new PropSectionCollection()
            {
                new PropSection("DEBUG01"),
                new PropSection("DEBUG02"),
            };

            // 処理実行
            try
            {
                var bufResult1 = binBuilder.CreateSectionTable(sections, new ulong[] { 0, 0 });
                var bufResult2 = binBuilder.CreateSectionTable(sections, new ulong[] { 1000, 2000 });

                Assert.IsTrue(bufResult1.Length == bufResult2.Length);
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
Esempio n. 4
0
        // 非公開メソッド

        private ulong[][] _createItemBufferMap(PropBinaryBuilder binBuilder, PropSectionCollection sections)
        {
            var itemBufferMap   = new ulong[sections.Count][];
            var currentPosition = 0uL;
            var ns = new NullStream();

            for (var i = 0; i < sections.Count; i++)
            {
                var section = sections[i];
                itemBufferMap[i] = new ulong[section.Items.Count];
                for (var j = 0; j < section.Items.Count; j++)
                {
                    var item = section.Items[j];
                    ns.Seek(0, SeekOrigin.Begin);

                    // Reference アルゴリズム未実装
                    var bufferMode = PropItemBufferMode.Buffered;
                    if (item.IsNull)
                    {
                        bufferMode = PropItemBufferMode.Null;
                    }
                    binBuilder.WriteItemBuffer(ns, item, bufferMode);

                    itemBufferMap[i][j] = currentPosition;
                    currentPosition    += (ulong)ns.Position;
                }
            }

            return(itemBufferMap);
        }
Esempio n. 5
0
        // 公開メソッド

        /// <summary>
        /// セクション テーブルのバッファを生成します。バッファは、セクションの数と名前が同一である場合、同じ長さになります。
        /// </summary>
        /// <param name="sections"></param>
        /// <param name="itemBufferTableStartOffset">アイテム バッファ テーブル セクション内でのアイテム バッファ テーブルの開始オフセット</param>
        /// <returns></returns>
        public byte[] CreateSectionTable(PropSectionCollection sections, ulong[] itemBufferTableStartOffset)
        {
            if (sections.Count != itemBufferTableStartOffset.Length)
            {
                throw new ArgumentException("Internal Error", nameof(itemBufferTableStartOffset));
            }

            using (var ms = new MemoryStream())
                using (var bw = new BinaryWriter(ms))
                {
                    bw.Write((uint)sections.Count); // セクション数

#if DEBUG
                    Console.WriteLine("== CREATE SECTION TABLE ==");
                    Console.WriteLine("SectionsCount: {0}", sections.Count);
#endif

                    foreach (var elem in sections.Select((sec, idx) => new { sec, itemTableStartOffset = itemBufferTableStartOffset[idx] }))
                    {
                        this._writeString(bw, elem.sec.Name); // セクション名 (バッファ長付き)
                        bw.Write(elem.itemTableStartOffset);  // アイテム テーブルの開始オフセット

#if DEBUG
                        Console.WriteLine("{0}={1}", elem.sec.Name, elem.itemTableStartOffset);
#endif
                    }

                    bw.Flush();
                    return(ms.ToArray());
                }
        }
        public void Test002()
        {
            // UTF-8 でビルダ・ローダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);
            var binLoader  = new PropBinaryLoader(encoding);

            // セクションの定義
            var sectionNames = new string[]
            {
                "DEBUG_SECTION_01",
                "DEBUG_SECTION_02",
                "DEBUG_SECTION_03",
                "DEBUG_SECTION_04",
                "DEBUG_SECTION_05",
            };

            var sections = new PropSectionCollection()
            {
                new PropSection(sectionNames[0]),
                new PropSection(sectionNames[1]),
                new PropSection(sectionNames[2]),
                new PropSection(sectionNames[3]),
                new PropSection(sectionNames[4]),
            };

            // セクション テーブルを生成
            var ms = new MemoryStream(binBuilder.CreateSectionTable(sections, new ulong[sections.Count]));

            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    var sectionTable = binLoader.LoadSectionTable(br);

                    // 5 件のセクション情報が格納されていることを確認
                    Assert.AreEqual(5, sectionTable.Count);

                    // 各セクションのセクション名が正しいことを確認
                    var loadedNames = sectionTable.Keys.Select(s => s.Name).ToArray();
                    for (var i = 0; i < 5; i++)
                    {
                        this.TestContext.WriteLine("expected: {0}, actual: {1}", sectionNames[i], loadedNames[i]);
                        Assert.AreEqual(sectionNames[i], loadedNames[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
Esempio n. 7
0
        public void Test002()
        {
            // UTF-8 でビルダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);

            // セクションの定義
            var sections = new PropSectionCollection()
            {
                new PropSection("DEBUG01"),
            };

            // 処理実行
            try
            {
                var binResult = binBuilder.CreateSectionTable(sections, new ulong[sections.Count]);
                this.TestContext.WriteLine("Added sections = {0}", sections.Count);
                this.TestContext.WriteLine("Created buffer = {0} bytes", binResult.Length);
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
Esempio n. 8
0
 public Props(IEnumerable <PropSection> sections)
 {
     this.Sections = new PropSectionCollection();
     this.Sections.AddRange(sections);
 }