Package org.apache.thrift
Class EncodingUtils
- java.lang.Object
-
- org.apache.thrift.EncodingUtils
-
public class EncodingUtils extends java.lang.Object
Utility methods for use when encoding/decoding raw data as byte arrays.
-
-
Constructor Summary
Constructors Constructor Description EncodingUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte
clearBit(byte v, int position)
Returns v, with the bit at position set to zero.static int
clearBit(int v, int position)
static long
clearBit(long v, int position)
static short
clearBit(short v, int position)
static int
decodeBigEndian(byte[] buf)
Decode a series of 4 bytes frombuf
, starting at position 0, and interpret them as an integer.static int
decodeBigEndian(byte[] buf, int offset)
Decode a series of 4 bytes frombuf
, start atoffset
, and interpret them as an integer.static void
encodeBigEndian(int integer, byte[] buf)
Encodeinteger
as a series of 4 bytes intobuf
starting at position 0 within that buffer.static void
encodeBigEndian(int integer, byte[] buf, int offset)
Encodeinteger
as a series of 4 bytes intobuf
starting at positionoffset
.static byte
setBit(byte v, int position, boolean value)
Returns v, with the bit at position set to 1 or 0 depending on value.static int
setBit(int v, int position, boolean value)
static long
setBit(long v, int position, boolean value)
static short
setBit(short v, int position, boolean value)
static boolean
testBit(byte v, int position)
Bitfield utilities.static boolean
testBit(int v, int position)
static boolean
testBit(long v, int position)
static boolean
testBit(short v, int position)
-
-
-
Method Detail
-
encodeBigEndian
public static final void encodeBigEndian(int integer, byte[] buf)
Encodeinteger
as a series of 4 bytes intobuf
starting at position 0 within that buffer.- Parameters:
integer
- The integer to encode.buf
- The buffer to write to.
-
encodeBigEndian
public static final void encodeBigEndian(int integer, byte[] buf, int offset)
Encodeinteger
as a series of 4 bytes intobuf
starting at positionoffset
.- Parameters:
integer
- The integer to encode.buf
- The buffer to write to.offset
- The offset withinbuf
to start the encoding.
-
decodeBigEndian
public static final int decodeBigEndian(byte[] buf)
Decode a series of 4 bytes frombuf
, starting at position 0, and interpret them as an integer.- Parameters:
buf
- The buffer to read from.- Returns:
- An integer, as read from the buffer.
-
decodeBigEndian
public static final int decodeBigEndian(byte[] buf, int offset)
Decode a series of 4 bytes frombuf
, start atoffset
, and interpret them as an integer.- Parameters:
buf
- The buffer to read from.offset
- The offset withbuf
to start the decoding.- Returns:
- An integer, as read from the buffer.
-
testBit
public static final boolean testBit(byte v, int position)
Bitfield utilities. Returns true if the bit at position is set in v.
-
testBit
public static final boolean testBit(short v, int position)
-
testBit
public static final boolean testBit(int v, int position)
-
testBit
public static final boolean testBit(long v, int position)
-
clearBit
public static final byte clearBit(byte v, int position)
Returns v, with the bit at position set to zero.
-
clearBit
public static final short clearBit(short v, int position)
-
clearBit
public static final int clearBit(int v, int position)
-
clearBit
public static final long clearBit(long v, int position)
-
setBit
public static final byte setBit(byte v, int position, boolean value)
Returns v, with the bit at position set to 1 or 0 depending on value.
-
setBit
public static final short setBit(short v, int position, boolean value)
-
setBit
public static final int setBit(int v, int position, boolean value)
-
setBit
public static final long setBit(long v, int position, boolean value)
-
-