java.lang.Object
org.yamcs.utils.ByteArrayUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompare(byte[] a1, byte[] a2) lexicographic comparison which returns 0 if one of the array is a subarray of the other onestatic longdecode5Bytes(byte[] a, int offset) Decode 5 bytes as a signed integer in two's complement encodingstatic longdecode6Bytes(byte[] a, int offset) Decode 6 bytes as a signed integer in two's complement encodingstatic bytedecodeByte(byte[] a, int offset) static intdecodeInt(byte[] a, int offset) static intdecodeIntLE(byte[] a, int offset) static longdecodeLong(byte[] a, int offset) static longdecodeLongLE(byte[] a, int offset) static shortdecodeShort(byte[] a, int offset) static shortdecodeShortLE(byte[] a, int offset) static intdecodeUnsigned3Bytes(byte[] a, int offset) static intdecodeUnsigned3BytesLE(byte[] a, int offset) static longdecodeUnsigned5Bytes(byte[] a, int offset) static longdecodeUnsigned6Bytes(byte[] a, int offset) Decode 6 bytes as an unsigned integerstatic longdecodeUnsigned7Bytes(byte[] a, int offset) static shortdecodeUnsignedByte(byte[] a, int offset) static longdecodeUnsignedIntLE(byte[] a, int offset) static intdecodeUnsignedShort(byte[] a, int offset) static intdecodeUnsignedShortLE(byte[] a, int offset) Decode unsigned shortstatic byte[]encodeByte(short x, byte[] a, int offset) static byte[]encodeInt(int x) static byte[]encodeInt(int x, byte[] a, int offset) write an int into a byte array at offset and returns the arraystatic byte[]encodeIntLE(int x) static byte[]encodeIntLE(int x, byte[] a, int offset) static byte[]encodeLong(long x) write a long into a byte array of 8 bytesstatic byte[]encodeLong(long x, byte[] a, int offset) write an long into a byte array at offset and returns the arraystatic byte[]encodeLongLE(long x) write a long into a byte array of 8 bytes, in little endianstatic byte[]encodeLongLE(long x, byte[] a, int offset) static byte[]encodeUnsigned3Bytes(int x, byte[] a, int offset) static byte[]encodeUnsigned5Bytes(long x, byte[] a, int offset) static byte[]encodeUnsigned6Bytes(long x, byte[] a, int offset) static byte[]encodeUnsignedByte(short x, byte[] a, int offset) static byte[]encodeUnsignedIntLE(long x, byte[] a, int offset) static byte[]encodeUnsignedShort(int x) static byte[]encodeUnsignedShort(int x, byte[] a, int offset) static byte[]encodeUnsignedShortLE(int x) static byte[]encodeUnsignedShortLE(int x, byte[] a, int offset) static byte[]minusOne(byte[] a) static byte[]plusOne(byte[] a) If the array is considered binary representation of an integer, add 1 to the integer and returns the corresponding binary representation.
-
Field Details
-
EMPTY
public static final byte[] EMPTY
-
-
Constructor Details
-
ByteArrayUtils
public ByteArrayUtils()
-
-
Method Details
-
plusOne
public static byte[] plusOne(byte[] a) If the array is considered binary representation of an integer, add 1 to the integer and returns the corresponding binary representation. In case an overflow is detected (if the initial array was all 0XFF) an IllegalArgumentException is thrown.- Parameters:
a-- Returns:
- a+1
-
minusOne
public static byte[] minusOne(byte[] a) -
compare
public static int compare(byte[] a1, byte[] a2) lexicographic comparison which returns 0 if one of the array is a subarray of the other one- Parameters:
a1-a2-
-
encodeLong
public static byte[] encodeLong(long x, byte[] a, int offset) write an long into a byte array at offset and returns the array -
encodeLongLE
public static byte[] encodeLongLE(long x, byte[] a, int offset) -
encodeLong
public static byte[] encodeLong(long x) write a long into a byte array of 8 bytes- Parameters:
x-- Returns:
-
encodeLongLE
public static byte[] encodeLongLE(long x) write a long into a byte array of 8 bytes, in little endian -
decodeLong
public static long decodeLong(byte[] a, int offset) -
decodeLongLE
public static long decodeLongLE(byte[] a, int offset) -
decodeUnsigned7Bytes
public static long decodeUnsigned7Bytes(byte[] a, int offset) -
encodeUnsigned6Bytes
public static byte[] encodeUnsigned6Bytes(long x, byte[] a, int offset) -
decodeUnsigned6Bytes
public static long decodeUnsigned6Bytes(byte[] a, int offset) Decode 6 bytes as an unsigned integer- Parameters:
a-offset-- Returns:
-
decode6Bytes
public static long decode6Bytes(byte[] a, int offset) Decode 6 bytes as a signed integer in two's complement encoding- Parameters:
a-offset-- Returns:
-
decode5Bytes
public static long decode5Bytes(byte[] a, int offset) Decode 5 bytes as a signed integer in two's complement encoding- Parameters:
a-offset-- Returns:
-
encodeUnsigned5Bytes
public static byte[] encodeUnsigned5Bytes(long x, byte[] a, int offset) -
decodeUnsigned5Bytes
public static long decodeUnsigned5Bytes(byte[] a, int offset) -
encodeInt
public static byte[] encodeInt(int x, byte[] a, int offset) write an int into a byte array at offset and returns the array -
encodeIntLE
public static byte[] encodeIntLE(int x, byte[] a, int offset) -
encodeUnsignedIntLE
public static byte[] encodeUnsignedIntLE(long x, byte[] a, int offset) -
encodeInt
public static byte[] encodeInt(int x) -
encodeIntLE
public static byte[] encodeIntLE(int x) -
decodeInt
public static int decodeInt(byte[] a, int offset) -
decodeIntLE
public static int decodeIntLE(byte[] a, int offset) -
decodeUnsignedIntLE
public static long decodeUnsignedIntLE(byte[] a, int offset) -
encodeUnsigned3Bytes
public static byte[] encodeUnsigned3Bytes(int x, byte[] a, int offset) -
decodeUnsigned3Bytes
public static int decodeUnsigned3Bytes(byte[] a, int offset) -
decodeUnsigned3BytesLE
public static int decodeUnsigned3BytesLE(byte[] a, int offset) -
encodeUnsignedShort
public static byte[] encodeUnsignedShort(int x, byte[] a, int offset) -
encodeUnsignedShort
public static byte[] encodeUnsignedShort(int x) -
encodeUnsignedShortLE
public static byte[] encodeUnsignedShortLE(int x, byte[] a, int offset) -
encodeUnsignedShortLE
public static byte[] encodeUnsignedShortLE(int x) -
decodeShort
public static short decodeShort(byte[] a, int offset) -
decodeShortLE
public static short decodeShortLE(byte[] a, int offset) -
decodeUnsignedShort
public static int decodeUnsignedShort(byte[] a, int offset) -
decodeUnsignedShortLE
public static int decodeUnsignedShortLE(byte[] a, int offset) Decode unsigned short- Parameters:
a-offset-- Returns:
-
encodeUnsignedByte
public static byte[] encodeUnsignedByte(short x, byte[] a, int offset) -
encodeByte
public static byte[] encodeByte(short x, byte[] a, int offset) -
decodeUnsignedByte
public static short decodeUnsignedByte(byte[] a, int offset) -
decodeByte
public static byte decodeByte(byte[] a, int offset)
-