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

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

            // アイテム バッファ テーブルを生成
            var ms = new MemoryStream(binBuilder.CreateItemBufferTable(items, new ulong[items.Count]));

            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    // value データ本体は読み取らない
                    var itemBufferTable = binLoader.LoadItemBufferTable(br, false);

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

            // アイテム コレクションの定義
            var items = new PropItemCollection();

            // すべて null 値で追加
            var types = Enum.GetNames(typeof(PropType));

            foreach (var type in types)
            {
                items.Add(new PropItem(type + "Prop", (PropType)Enum.Parse(typeof(PropType), type), null));
            }

            // 処理実行
            try
            {
                var binResult = binBuilder.CreateItemBufferTable(items, new ulong[items.Count]);
                this.TestContext.WriteLine("Added props = {0}", items.Count);
                this.TestContext.WriteLine("Created buffer = {0} bytes", binResult.Length);
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #3
0
        /// <summary>
        /// アイテム バッファ テーブルのバッファを生成します。バッファは、アイテムの数と名前が同一である場合、同じ長さになります。
        /// </summary>
        /// <param name="items"></param>
        /// <param name="itemBufferStartOffset"></param>
        /// <returns></returns>
        public byte[] CreateItemBufferTable(PropItemCollection items, ulong[] itemBufferStartOffset)
        {
            if (items.Count != itemBufferStartOffset.Length)
            {
                throw new ArgumentException("Internal Error", nameof(itemBufferStartOffset));
            }

            using (var ms = new MemoryStream())
                using (var bw = new BinaryWriter(ms))
                {
                    bw.Write((uint)items.Count); // アイテム数

#if DEBUG
                    Console.WriteLine("== CREATE ITEM BUFFER TABLE ==");
#endif
                    foreach (var elem in items.Select((item, idx) => new { item, itemBufferOffset = itemBufferStartOffset[idx] }))
                    {
#if DEBUG
                        Console.WriteLine("{0}={1}", elem.item.Name, elem.itemBufferOffset);
#endif

                        this._writeString(bw, elem.item.Name); // アイテム名 (バッファ長付き)
                        bw.Write(elem.itemBufferOffset);       // アイテム バッファの開始オフセット
                    }

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

            // セクションの定義
            var propItemNames = new string[]
            {
                "DEBUG_PROP_01",
                "DEBUG_PROP_02",
                "DEBUG_PROP_03",
                "DEBUG_PROP_04",
                "DEBUG_PROP_05",
            };

            var propItems = new PropItemCollection()
            {
                new PropItem(propItemNames[0], PropType.String, null),
                new PropItem(propItemNames[1], PropType.String, null),
                new PropItem(propItemNames[2], PropType.String, null),
                new PropItem(propItemNames[3], PropType.String, null),
                new PropItem(propItemNames[4], PropType.String, null),
            };

            // アイテム バッファ テーブルを生成
            var ms = new MemoryStream(binBuilder.CreateItemBufferTable(propItems, new ulong[propItems.Count]));

            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    var propItemBufferTable = binLoader.LoadItemBufferTable(br, false);

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

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

            // アイテム コレクションの定義
            var items = new PropItemCollection()
            {
                // 0 件
            };

            // 処理実行
            try
            {
                var binResult = binBuilder.CreateItemBufferTable(items, new ulong[items.Count]);
                this.TestContext.WriteLine("Added props = {0}", items.Count);
                this.TestContext.WriteLine("Created buffer = {0} bytes", binResult.Length);
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }