org.eclipse.jgit.util
Class NB

java.lang.Object
  extended by org.eclipse.jgit.util.NB

public final class NB
extends Object

Conversion utilities for network byte order handling.


Method Summary
static int compareUInt32(int a, int b)
          Compare a 32 bit unsigned integer stored in a 32 bit signed integer.
static int decodeInt32(byte[] intbuf, int offset)
          Convert sequence of 4 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 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 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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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.

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.

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.

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.

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 48bytes 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.


Copyright © 2012. All Rights Reserved.