code: public static int encode(BigInteger value, byte[] dst, int dstOffset) {
          if (value == null) {
              dst[dstOffset] = NULL_BYTE_HIGH;
              return 1;
          }
  
          byte[] bytes = value.toByteArray();
  
          // Write the byte array length first, in a variable amount of bytes.
          int amt = encodeUnsignedVarInt(bytes.length, dst, dstOffset);
  
          // Now write the byte array.
          System.arraycopy(bytes, 0, dst, dstOffset + amt, bytes.length);
  
          return amt + bytes.length;
      }
docs: Encodes the given optional BigInteger into a variable amount of
  bytes. If the BigInteger is null, exactly 1 byte is written. Otherwise,
  the amount written can be determined by calling calculateEncodedLength.
  
  @param value BigInteger value to encode, may be null
  @param dst destination for encoded bytes
  @param dstOffset offset into destination array
  @return amount of bytes written
  @since 1.2