Encodes 64 or 128 bits from the input into a hex trace ID.

@param high Upper 64bits of the trace ID. Zero means the trace ID is 64-bit.
@param low Lower 64bits of the trace ID.
@throws IllegalArgumentException if both values are zero
320832
public Builder traceId(long high, long low) {
      if (high == 0L && low == 0L) throw new IllegalArgumentException("empty trace ID");
      char[] result = new char[high != 0L ? 32 : 16];
      int pos = 0;
      if (high != 0L) {
        writeHexLong(result, pos, high);
        pos += 16;
      }
      writeHexLong(result, pos, low);
      this.traceId = new String(result);
      return this;
    }
96600
function () {

			var low, high;

			if ( this.littleEndian ) {

				low = this.getUint32();
				high = this.getUint32();

			} else {

				high = this.getUint32();
				low = this.getUint32();

			}

			return high * 0x100000000 + low;

		}
1174598
static final String toHex(final byte[] input, final int len, final boolean upper) {
		final char[] hex = new char[len << 1];
		for (int i = 0, j = 0; i < len; i++) {
			final int bx = input[i];
			final int bh = ((bx >> 4) & 0xF);
			final int bl = (bx & 0xF);
			if ((bh >= 0) && (bh <= 9)) {
				hex[j++] |= (bh + '0');
			} else if ((bh >= 0xA) && (bh <= 0xF)) {
				hex[j++] |= (bh - 0xA + (upper ? 'A' : 'a'));
			}
			if ((bl >= 0x0) && (bl <= 0x9)) {
				hex[j++] |= (bl + '0');
			} else if ((bl >= 0xA) && (bl <= 0xF)) {
				hex[j++] |= (bl - 0xA + (upper ? 'A' : 'a'));
			}
		}
		return new String(hex);
	}
192021
public static void writeUnsignedIntegerLittleEndian(ByteBuffer io, long value) {
		io.put((byte)(value & 0xFF));
		io.put((byte)((value >> 8) & 0xFF));
		io.put((byte)((value >> 16) & 0xFF));
		io.put((byte)((value >> 24) & 0xFF));
	}
1042287
public static byte highestOneBit(final long v) {
    final long h = Long.highestOneBit(v);
    if (0 == v) {
      return 0;
    }
    for (byte i = 0; i < 64; i++) {
      if (h == 1l << i) {
        return (byte) (i + 1);
      }
    }
    throw new RuntimeException();
  }
1024944
private static int hi0bits(int x)
    {
        int k = 0;

        if ((x & 0xffff0000) == 0) {
            k = 16;
            x <<= 16;
        }
        if ((x & 0xff000000) == 0) {
            k += 8;
            x <<= 8;
        }
        if ((x & 0xf0000000) == 0) {
            k += 4;
            x <<= 4;
        }
        if ((x & 0xc0000000) == 0) {
            k += 2;
            x <<= 2;
        }
        if ((x & 0x80000000) == 0) {
            k++;
            if ((x & 0x40000000) == 0)
                return 32;
        }
        return k;
    }
1275635
private static String toPaddedHex(long n) {
        String hexValue = Long.toHexString(n);
        hexValue = upperCaseHex(hexValue);
        String paddedHexValue = hexValue.length() <= 12 ? ZEROES.substring(hexValue.length()) + hexValue : hexValue;
        return paddedHexValue;
    }
725784
public static void writeInt64LE(final long value, final byte[] buffer, int offset)
    {
        buffer[offset++] = (byte) (value >>> 0);
        buffer[offset++] = (byte) (value >>> 8);
        buffer[offset++] = (byte) (value >>> 16);
        buffer[offset++] = (byte) (value >>> 24);
        buffer[offset++] = (byte) (value >>> 32);
        buffer[offset++] = (byte) (value >>> 40);
        buffer[offset++] = (byte) (value >>> 48);
        buffer[offset] = (byte) (value >>> 56);
    }
815825
private static void encodeInteger(ByteBuf out, int mask, int n, long i) {
        assert n >= 0 && n <= 8 : "N: " + n;
        int nbits = 0xFF >>> (8 - n);
        if (i < nbits) {
            out.writeByte((int) (mask | i));
        } else {
            out.writeByte(mask | nbits);
            long length = i - nbits;
            for (; (length & ~0x7F) != 0; length >>>= 7) {
                out.writeByte((int) ((length & 0x7F) | 0x80));
            }
            out.writeByte((int) length);
        }
    }
736696
public static byte[] encodeInteger(BigInteger bigInt) {
        if (bigInt == null) {
            throw new NullPointerException("encodeInteger called with null parameter");
        }
        return encodeBase64(toIntegerBytes(bigInt), false);
    }
1047932
public static byte[] hexToBytes(char[] hex)
    {
        int length = hex.length / 2;
        byte[] raw = new byte[length];
        for (int i = 0; i < length; i++)
        {
            int high = Character.digit(hex[i * 2], 16);
            int low = Character.digit(hex[i * 2 + 1], 16);
            int value = (high << 4) | low;
            if (value > 127)
            {
                value -= 256;
            }
            raw[i] = (byte) value;
        }
        return raw;
    }
1264267
public void writeRawLittleEndian64(final long value) throws IOException {
    writeRawByte((int)(value      ) & 0xFF);
    writeRawByte((int)(value >>  8) & 0xFF);
    writeRawByte((int)(value >> 16) & 0xFF);
    writeRawByte((int)(value >> 24) & 0xFF);
    writeRawByte((int)(value >> 32) & 0xFF);
    writeRawByte((int)(value >> 40) & 0xFF);
    writeRawByte((int)(value >> 48) & 0xFF);
    writeRawByte((int)(value >> 56) & 0xFF);
  }
646162
public void writeUInt64(final int fieldNumber, final long value)
                          throws IOException {
    writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
    writeUInt64NoTag(value);
  }
1046597
private String encodeBase64(byte[] bytes) {
        Objects.requireNonNull(bytes, Required.BYTES.toString());
        return org.apache.commons.codec.binary.Base64.encodeBase64String(bytes);
    }
436666
public static String base64Encode(byte[] bytes) {
    if (bytes == null) {
      throw new IllegalArgumentException("Input bytes must not be null.");
    }
    if (bytes.length >= BASE64_UPPER_BOUND) {
      throw new IllegalArgumentException(
          "Input bytes length must not exceed " + BASE64_UPPER_BOUND);
    }

    // Every three bytes is encoded into four characters.
    //
    // Example:
    //           input |0 1 0 1 0 0 1 0|0 1 1 0 1 1 1 1|0 1 1 0 0 0 1 0|
    // encode grouping |0 1 0 1 0 0|1 0 0 1 1 0|1 1 1 1 0 1|1 0 0 0 1 0|
    //   encoded ascii |     U     |     m     |     9     |     i     |

    int triples = bytes.length / 3;

    // If the number of input bytes is not a multiple of three, padding characters will be added.
    if (bytes.length % 3 != 0) {
      triples += 1;
    }

    // The encoded string will have four characters for every three bytes.
    char[] encoding = new char[triples << 2];

    for (int in = 0, out = 0; in < bytes.length; in += 3, out += 4) {
      int triple = (bytes[in] & 0xff) << 16;
      if (in + 1 < bytes.length) {
        triple |= ((bytes[in + 1] & 0xff) << 8);
      }
      if (in + 2 < bytes.length) {
        triple |= (bytes[in + 2] & 0xff);
      }
      encoding[out] = BASE64_CHARS.charAt((triple >> 18) & 0x3f);
      encoding[out + 1] = BASE64_CHARS.charAt((triple >> 12) & 0x3f);
      encoding[out + 2] = BASE64_CHARS.charAt((triple >> 6) & 0x3f);
      encoding[out + 3] = BASE64_CHARS.charAt(triple & 0x3f);
    }

    // Add padding characters if needed.
    for (int i = encoding.length - (triples * 3 - bytes.length); i < encoding.length; i++) {
      encoding[i] = '=';
    }

    return String.valueOf(encoding);
  }
996883
public void write8BE(final long n) {
        write((byte) (n >> 56 & 0xff));
        write((byte) (n >> 48 & 0xff));
        write((byte) (n >> 40 & 0xff));
        write((byte) (n >> 32 & 0xff));
        write((byte) (n >> 24 & 0xff));
        write((byte) (n >> 16 & 0xff));
        write((byte) (n >> 8 & 0xff));
        write((byte) (n & 0xff));
    }
409186
protected String zeroPaddingNumber(long value, int minDigits, int maxDigits)
    {
        numberFormat.setMinimumIntegerDigits(minDigits);
        numberFormat.setMaximumIntegerDigits(maxDigits);
        return numberFormat.format(value);
    }