Package org.eclipse.jgit.util
Class NB
java.lang.Object
org.eclipse.jgit.util.NB
Conversion utilities for network byte order handling.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
compareUInt32
(int a, int b) Compare a 32 bit unsigned integer stored in a 32 bit signed integer.static int
compareUInt64
(long a, long b) Compare a 64 bit unsigned integer stored in a 64 bit signed integer.static int
decodeInt32
(byte[] intbuf, int offset) Convert sequence of 4 bytes (network byte order) into signed value.static long
decodeInt64
(byte[] intbuf, int offset) Convert sequence of 8 bytes (network byte order) into signed value.static int
decodeUInt16
(byte[] intbuf, int offset) Convert sequence of 2 bytes (network byte order) into unsigned value.static int
decodeUInt24
(byte[] intbuf, int offset) Convert sequence of 3 bytes (network byte order) into unsigned value.static long
decodeUInt32
(byte[] intbuf, int offset) Convert sequence of 4 bytes (network byte order) into unsigned value.static long
decodeUInt64
(byte[] intbuf, int offset) Convert sequence of 8 bytes (network byte order) into unsigned value.static void
encodeInt16
(byte[] intbuf, int offset, int v) Write a 16 bit integer as a sequence of 2 bytes (network byte order).static void
encodeInt24
(byte[] intbuf, int offset, int v) Write a 24 bit integer as a sequence of 3 bytes (network byte order).static void
encodeInt32
(byte[] intbuf, int offset, int v) Write a 32 bit integer as a sequence of 4 bytes (network byte order).static void
encodeInt64
(byte[] intbuf, int offset, long v) Write a 64 bit integer as a sequence of 8 bytes (network byte order).
-
Constructor Details
-
NB
private NB()
-
-
Method Details
-
compareUInt32
public static int compareUInt32(int a, int b) Compare a 32 bit unsigned integer stored in a 32 bit signed integer.This function performs an unsigned compare operation, even though Java does not natively support unsigned integer values. Negative numbers are treated as larger than positive ones.
- Parameters:
a
- the first value to compare.b
- the second value to compare.- Returns:
- < 0 if a < b; 0 if a == b; > 0 if a > b.
-
compareUInt64
public static int compareUInt64(long a, long b) Compare a 64 bit unsigned integer stored in a 64 bit signed integer.This function performs an unsigned compare operation, even though Java does not natively support unsigned integer values. Negative numbers are treated as larger than positive ones.
- Parameters:
a
- the first value to compare.b
- the second value to compare.- Returns:
- < 0 if a < b; 0 if a == b; > 0 if a > b.
- Since:
- 4.3
-
decodeUInt16
public static int decodeUInt16(byte[] intbuf, int offset) Convert sequence of 2 bytes (network byte order) into unsigned value.- Parameters:
intbuf
- buffer to acquire the 2 bytes of data from.offset
- position within the buffer to begin reading from. This position and the next byte after it (for a total of 2 bytes) will be read.- Returns:
- unsigned integer value that matches the 16 bits read.
-
decodeUInt24
public static int decodeUInt24(byte[] intbuf, int offset) Convert sequence of 3 bytes (network byte order) into unsigned value.- Parameters:
intbuf
- buffer to acquire the 3 bytes of data from.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.- Returns:
- signed integer value that matches the 24 bits read.
- Since:
- 4.9
-
decodeInt32
public static int decodeInt32(byte[] intbuf, int offset) Convert sequence of 4 bytes (network byte order) into signed value.- Parameters:
intbuf
- buffer to acquire the 4 bytes of data from.offset
- position within the buffer to begin reading from. This position and the next 3 bytes after it (for a total of 4 bytes) will be read.- Returns:
- signed integer value that matches the 32 bits read.
-
decodeInt64
public static long decodeInt64(byte[] intbuf, int offset) Convert sequence of 8 bytes (network byte order) into signed value.- Parameters:
intbuf
- buffer to acquire the 8 bytes of data from.offset
- position within the buffer to begin reading from. This position and the next 7 bytes after it (for a total of 8 bytes) will be read.- Returns:
- signed integer value that matches the 64 bits read.
- Since:
- 3.0
-
decodeUInt32
public static long decodeUInt32(byte[] intbuf, int offset) Convert sequence of 4 bytes (network byte order) into unsigned value.- Parameters:
intbuf
- buffer to acquire the 4 bytes of data from.offset
- position within the buffer to begin reading from. This position and the next 3 bytes after it (for a total of 4 bytes) will be read.- Returns:
- unsigned integer value that matches the 32 bits read.
-
decodeUInt64
public static long decodeUInt64(byte[] intbuf, int offset) Convert sequence of 8 bytes (network byte order) into unsigned value.- Parameters:
intbuf
- buffer to acquire the 8 bytes of data from.offset
- position within the buffer to begin reading from. This position and the next 7 bytes after it (for a total of 8 bytes) will be read.- Returns:
- unsigned integer value that matches the 64 bits read.
-
encodeInt16
public static void encodeInt16(byte[] intbuf, int offset, int v) Write a 16 bit integer as a sequence of 2 bytes (network byte order).- Parameters:
intbuf
- buffer to write the 2 bytes of data into.offset
- position within the buffer to begin writing to. This position and the next byte after it (for a total of 2 bytes) will be replaced.v
- the value to write.
-
encodeInt24
public static void encodeInt24(byte[] intbuf, int offset, int v) Write a 24 bit integer as a sequence of 3 bytes (network byte order).- Parameters:
intbuf
- buffer to write the 3 bytes of data into.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.v
- the value to write.- Since:
- 4.9
-
encodeInt32
public static void encodeInt32(byte[] intbuf, int offset, int v) Write a 32 bit integer as a sequence of 4 bytes (network byte order).- Parameters:
intbuf
- buffer to write the 4 bytes of data into.offset
- position within the buffer to begin writing to. This position and the next 3 bytes after it (for a total of 4 bytes) will be replaced.v
- the value to write.
-
encodeInt64
public static void encodeInt64(byte[] intbuf, int offset, long v) Write a 64 bit integer as a sequence of 8 bytes (network byte order).- Parameters:
intbuf
- buffer to write the 8 bytes of data into.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.v
- the value to write.
-