Ejemplo n.º 1
0
        /// <summary>
        /// 解析数据
        /// </summary>
        private void ParseDataInternal(byte[] bytes)
        {
            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 {Location} , 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 {Location}, tab line {tabLine}");
                }

                // 读取行内容
                ConfigTab tab = null;
                try
                {
                    tab = ReadTab(bb);
                }
                catch (Exception ex)
                {
                    throw new Exception($"ReadTab falied. File is {Location}, 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 {Location}, key is { tab.Id}");
                }
                else
                {
                    _tabs.Add(tab.Id, tab);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取数据,如果不存在不会报警告
 /// </summary>
 public bool TryGetTab(int key, out ConfigTab tab)
 {
     return(_tabs.TryGetValue(key, out tab));
 }