public static void writeToByteStream(
      RandomAccessOutput byteStream,
      HiveDecimal dec,
      long[] scratchLongs, byte[] scratchBytes, byte[] scratchLongBytes) {
    LazyBinaryUtils.writeVInt(byteStream, dec.scale(), scratchLongBytes);

    // Convert decimal into the scratch buffer without allocating a byte[] each time
    // for better performance.
    int byteLength = 
        dec.bigIntegerBytes(
            scratchLongs, scratchBytes);
    if (byteLength == 0) {
      throw new RuntimeException("Decimal to binary conversion failed");
    }
    LazyBinaryUtils.writeVInt(byteStream, byteLength, scratchLongBytes);
    byteStream.write(scratchBytes, 0, byteLength);
  }
Allocate scratchLongs with HiveDecimal.SCRATCH_LONGS_LEN longs.
And, allocate scratch buffer with HiveDecimal.SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES bytes.

@param byteStream
@param dec
@param scratchLongs
@param scratchBytes
@param scratchLongBytes
serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java