Class EncodingUtils

java.lang.Object
org.apache.thrift.EncodingUtils

public class EncodingUtils extends Object
Utility methods for use when encoding/decoding raw data as byte arrays.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final byte
    clearBit(byte v, int position)
    Returns v, with the bit at position set to zero.
    static final int
    clearBit(int v, int position)
     
    static final long
    clearBit(long v, int position)
     
    static final short
    clearBit(short v, int position)
     
    static final int
    decodeBigEndian(byte[] buf)
    Decode a series of 4 bytes from buf, starting at position 0, and interpret them as an integer.
    static final int
    decodeBigEndian(byte[] buf, int offset)
    Decode a series of 4 bytes from buf, start at offset, and interpret them as an integer.
    static final void
    encodeBigEndian(int integer, byte[] buf)
    Encode integer as a series of 4 bytes into buf starting at position 0 within that buffer.
    static final void
    encodeBigEndian(int integer, byte[] buf, int offset)
    Encode integer as a series of 4 bytes into buf starting at position offset.
    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.
    static final int
    setBit(int v, int position, boolean value)
     
    static final long
    setBit(long v, int position, boolean value)
     
    static final short
    setBit(short v, int position, boolean value)
     
    static final boolean
    testBit(byte v, int position)
    Bitfield utilities.
    static final boolean
    testBit(int v, int position)
     
    static final boolean
    testBit(long v, int position)
     
    static final boolean
    testBit(short v, int position)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EncodingUtils

      public EncodingUtils()
  • Method Details

    • encodeBigEndian

      public static final void encodeBigEndian(int integer, byte[] buf)
      Encode integer as a series of 4 bytes into buf 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)
      Encode integer as a series of 4 bytes into buf starting at position offset.
      Parameters:
      integer - The integer to encode.
      buf - The buffer to write to.
      offset - The offset within buf to start the encoding.
    • decodeBigEndian

      public static final int decodeBigEndian(byte[] buf)
      Decode a series of 4 bytes from buf, 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 from buf, start at offset, and interpret them as an integer.
      Parameters:
      buf - The buffer to read from.
      offset - The offset with buf 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.
      Parameters:
      v - the value whose bit is to be checked.
      position - the 0 based bit number indicating the bit to check.
      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.
      Parameters:
      v - the value whose bit is to be cleared.
      position - the 0 based bit number indicating the bit to clear.
      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.
      Parameters:
      v - the value whose bit is to be set.
      position - the 0 based bit number indicating the bit to set.
      value - if true, the given bit is set to 1; otherwise it is set to 0.
      Returns:
      v, with the bit at position set to 0 (if value is false) or 1 (if value is true).
    • 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)