@HiveDecimalWritableVersionV2
  public void write(
      DataOutput out,
      long[] scratchLongs, byte[] scratchBuffer) throws IOException {
    if (!isSet()) {
      throw new RuntimeException("no value set");
    }

    WritableUtils.writeVInt(out, fastScale());

    int byteLength =
        fastBigIntegerBytes(
            scratchLongs, scratchBuffer);
    if (byteLength == 0) {
      throw new RuntimeException("Couldn't convert decimal to binary");
    }

    WritableUtils.writeVInt(out, byteLength);
    out.write(scratchBuffer, 0, byteLength);
  }
A variation of the standard Writable method that serialize the fields of this object to a
DataOutput with scratch buffers for good performance.
<p>
Allocate scratchLongs with HiveDecimal.SCRATCH_LONGS_LEN longs.
And, allocate scratch buffer with HiveDecimal.SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES bytes.
storage-api/src/java/org/apache/hadoop/hive/serde2/io/HiveDecimalWritable.java