/// <summary> /// 解析数据表。 /// </summary> /// <param name="dataTable">数据表。</param> /// <param name="dataTableString">要解析的数据表字符串。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>是否解析数据表成功。</returns> public override bool ParseData(DataTableBase dataTable, string dataTableString, object userData) { try { int position = 0; string dataRowString = null; while ((dataRowString = dataTableString.ReadLine(ref position)) != null) { if (dataRowString[0] == '#') { continue; } if (!dataTable.AddDataRow(dataRowString, userData)) { Log.Warning("Can not parse data row string '{0}'.", dataRowString); return(false); } } return(true); } catch (Exception exception) { Log.Warning("Can not parse data table string with exception '{0}'.", exception.ToString()); return(false); } }
/// <summary> /// 解析数据表。 /// </summary> /// <param name="dataTable">数据表。</param> /// <param name="dataTableBytes">要解析的数据表二进制流。</param> /// <param name="startIndex">数据表二进制流的起始位置。</param> /// <param name="length">数据表二进制流的长度。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>是否解析数据表成功。</returns> public override bool ParseData(DataTableBase dataTable, byte[] dataTableBytes, int startIndex, int length, object userData) { try { using (MemoryStream memoryStream = new MemoryStream(dataTableBytes, startIndex, length, false)) { using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8)) { while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { int dataRowBytesLength = binaryReader.Read7BitEncodedInt32(); if (!dataTable.AddDataRow(dataTableBytes, (int)binaryReader.BaseStream.Position, dataRowBytesLength, userData)) { Log.Warning("Can not parse data row bytes."); return(false); } binaryReader.BaseStream.Position += dataRowBytesLength; } } } return(true); } catch (Exception exception) { Log.Warning("Can not parse dictionary bytes with exception '{0}'.", exception.ToString()); return(false); } }