com.amazon.redshift.util

## Class ByteConverter

- java.lang.Object
- - com.amazon.redshift.util.ByteConverter

    public class ByteConverter
    extends Object

Helper methods to parse java base types from byte arrays.

Author:
  Mikko Tiihonen

### Method Summary

Methods
`static boolean` `bool(byte[] bytes, int idx)` Parses a boolean value from the byte array.
`static void` `bool(byte[] target, int idx, boolean value)` Encodes a boolean value to the byte array.
`static int` `bytesToInt(byte[] bytes)` Convert a variable length array of bytes to an integer
`static float` `float4(byte[] bytes, int idx)` Parses a float value from the byte array.
`static void` `float4(byte[] target, int idx, float value)` Encodes a int value to the byte array.
`static double` `float8(byte[] bytes, int idx)` Parses a double value from the byte array.
`static void` `float8(byte[] target, int idx, double value)` Encodes a int value to the byte array.
`static short` `int2(byte[] bytes, int idx)` Parses a short value from the byte array.
`static void` `int2(byte[] target, int idx, int value)` Encodes a int value to the byte array.
`static int` `int4(byte[] bytes, int idx)` Parses an int value from the byte array.
`static void` `int4(byte[] target, int idx, int value)` Encodes a int value to the byte array.
`static long` `int8(byte[] bytes, int idx)` Parses a long value from the byte array.
`static void` `int8(byte[] target, int idx, long value)` Encodes a long value to the byte array.
`static Number` `numeric(byte[] bytes)` Convert a variable length array of bytes to an integer
`static Number` `numeric(byte[] bytes, int pos, int numBytes)` Convert a variable length array of bytes to an integer
`static byte[]` `redshiftNumeric(BigDecimal val, int precision, int scale)` Convert BigDecimal value into scaled bytes.
`static Number` `redshiftNumeric(byte[] bytes, int precision, int scale)` Convert a variable length array of bytes to a Number
`static Number` `redshiftNumeric(byte[] bytes, int pos, int numBytes, int precision, int scale)` Convert a variable length array of bytes to a Number

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### bytesToInt

    public static int bytesToInt(byte[] bytes)

Convert a variable length array of bytes to an integer

Parameters:
  `bytes` - array of bytes that can be decoded as an integer
Returns:
  integer

#### numeric

    public static Number numeric(byte[] bytes)

Convert a variable length array of bytes to an integer

Parameters:
  `bytes` - array of bytes that can be decoded as an integer
Returns:
  integer

#### redshiftNumeric

    public static Number redshiftNumeric(byte[] bytes,
                         int precision,
                         int scale)

Convert a variable length array of bytes to a Number

Parameters:
  `bytes` - array of column bytes that can be decoded as Numeric
  `precision` - precision of the defined column
  `scale` - scale of the defined column
Returns:
  Number value of the given unscaled byte array

#### numeric

    public static Number numeric(byte[] bytes,
                 int pos,
                 int numBytes)

Convert a variable length array of bytes to an integer

Parameters:
  `bytes` - array of bytes that can be decoded as an integer
  `pos` - index of the start position of the bytes array for number
  `numBytes` - number of bytes to use, length is already encoded in the binary format but this is used for double checking
Returns:
  integer

#### redshiftNumeric

    public static Number redshiftNumeric(byte[] bytes,
                         int pos,
                         int numBytes,
                         int precision,
                         int scale)

Convert a variable length array of bytes to a Number

Parameters:
  `bytes` - array of column bytes that can be decoded as Numeric
  `pos` - index of the start position of the bytes array for number
  `numBytes` - number of bytes to use, length is already encoded in the binary format but this is used for double checking
  `precision` - precision of the defined column
  `scale` - scale of the defined column
Returns:
  Number value of the given unscaled byte array

#### redshiftNumeric

    public static byte[] redshiftNumeric(BigDecimal val,
                         int precision,
                         int scale)

Convert BigDecimal value into scaled bytes.

Parameters:
  `val` - BigDecimal value to be converted into bytes
  `precision` - Precision of column
  `scale` - Scale of column
Returns:
  Scaled bytes of the given BigDecimal value.

#### int8

    public static long int8(byte[] bytes,
            int idx)

Parses a long value from the byte array.

Parameters:
  `bytes` - The byte array to parse.
  `idx` - The starting index of the parse in the byte array.
Returns:
  parsed long value.

#### int4

    public static int int4(byte[] bytes,
           int idx)

Parses an int value from the byte array.

Parameters:
  `bytes` - The byte array to parse.
  `idx` - The starting index of the parse in the byte array.
Returns:
  parsed int value.

#### int2

    public static short int2(byte[] bytes,
             int idx)

Parses a short value from the byte array.

Parameters:
  `bytes` - The byte array to parse.
  `idx` - The starting index of the parse in the byte array.
Returns:
  parsed short value.

#### bool

    public static boolean bool(byte[] bytes,
               int idx)

Parses a boolean value from the byte array.

Parameters:
  `bytes` - The byte array to parse.
  `idx` - The starting index to read from bytes.
Returns:
  parsed boolean value.

#### float4

    public static float float4(byte[] bytes,
               int idx)

Parses a float value from the byte array.

Parameters:
  `bytes` - The byte array to parse.
  `idx` - The starting index of the parse in the byte array.
Returns:
  parsed float value.

#### float8

    public static double float8(byte[] bytes,
                int idx)

Parses a double value from the byte array.

Parameters:
  `bytes` - The byte array to parse.
  `idx` - The starting index of the parse in the byte array.
Returns:
  parsed double value.

#### int8

    public static void int8(byte[] target,
            int idx,
            long value)

Encodes a long value to the byte array.

Parameters:
  `target` - The byte array to encode to.
  `idx` - The starting index in the byte array.
  `value` - The value to encode.

#### int4

    public static void int4(byte[] target,
            int idx,
            int value)

Encodes a int value to the byte array.

Parameters:
  `target` - The byte array to encode to.
  `idx` - The starting index in the byte array.
  `value` - The value to encode.

#### int2

    public static void int2(byte[] target,
            int idx,
            int value)

Encodes a int value to the byte array.

Parameters:
  `target` - The byte array to encode to.
  `idx` - The starting index in the byte array.
  `value` - The value to encode.

#### bool

    public static void bool(byte[] target,
            int idx,
            boolean value)

Encodes a boolean value to the byte array.

Parameters:
  `target` - The byte array to encode to.
  `idx` - The starting index in the byte array.
  `value` - The value to encode.

#### float4

    public static void float4(byte[] target,
              int idx,
              float value)

Encodes a int value to the byte array.

Parameters:
  `target` - The byte array to encode to.
  `idx` - The starting index in the byte array.
  `value` - The value to encode.

#### float8

    public static void float8(byte[] target,
              int idx,
              double value)

Encodes a int value to the byte array.

Parameters:
  `target` - The byte array to encode to.
  `idx` - The starting index in the byte array.
  `value` - The value to encode.