public class BufferUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static int |
compareBytes(byte[] left,
byte[] right) |
static java.nio.ByteBuffer |
createByteBuffer(boolean[] booleans,
Primitive valueType) |
static java.nio.ByteBuffer |
createByteBuffer(double[] doubles,
Primitive valueType)
Creates a ByteBuffer of specified valueType from an array of doubles
|
static java.nio.ByteBuffer |
createByteBuffer(float[] floats,
Primitive valueType)
Creates a ByteBuffer of specified valueType from an array of floats
|
static java.nio.ByteBuffer |
createByteBuffer(int[] ints,
Primitive valueType)
Creates a ByteBuffer of specified valueType from an array of ints
|
static java.nio.ByteBuffer |
createByteBuffer(java.util.List<?> values,
Primitive valueType)
Creates a byteBuffer of specified valueType from a collection of numbers or strings.
|
static java.nio.ByteBuffer |
createByteBuffer(long[] longs,
Primitive valueType)
Creates a ByteBuffer of specified valueType from an array of longs
|
static java.lang.String |
decodeString(byte[] bytes) |
static java.lang.String |
decodeString(java.nio.ByteBuffer buffer) |
static int |
decodeVarint(java.nio.ByteBuffer buffer) |
static java.nio.ByteBuffer |
encodeString(java.lang.String string) |
static int |
encodeVarint(java.nio.ByteBuffer buffer,
int value)
Based on EncodeVarint64 in TensorFlow:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/lib/core/coding.cc#L110
Note that Java int is 32 bit, so this code is not fully identical.
|
static int |
primitiveSize(Primitive valueType)
Return size of primitive types in terms of bytes
|
static int |
varintLength(int value)
Based on VarintLength in TensorFlow:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/lib/core/coding.cc#L127
Note that Java int is 32 bit, so this code is not fully identical.
|
public static java.nio.ByteBuffer encodeString(java.lang.String string)
public static java.lang.String decodeString(byte[] bytes)
public static java.lang.String decodeString(java.nio.ByteBuffer buffer)
public static int compareBytes(byte[] left,
byte[] right)
public static int primitiveSize(Primitive valueType)
valueType - type for which size is requiredpublic static java.nio.ByteBuffer createByteBuffer(java.util.List<?> values,
Primitive valueType)
values - a collection of values; Currently only Number and String values are supportedvalueType - numbers are coerced to this type before being added to bytebufferpublic static java.nio.ByteBuffer createByteBuffer(float[] floats,
Primitive valueType)
floats - an array of floatsvalueType - floats are coerced to this type before being added to ByteBufferpublic static java.nio.ByteBuffer createByteBuffer(long[] longs,
Primitive valueType)
longs - an array of longsvalueType - longs are coerced to this type before being added to ByteBufferpublic static java.nio.ByteBuffer createByteBuffer(int[] ints,
Primitive valueType)
ints - an array of intsvalueType - ints are coerced to this type before being added to ByteBufferpublic static java.nio.ByteBuffer createByteBuffer(double[] doubles,
Primitive valueType)
doubles - an array of doublesvalueType - doubles are coerced to this type before being added to ByteBufferpublic static java.nio.ByteBuffer createByteBuffer(boolean[] booleans,
Primitive valueType)
public static int varintLength(int value)
public static int encodeVarint(java.nio.ByteBuffer buffer,
int value)
public static int decodeVarint(java.nio.ByteBuffer buffer)