public static int GetOffset(byte[] data) { WDBHeader header = (WDBHeader)GemType.RawDeserialize(data, typeof(WDBHeader)); if (header.nId != WDBConst.HeadMark) { return(0); } int DataOffset = Marshal.SizeOf(typeof(WDBHeader)); // read filed name int bufLen = header.nNameBufLen * sizeof(short); if (bufLen > 0) { int index = DataOffset; for (int i = 0; i < header.nFields; i++) { int nextindex = 0, count = 0; if (GetNDBStrLen(data, index, ref nextindex, ref count)) { string fieldName = Encoding.Unicode.GetString(data, index, count); index = nextindex; } else { return(0); } } DataOffset = index; } else { return(0); } return(DataOffset); }
public bool OpenData(byte[] data, string ndbName) { /* * FileStream fs = new FileStream(path, FileMode.Open); * if (fs.CanRead == false) * return false; * mData = new byte[fs.Length]; * fs.Read(mData, 0, (int)fs.Length); * fs.Close(); */ mData = data; // read header mHeader = (WDBHeader)GemType.RawDeserialize(mData, typeof(WDBHeader)); if (mHeader.nId != WDBConst.HeadMark) { return(false); } mDataOffset = Marshal.SizeOf(typeof(WDBHeader)); // read filed name int bufLen = mHeader.nNameBufLen * sizeof(short); if (bufLen > 0) { int index = mDataOffset; mFieldName = new Dictionary <string, int> (); for (int i = 0; i < mHeader.nFields; i++) { int nextindex = 0, count = 0; if (GetNDBStrLen(mData, index, ref nextindex, ref count)) { string fieldName = Encoding.Unicode.GetString(mData, index, count); index = nextindex; if (mFieldName.ContainsKey(fieldName)) { LKDebug.LogError(fieldName + " Have Exist.In table:" + ndbName); continue; } mFieldName.Add(fieldName, i); } else { return(false); } } mDataOffset = index; } else { return(true); } if (mDataOffset % 4 != 0) { mDataOffset += 2; } if (mDataOffset % 4 != 0) { mDataOffset += 2; } // read the first data as field type mFieldType = new int[mHeader.nFields]; for (int j = 0; j < mHeader.nFields; j++) { mFieldType[j] = BitConverter.ToInt32(mData, mDataOffset + j * sizeof(int)); } for (int j = 0; j < mHeader.nFields; j++) { mDataOffset += sizeof(int); } // string offset mStringOffset = mDataOffset + mHeader.nRecords * mHeader.nRecordSize; // create index int indexfield = -1; for (int i = 0; i < GetFieldCount(); i++) { int type = GetFieldType(i); if (type == (int)EWDB_FIELD_TYPE.WFT_V_INDEX) { indexfield = i; } } if (indexfield >= 0) { mIndex = new Dictionary <int, int> (); //MaybeEmpty for (int i = 0; i < GetRecordCount(); i++) { int activeIndex = (int)GetDataByNumber(i, indexfield); if (mIndex.ContainsKey(activeIndex)) { LKDebug.LogError(activeIndex + " Have Exist.In table:" + ndbName); continue; } mIndex.Add(activeIndex, i); } } return(true); }