Package org.apache.avro.io
Class BinaryData
java.lang.Object
org.apache.avro.io.BinaryData
Utilities for binary-encoded data.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Compare binary encoded data.static int
Compare binary encoded data.static int
compareBytes
(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) Lexicographically compare bytes.static int
encodeBoolean
(boolean b, byte[] buf, int pos) Encode a boolean to the byte array at the given position.static int
encodeDouble
(double d, byte[] buf, int pos) Encode a double to the byte array at the given position.static int
encodeFloat
(float f, byte[] buf, int pos) Encode a float to the byte array at the given position.static int
encodeInt
(int n, byte[] buf, int pos) Encode an integer to the byte array at the given position.static int
encodeLong
(long n, byte[] buf, int pos) Encode a long to the byte array at the given position.static int
Hash binary encoded data.static int
skipLong
(byte[] bytes, int start) Skip a binary-encoded long, returning the position after it.
-
Method Details
-
compare
Compare binary encoded data. If equal, return zero. If greater-than, return 1, if less than return -1. Order is consistent with that ofGenericData.compare(Object, Object, Schema)
. -
compare
Compare binary encoded data. If equal, return zero. If greater-than, return 1, if less than return -1. Order is consistent with that ofGenericData.compare(Object, Object, Schema)
. -
compareBytes
public static int compareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) Lexicographically compare bytes. If equal, return zero. If greater-than, return a positive value, if less than return a negative value. -
hashCode
Hash binary encoded data. Consistent withGenericData.hashCode(Object, Schema)
. -
skipLong
public static int skipLong(byte[] bytes, int start) Skip a binary-encoded long, returning the position after it. -
encodeBoolean
public static int encodeBoolean(boolean b, byte[] buf, int pos) Encode a boolean to the byte array at the given position. Will throw IndexOutOfBounds if the position is not valid.- Returns:
- The number of bytes written to the buffer, 1.
-
encodeInt
public static int encodeInt(int n, byte[] buf, int pos) Encode an integer to the byte array at the given position. Will throw IndexOutOfBounds if it overflows. Users should ensure that there are at least 5 bytes left in the buffer before calling this method.- Returns:
- The number of bytes written to the buffer, between 1 and 5.
-
encodeLong
public static int encodeLong(long n, byte[] buf, int pos) Encode a long to the byte array at the given position. Will throw IndexOutOfBounds if it overflows. Users should ensure that there are at least 10 bytes left in the buffer before calling this method.- Returns:
- The number of bytes written to the buffer, between 1 and 10.
-
encodeFloat
public static int encodeFloat(float f, byte[] buf, int pos) Encode a float to the byte array at the given position. Will throw IndexOutOfBounds if it overflows. Users should ensure that there are at least 4 bytes left in the buffer before calling this method.- Returns:
- Returns the number of bytes written to the buffer, 4.
-
encodeDouble
public static int encodeDouble(double d, byte[] buf, int pos) Encode a double to the byte array at the given position. Will throw IndexOutOfBounds if it overflows. Users should ensure that there are at least 8 bytes left in the buffer before calling this method.- Returns:
- Returns the number of bytes written to the buffer, 8.
-