Top Description Constructors Methods
org.eclipse.jgit.util

public final Class NB

extends Object
Class Inheritance

Conversion utilities for network byte order handling.

Constructor Summary

AccessConstructor and Description
private
NB()

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

< 0 if a < b; 0 if a == b; > 0 if a > b.
compareUInt32
(final int
the first value to compare.
a
,
final int
the second value to compare.
b
)

Compare a 32 bit unsigned integer stored in a 32 bit signed integer.

public static int

Returns:

< 0 if a < b; 0 if a == b; > 0 if a > b.
compareUInt64
(final long
the first value to compare.
a
,
final long
the second value to compare.
b
)

Compare a 64 bit unsigned integer stored in a 64 bit signed integer.

public static int

Returns:

signed integer value that matches the 32 bits read.
decodeInt32
(final byte[]
buffer to acquire the 4 bytes of data from.
intbuf
,
final int
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.
offset
)

Convert sequence of 4 bytes (network byte order) into signed value.

public static long

Returns:

signed integer value that matches the 64 bits read.
decodeInt64
(final byte[]
buffer to acquire the 8 bytes of data from.
intbuf
,
final int
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.
offset
)

Convert sequence of 8 bytes (network byte order) into signed value.

public static int

Returns:

unsigned integer value that matches the 16 bits read.
decodeUInt16
(final byte[]
buffer to acquire the 2 bytes of data from.
intbuf
,
final int
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.
offset
)

Convert sequence of 2 bytes (network byte order) into unsigned value.

public static int

Returns:

signed integer value that matches the 24 bits read.
decodeUInt24
(byte[]
buffer to acquire the 3 bytes of data from.
intbuf
,
int
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.
offset
)

Convert sequence of 3 bytes (network byte order) into unsigned value.

public static long

Returns:

unsigned integer value that matches the 32 bits read.
decodeUInt32
(final byte[]
buffer to acquire the 4 bytes of data from.
intbuf
,
final int
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.
offset
)

Convert sequence of 4 bytes (network byte order) into unsigned value.

public static long

Returns:

unsigned integer value that matches the 64 bits read.
decodeUInt64
(final byte[]
buffer to acquire the 8 bytes of data from.
intbuf
,
final int
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.
offset
)

Convert sequence of 8 bytes (network byte order) into unsigned value.

public static void
encodeInt16(final byte[]
buffer to write the 2 bytes of data into.
intbuf
,
final int
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.
offset
,
int
the value to write.
v
)

Write a 16 bit integer as a sequence of 2 bytes (network byte order).

public static void
encodeInt24(byte[]
buffer to write the 3 bytes of data into.
intbuf
,
int
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.
offset
,
int
the value to write.
v
)

Write a 24 bit integer as a sequence of 3 bytes (network byte order).

public static void
encodeInt32(final byte[]
buffer to write the 4 bytes of data into.
intbuf
,
final int
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.
offset
,
int
the value to write.
v
)

Write a 32 bit integer as a sequence of 4 bytes (network byte order).

public static void
encodeInt64(final byte[]
buffer to write the 8 bytes of data into.
intbuf
,
final int
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.
offset
,
long
the value to write.
v
)

Write a 64 bit integer as a sequence of 8 bytes (network byte order).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NBback to summary
private NB()

Method Detail

compareUInt32back to summary
public static int compareUInt32(final int a, final 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:int

the first value to compare.

b:int

the second value to compare.

Returns:int

< 0 if a < b; 0 if a == b; > 0 if a > b.

compareUInt64back to summary
public static int compareUInt64(final long a, final 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:long

the first value to compare.

b:long

the second value to compare.

Returns:int

< 0 if a < b; 0 if a == b; > 0 if a > b.

Since
4.3
decodeInt32back to summary
public static int decodeInt32(final byte[] intbuf, final int offset)

Convert sequence of 4 bytes (network byte order) into signed value.

Parameters
intbuf:byte[]

buffer to acquire the 4 bytes of data from.

offset:int

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:int

signed integer value that matches the 32 bits read.

decodeInt64back to summary
public static long decodeInt64(final byte[] intbuf, final int offset)

Convert sequence of 8 bytes (network byte order) into signed value.

Parameters
intbuf:byte[]

buffer to acquire the 8 bytes of data from.

offset:int

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:long

signed integer value that matches the 64 bits read.

Since
3.0
decodeUInt16back to summary
public static int decodeUInt16(final byte[] intbuf, final int offset)

Convert sequence of 2 bytes (network byte order) into unsigned value.

Parameters
intbuf:byte[]

buffer to acquire the 2 bytes of data from.

offset:int

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:int

unsigned integer value that matches the 16 bits read.

decodeUInt24back to summary
public static int decodeUInt24(byte[] intbuf, int offset)

Convert sequence of 3 bytes (network byte order) into unsigned value.

Parameters
intbuf:byte[]

buffer to acquire the 3 bytes of data from.

offset:int

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:int

signed integer value that matches the 24 bits read.

Since
4.9
decodeUInt32back to summary
public static long decodeUInt32(final byte[] intbuf, final int offset)

Convert sequence of 4 bytes (network byte order) into unsigned value.

Parameters
intbuf:byte[]

buffer to acquire the 4 bytes of data from.

offset:int

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:long

unsigned integer value that matches the 32 bits read.

decodeUInt64back to summary
public static long decodeUInt64(final byte[] intbuf, final int offset)

Convert sequence of 8 bytes (network byte order) into unsigned value.

Parameters
intbuf:byte[]

buffer to acquire the 8 bytes of data from.

offset:int

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:long

unsigned integer value that matches the 64 bits read.

encodeInt16back to summary
public static void encodeInt16(final byte[] intbuf, final int offset, int v)

Write a 16 bit integer as a sequence of 2 bytes (network byte order).

Parameters
intbuf:byte[]

buffer to write the 2 bytes of data into.

offset:int

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:int

the value to write.

encodeInt24back to summary
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:byte[]

buffer to write the 3 bytes of data into.

offset:int

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:int

the value to write.

Since
4.9
encodeInt32back to summary
public static void encodeInt32(final byte[] intbuf, final int offset, int v)

Write a 32 bit integer as a sequence of 4 bytes (network byte order).

Parameters
intbuf:byte[]

buffer to write the 4 bytes of data into.

offset:int

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:int

the value to write.

encodeInt64back to summary
public static void encodeInt64(final byte[] intbuf, final int offset, long v)

Write a 64 bit integer as a sequence of 8 bytes (network byte order).

Parameters
intbuf:byte[]

buffer to write the 8 bytes of data into.

offset:int

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:long

the value to write.