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}"); } }
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}"); } }
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}"); } }
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}"); } }
// 公開メソッド public void Write(Props props) { if (this._isDisposed) { throw new ObjectDisposedException(nameof(PropWriter)); } using (var bw = new BinaryWriter(this._stream, this._encoding, true)) { // アイテム バッファの空書き込みを実行し、アイテム バッファのマップを作成する var itemBufferMap = this._createItemBufferMap(_binBuilder, props.Sections); #if DEBUG Console.WriteLine("== ITEM BUFFER MAPPING =="); for (var i = 0; i < props.Sections.Count; i++) { var sect = props.Sections[i]; Console.WriteLine("[{0}]", sect.Name); for (var j = 0; j < sect.Items.Count; j++) { var item = sect.Items[j]; var itemName = item.Name; var bufferPos = itemBufferMap[i][j]; Console.WriteLine("{0}={1}", itemName, bufferPos); } } #endif // アイテム バッファ テーブルを作成する var itemBufferTableBuffer = new byte[props.Sections.Count][]; var itemBufferTableMap = new ulong[props.Sections.Count]; var currentPosition = 0uL; for (var i = 0; i < props.Sections.Count; i++) { itemBufferTableBuffer[i] = _binBuilder.CreateItemBufferTable(props.Sections[i].Items, itemBufferMap[i]); itemBufferTableMap[i] = currentPosition; currentPosition += (ulong)itemBufferTableBuffer[i].Length; //itemBufferTableMap[i]; } // セクション テーブルを作成し、書き込む bw.Write(_binBuilder.CreateSectionTable(props.Sections, itemBufferTableMap)); // アイテム バッファ テーブルを書き込む for (var i = 0; i < itemBufferTableBuffer.Length; i++) { bw.Write(itemBufferTableBuffer[i]); } // バイナリライタを Flush してからアイテム バッファを書き込む bw.Flush(); for (var i = 0; i < props.Sections.Count; i++) { var section = props.Sections[i]; for (var j = 0; j < section.Items.Count; j++) { var item = section.Items[j]; // Reference アルゴリズム未実装 var bufferMode = PropItemBufferMode.Buffered; if (item.IsNull) { bufferMode = PropItemBufferMode.Null; } _binBuilder.WriteItemBuffer(this._stream, section.Items[j], bufferMode); } } } this._stream.Flush(); }