/// <summary> /// Writed data to data page. /// </summary> /// <param name="data">Data to write.</param> public void WriteData(byte[] data) { if (data.Length > DataAreaSize) { throw new Exception("Data page can't store more than " + DataAreaSize + " bytes, use mutliple data pages !"); } // Set stored data length m_pOwnerDB.SetFilePosition(m_StartPointer + 27); m_pOwnerDB.WriteToFile(ldb_Utils.IntToByte(data.Length), 0, 4); // Store data m_pOwnerDB.SetFilePosition(m_StartPointer + 33); m_pOwnerDB.WriteToFile(data, 0, data.Length); m_StoredDataLength = data.Length; }
/// <summary> /// Default constructor. /// </summary> /// <param name="dataPageDataAreaSize">Specifies how much data data page can store.</param> /// <param name="ownerDB">Owner DB file..</param> /// <param name="startOffset">Data page start offset pointer.</param> public DataPage(int dataPageDataAreaSize, DbFile ownerDB, long startOffset) { /* DataPage structure * 2 bytes - CRLF * 1 byte - used (f - unused,u - used) * 8 byte - owner object id * 8 bytes - owner data page pointer * 8 bytes - continuing data page pointer * 4 bytes - stored data length in data area * 2 bytes - CRLF * 1000 bytes - data area */ m_DataAreaSize = dataPageDataAreaSize; m_pOwnerDB = ownerDB; m_StartPointer = startOffset; byte[] dataPageInfo = new byte[33]; ownerDB.SetFilePosition(startOffset); ownerDB.ReadFromFile(dataPageInfo, 0, dataPageInfo.Length); m_Data = new byte[dataPageDataAreaSize]; ownerDB.ReadFromFile(m_Data, 0, dataPageDataAreaSize); // CRLF if (dataPageInfo[0] != (byte)'\r') { throw new Exception( "Not right data page startOffset, or invalid data page <CR> is expected but is '" + (int)dataPageInfo[0] + "' !"); } if (dataPageInfo[1] != (byte)'\n') { throw new Exception( "Not right data page startOffset, or invalid data page <LF> is expected but is '" + (int)dataPageInfo[1] + "' !"); } // used if (dataPageInfo[2] == (byte)'u') { m_Used = true; } else { m_Used = false; } // owner object id m_OwnerID = ldb_Utils.ByteToLong(dataPageInfo, 3); // owner data page pointer m_OwnerDataPagePointer = ldb_Utils.ByteToLong(dataPageInfo, 11); // continuing data page pointer m_NextDataPagePointer = ldb_Utils.ByteToLong(dataPageInfo, 19); // stored data length in data area m_StoredDataLength = ldb_Utils.ByteToInt(dataPageInfo, 27); // CRLF if (dataPageInfo[31] != (byte)'\r') { throw new Exception( "Not right data page startOffset, or invalid data page <CR> is expected but is '" + (int)dataPageInfo[31] + "' !"); } if (dataPageInfo[32] != (byte)'\n') { throw new Exception( "Not right data page startOffset, or invalid data page <LF> is expected but is '" + (int)dataPageInfo[32] + "' !"); } }
/// <summary> /// Default constructor. /// </summary> /// <param name="dataPageDataAreaSize">Specifies how much data data page can store.</param> /// <param name="ownerDB">Owner DB file..</param> /// <param name="startOffset">Data page start offset pointer.</param> public DataPage(int dataPageDataAreaSize, DbFile ownerDB, long startOffset) { /* DataPage structure 2 bytes - CRLF 1 byte - used (f - unused,u - used) 8 byte - owner object id 8 bytes - owner data page pointer 8 bytes - continuing data page pointer 4 bytes - stored data length in data area 2 bytes - CRLF 1000 bytes - data area */ m_DataAreaSize = dataPageDataAreaSize; m_pOwnerDB = ownerDB; m_StartPointer = startOffset; byte[] dataPageInfo = new byte[33]; ownerDB.SetFilePosition(startOffset); ownerDB.ReadFromFile(dataPageInfo, 0, dataPageInfo.Length); m_Data = new byte[dataPageDataAreaSize]; ownerDB.ReadFromFile(m_Data, 0, dataPageDataAreaSize); // CRLF if (dataPageInfo[0] != (byte) '\r') { throw new Exception( "Not right data page startOffset, or invalid data page <CR> is expected but is '" + (int) dataPageInfo[0] + "' !"); } if (dataPageInfo[1] != (byte) '\n') { throw new Exception( "Not right data page startOffset, or invalid data page <LF> is expected but is '" + (int) dataPageInfo[1] + "' !"); } // used if (dataPageInfo[2] == (byte) 'u') { m_Used = true; } else { m_Used = false; } // owner object id m_OwnerID = ldb_Utils.ByteToLong(dataPageInfo, 3); // owner data page pointer m_OwnerDataPagePointer = ldb_Utils.ByteToLong(dataPageInfo, 11); // continuing data page pointer m_NextDataPagePointer = ldb_Utils.ByteToLong(dataPageInfo, 19); // stored data length in data area m_StoredDataLength = ldb_Utils.ByteToInt(dataPageInfo, 27); // CRLF if (dataPageInfo[31] != (byte) '\r') { throw new Exception( "Not right data page startOffset, or invalid data page <CR> is expected but is '" + (int) dataPageInfo[31] + "' !"); } if (dataPageInfo[32] != (byte) '\n') { throw new Exception( "Not right data page startOffset, or invalid data page <LF> is expected but is '" + (int) dataPageInfo[32] + "' !"); } }