public TableTypesData GetByKey(int key1, int key2, int key3, int key4) { ulong key = TableHelper.GetKey(key1, key2, key3, key4); TableTypesData TableBytesData = GetTableBytesData(key); return(TableBytesData); }
protected override BaseTableData OnGetVal(TableTypesData bytesData) { var table = new Table_Assets(); bytesData.BeginLoad(); table.id = bytesData.ReadInt32(); table.dir = bytesData.ReadString(); table.name = bytesData.ReadString(); table.suffix = bytesData.ReadString(); return(table); }
protected TableData <T> GetTableData(TableTypesData bytesData) { try { var TableData = OnGetVal(bytesData); return((TableData <T>)TableData); } catch (Exception exception) { Debug.LogErrorFormat("{0}表 解析出错 {1}", Name(), exception.StackTrace); return(null); } }
/// <summary> /// 通过ID获取对象 /// </summary> private TableData <T> Get(ulong key, bool isCache = true) { LoadTableTable(); TableData <T> TableData; if (!TableDataDic.TryGetValue(key, out TableData)) { TableTypesData bytesData = GetTableBytesData(key); if (bytesData == null) { return(null); } TableData = GetTableData(bytesData); if (isCache) { if (!TableDataDic.ContainsKey(key)) { TableDataDic.Add(key, TableData); } } } return(TableData); }
public TableInfo GetTableTable(string tableName) { TableInfo tableInfo; if (_tableInfoDic.ContainsKey(tableName)) { tableInfo = _tableInfoDic[tableName]; } else { tableInfo = new TableInfo(); Dictionary <ulong, TableTypesData> TableBytesDataDic = new Dictionary <ulong, TableTypesData>(); byte[] data = TableHelper.GetBytes(tableName); if (data == null) { return(null); } MemoryStream stream = new MemoryStream(data); BinaryReader reader = null; List <TableField> tableFieldList = new List <TableField>(); try { reader = new BinaryReader(stream); int rowsCount = reader.ReadUInt16(); //行数,不包括标题行 int columnsCount = reader.ReadByte(); //列数(也就是Table表每行字段数) for (int i = 0; i < columnsCount; i++) { TableField tableField = new TableField(); var val = (int)reader.ReadByte(); tableField.isBase = ((val & 0x1) != 0); tableField.isList = ((val & 0x2) != 0); tableField.define = (TableDefine)((val >> 2) & 0x3); tableField.fieldType = (ETableBaseType)((val >> 4) & 0xf); tableFieldList.Add(tableField); } for (int i = 0; i < rowsCount; i++) { ulong key = reader.ReadUInt64(); int len = reader.ReadInt32(); byte[] allFieldData = reader.ReadBytes(len); TableTypesData TableDate = new TableTypesData(); TableDate.Init(allFieldData, tableFieldList, tableName); TableBytesDataDic.Add(key, TableDate); } } catch (Exception exception) { Debug.LogErrorFormat("{0}表 二进制数据解析出错 {1}", tableName, exception.StackTrace); return(null); } finally { if (reader != null) { reader.Close(); } } tableInfo.Init(TableBytesDataDic, tableFieldList); _tableInfoDic.Add(tableName, tableInfo); } return(tableInfo); }
protected virtual BaseTableData OnGetVal(TableTypesData bytesData) { return(null); }