/// <summary> /// 解析数据 /// </summary> private void ParseDataInternal() { ByteBuffer bb = new ByteBuffer(_bytes); int tabLine = 1; const int headMarkAndSize = 6; while (bb.IsReadable(headMarkAndSize)) { // 检测行标记 short tabHead = bb.ReadShort(); if (tabHead != ConfigDefine.TabStreamHead) { throw new Exception($"Table stream head is invalid. File is {ResName} , tab line is {tabLine}"); } // 检测行大小 int tabSize = bb.ReadInt(); if (!bb.IsReadable(tabSize) || tabSize > ConfigDefine.TabStreamMaxLen) { throw new Exception($"Table stream size is invalid. File is {ResName}, tab line {tabLine}"); } // 读取行内容 ConfigTab tab = null; try { tab = ReadTab(bb); } catch (Exception ex) { throw new Exception($"ReadTab falied. File is {ResName}, tab line {tabLine}. Error : {ex.ToString()}"); } ++tabLine; // 检测是否重复 if (_tabs.ContainsKey(tab.Id)) { throw new Exception($"The tab key is already exist. Type is {this.GetType()}, file is {ResName}, key is { tab.Id}"); } else { _tabs.Add(tab.Id, tab); } } }
/// <summary> /// 获取数据,如果不存在不会报警告 /// </summary> public bool TryGetTab(int key, out ConfigTab tab) { return(_tabs.TryGetValue(key, out tab)); }