/// <summary>Commits the object header onto the stream.</summary> /// <remarks> /// Commits the object header onto the stream. /// <p> /// Once the header has been written, the object representation must be fully /// output, or packing must abort abnormally. /// </remarks> /// <param name="otp">the object to pack. Header information is obtained.</param> /// <param name="rawLength"> /// number of bytes of the inflated content. For an object that is /// in whole object format, this is the same as the object size. /// For an object that is in a delta format, this is the size of /// the inflated delta instruction stream. /// </param> /// <exception cref="System.IO.IOException">the underlying stream refused to accept the header. /// </exception> public void WriteHeader(ObjectToPack otp, long rawLength) { if (otp.IsDeltaRepresentation()) { if (packWriter.IsDeltaBaseAsOffset()) { ObjectToPack baseInPack = otp.GetDeltaBase(); if (baseInPack != null && baseInPack.IsWritten()) { long start = count; int n = EncodeTypeSize(Constants.OBJ_OFS_DELTA, rawLength); Write(headerBuffer, 0, n); long offsetDiff = start - baseInPack.GetOffset(); n = headerBuffer.Length - 1; headerBuffer[n] = unchecked ((byte)(offsetDiff & unchecked ((int)(0x7F)))); while ((offsetDiff >>= 7) > 0) { headerBuffer[--n] = unchecked ((byte)(unchecked ((int)(0x80)) | (--offsetDiff & unchecked ( (int)(0x7F))))); } Write(headerBuffer, n, headerBuffer.Length - n); return; } } int n_1 = EncodeTypeSize(Constants.OBJ_REF_DELTA, rawLength); otp.GetDeltaBaseId().CopyRawTo(headerBuffer, n_1); Write(headerBuffer, 0, n_1 + Constants.OBJECT_ID_LENGTH); } else { int n = EncodeTypeSize(otp.GetType(), rawLength); Write(headerBuffer, 0, n); } }
public virtual void TestContructor() { writer = new PackWriter(config, db.NewObjectReader()); NUnit.Framework.Assert.AreEqual(false, writer.IsDeltaBaseAsOffset()); NUnit.Framework.Assert.AreEqual(true, config.IsReuseDeltas()); NUnit.Framework.Assert.AreEqual(true, config.IsReuseObjects()); NUnit.Framework.Assert.AreEqual(0, writer.GetObjectsNumber()); }
public virtual void TestModifySettings() { config.SetReuseDeltas(false); config.SetReuseObjects(false); config.SetDeltaBaseAsOffset(false); NUnit.Framework.Assert.AreEqual(false, config.IsReuseDeltas()); NUnit.Framework.Assert.AreEqual(false, config.IsReuseObjects()); NUnit.Framework.Assert.AreEqual(false, config.IsDeltaBaseAsOffset()); writer = new PackWriter(config, db.NewObjectReader()); writer.SetDeltaBaseAsOffset(true); NUnit.Framework.Assert.AreEqual(true, writer.IsDeltaBaseAsOffset()); NUnit.Framework.Assert.AreEqual(false, config.IsDeltaBaseAsOffset()); }