Beispiel #1
0
		internal Header(RRDFile file)
		{
			if (file.ReadString(4) != Constants.COOKIE)
			{
				throw new IOException("Invalid COOKIE");
			}

			Version = file.ReadString(5);
			IntVersion = int.Parse(Version);
			if (IntVersion > 3)
			{
				throw new IOException("Unsupported RRD version (" + Version + ")");
			}

			file.Align();

			// Consume the FLOAT_COOKIE
			file.ReadDouble();

			DataSourceCount = file.ReadInt();
			ArchiveCount = file.ReadInt();
			PrimaryDataPointStep = file.ReadInt();

			// Skip rest of stat_head_t.par
			file.Align();
			file.SkipBytes(80);

			size = file.FilePointer - offset;
		}
Beispiel #2
0
	public void testReadInt64BitBigEndian(){
	string tempFile = Path.GetTempFileName();
		try
		{
			using (FileStream outputStream = File.OpenWrite(tempFile))
			{
				write64BitBigEndianHeaderToFloatCookie(outputStream);
				//Write out 3 integers (the rest of the normal header), each 64 bits, in little endian format.
				//However, we're expecting only an int (32-bits) back, so the value we're expecting from a 
				// big-endian file is the *last* four bytes only.  The first four bytes are ignored.
				//We write them with real possibly mis-interpretable numbers though, to double check 
				//that it's reading correctly
				byte[] int1 = { 0x77, 0x66, 0x55, 0x44, 0x78, 0x56, 0x34, 0x12};
				byte[] int2 = { 0x77, 0x66, 0x55, 0x44, 0x12, 0x34, 0x56, 0x78};
				byte[] int3 = { 0x77, 0x66, 0x55, 0x44, 0x78, 0x12, 0x56, 0x34};

				outputStream.Write(int1,0,8);
				outputStream.Write(int2,0,8);
				outputStream.Write(int3,0,8);

			}

			using(RRDFile rrdFile = new RRDFile(tempFile))
			{
				rrdFile.SkipBytes(24); //Skip the string cookie, version, padding, and float cookie
				Assert.AreEqual(0x78563412, rrdFile.ReadInt());
				Assert.AreEqual(0x12345678, rrdFile.ReadInt());
				Assert.AreEqual(0x78125634, rrdFile.ReadInt());
			}

		}
		finally
		{
			try
			{
				File.Delete(tempFile);
			}
			catch (Exception)
			{

			}
		}
	}
Beispiel #3
0
	public void testReadInt64BitLittleEndian(){
	string tempFile = Path.GetTempFileName();
		try
		{
			using (FileStream outputStream = File.OpenWrite(tempFile))
			{
				write64BitLittleEndianHeaderToFloatCookie(outputStream);
				//Write out 3 integers (the rest of the normal header), each 32 bits, in little endian format.
				byte[] int1 = {0x12, 0x34, 0x56, 0x78, 0x77, 0x66, 0x55, 0x44}; //Gives the integer 0x78563412 in little endian
				byte[] int2 = {0x78, 0x56, 0x34, 0x12, 0x77, 0x66, 0x55, 0x44}; //Gives the integer 0x12345678 in little endian
				byte[] int3 = {0x34, 0x12, 0x78, 0x56, 0x77, 0x66, 0x55, 0x44}; //Gives the integer 0x56781234 in little endian

				outputStream.Write(int1,0,8);
				outputStream.Write(int2,0,8);
				outputStream.Write(int3,0,8);

			}

			using(RRDFile rrdFile = new RRDFile(tempFile))
			{
				rrdFile.SkipBytes(24); //Skip the string cookie, version, padding, and float cookie
				Assert.AreEqual(0x78563412, rrdFile.ReadInt());
				Assert.AreEqual(0x12345678, rrdFile.ReadInt());
				Assert.AreEqual(0x56781234, rrdFile.ReadInt());
			}

		}
		finally
		{
			try
			{
				File.Delete(tempFile);
			}
			catch (Exception)
			{

			}
		}
	}
Beispiel #4
0
		internal void LoadCurrentRow(RRDFile file)
		{
			currentRow = file.ReadInt();
		}