aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2017-08-01 08:49:33 -0700
committerShawn Pearce <spearce@spearce.org>2017-08-09 10:42:09 -0700
commit40c9c59e07d3f67db30d5b69a11e81f54cd53ac3 (patch)
tree9162df766690f7ede115097e59857b7d425eeb48 /org.eclipse.jgit
parent22201e8cca3b2b1f6df71fb1053c7358a9a2d72f (diff)
downloadjgit-40c9c59e07d3f67db30d5b69a11e81f54cd53ac3.tar.gz
jgit-40c9c59e07d3f67db30d5b69a11e81f54cd53ac3.zip
NB: encode and decode 24-bit ints
Change-Id: Ie036dc46e5a88a4e87dc52e880505bbe34601ca7
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
index 8536f1dc25..471a4998d7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
@@ -113,6 +113,24 @@ public final class NB {
}
/**
+ * Convert sequence of 3 bytes (network byte order) into unsigned value.
+ *
+ * @param intbuf
+ * buffer to acquire the 3 bytes of data from.
+ * @param offset
+ * position within the buffer to begin reading from. This
+ * position and the next 2 bytes after it (for a total of 3
+ * bytes) will be read.
+ * @return signed integer value that matches the 24 bits read.
+ * @since 4.9
+ */
+ public static int decodeUInt24(byte[] intbuf, int offset) {
+ int r = (intbuf[offset] & 0xff) << 8;
+ r |= intbuf[offset + 1] & 0xff;
+ return (r << 8) | (intbuf[offset + 2] & 0xff);
+ }
+
+ /**
* Convert sequence of 4 bytes (network byte order) into signed value.
*
* @param intbuf
@@ -223,6 +241,29 @@ public final class NB {
}
/**
+ * Write a 24 bit integer as a sequence of 3 bytes (network byte order).
+ *
+ * @param intbuf
+ * buffer to write the 3 bytes of data into.
+ * @param offset
+ * position within the buffer to begin writing to. This position
+ * and the next 2 bytes after it (for a total of 3 bytes) will be
+ * replaced.
+ * @param v
+ * the value to write.
+ * @since 4.9
+ */
+ public static void encodeInt24(byte[] intbuf, int offset, int v) {
+ intbuf[offset + 2] = (byte) v;
+ v >>>= 8;
+
+ intbuf[offset + 1] = (byte) v;
+ v >>>= 8;
+
+ intbuf[offset] = (byte) v;
+ }
+
+ /**
* Write a 32 bit integer as a sequence of 4 bytes (network byte order).
*
* @param intbuf