Class BufferUtils

java.lang.Object
com.linkedin.feathr.common.tensorbuilder.BufferUtils

public class BufferUtils extends Object
  • Method Details

    • encodeString

      public static ByteBuffer encodeString(String string)
    • decodeString

      public static String decodeString(byte[] bytes)
    • decodeString

      public static String decodeString(ByteBuffer buffer)
    • compareBytes

      public static int compareBytes(byte[] left, byte[] right)
    • primitiveSize

      public static int primitiveSize(Primitive valueType)
      Return size of primitive types in terms of bytes
      Parameters:
      valueType - type for which size is required
      Returns:
      size of the valueType in terms of bytes
    • createByteBuffer

      public static ByteBuffer createByteBuffer(List<?> values, Primitive valueType)
      Creates a byteBuffer of specified valueType from a collection of numbers or strings.
      Parameters:
      values - a collection of values; Currently only Number and String values are supported
      valueType - numbers are coerced to this type before being added to bytebuffer
      Returns:
      ByteBuffer containing all numbers coerced into specified valueType
    • createByteBuffer

      public static ByteBuffer createByteBuffer(float[] floats, Primitive valueType)
      Creates a ByteBuffer of specified valueType from an array of floats
      Parameters:
      floats - an array of floats
      valueType - floats are coerced to this type before being added to ByteBuffer
      Returns:
      ByteBuffer containing all floats coerced into specified valueType
    • createByteBuffer

      public static ByteBuffer createByteBuffer(long[] longs, Primitive valueType)
      Creates a ByteBuffer of specified valueType from an array of longs
      Parameters:
      longs - an array of longs
      valueType - longs are coerced to this type before being added to ByteBuffer
      Returns:
      ByteBuffer containing all longs coerced into specified valueType
    • createByteBuffer

      public static ByteBuffer createByteBuffer(int[] ints, Primitive valueType)
      Creates a ByteBuffer of specified valueType from an array of ints
      Parameters:
      ints - an array of ints
      valueType - ints are coerced to this type before being added to ByteBuffer
      Returns:
      ByteBuffer containing all ints coerced into specified valueType
    • createByteBuffer

      public static ByteBuffer createByteBuffer(double[] doubles, Primitive valueType)
      Creates a ByteBuffer of specified valueType from an array of doubles
      Parameters:
      doubles - an array of doubles
      valueType - doubles are coerced to this type before being added to ByteBuffer
      Returns:
      ByteBuffer containing all doubles coerced into specified valueType
    • createByteBuffer

      public static ByteBuffer createByteBuffer(boolean[] booleans, Primitive valueType)
    • varintLength

      public 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.
    • encodeVarint

      public static int encodeVarint(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.
      Returns:
      the length of the encoding.
    • decodeVarint

      public static int decodeVarint(ByteBuffer buffer)