[JGIT PATCH 07/10] Add 64 bit network byte order encoding to NB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The pack index v2 file format uses a 64 bit network byte order
element for the 64 bit offset table.  We already have code to
read these elements, but we do not yet have code to write such
an element to an output file.

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 org.spearce.jgit/src/org/spearce/jgit/util/NB.java |   37 ++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/util/NB.java b/org.spearce.jgit/src/org/spearce/jgit/util/NB.java
index 61877b8..6bb65d4 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/util/NB.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/util/NB.java
@@ -172,6 +172,43 @@ public final class NB {
 		intbuf[offset] = (byte) v;
 	}
 
+	/**
+	 * Write a 64 bit integer as a sequence of 8 bytes (network byte order).
+	 * 
+	 * @param intbuf
+	 *            buffer to write the 48bytes of data into.
+	 * @param offset
+	 *            position within the buffer to begin writing to. This position
+	 *            and the next 7 bytes after it (for a total of 8 bytes) will be
+	 *            replaced.
+	 * @param v
+	 *            the value to write.
+	 */
+	public static void encodeInt64(final byte[] intbuf, final int offset, long v) {
+		intbuf[offset + 7] = (byte) v;
+		v >>>= 8;
+
+		intbuf[offset + 6] = (byte) v;
+		v >>>= 8;
+
+		intbuf[offset + 5] = (byte) v;
+		v >>>= 8;
+
+		intbuf[offset + 4] = (byte) v;
+		v >>>= 8;
+
+		intbuf[offset + 3] = (byte) v;
+		v >>>= 8;
+
+		intbuf[offset + 2] = (byte) v;
+		v >>>= 8;
+
+		intbuf[offset + 1] = (byte) v;
+		v >>>= 8;
+
+		intbuf[offset] = (byte) v;
+	}
+
 	private NB() {
 		// Don't create instances of a static only utility.
 	}
-- 
1.5.6.74.g8a5e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux