in runtime/src/main/scala/org/apache/pekko/grpc/scaladsl/headers/PercentEncoding.scala [53:77]
private def isEscapingChar(b: Byte): Boolean = b < ' ' || b >= '~' || b == '%'
private def encodeSlow(valueBytes: Array[Byte], riArg: Int): String = {
var ri = riArg
val escapedBytes = new Array[Byte](riArg + ((valueBytes.length - riArg) * 3))
// copy over the good bytes
if (riArg != 0) System.arraycopy(valueBytes, 0, escapedBytes, 0, riArg)
var wi = ri
while (ri < valueBytes.length) {
val b = valueBytes(ri)
// Manually implement URL encoding, per the gRPC spec.
if (isEscapingChar(b)) {
escapedBytes.update(wi, '%')
escapedBytes.update(wi + 1, HexArr((b >> 4) & 0xF))
escapedBytes.update(wi + 2, HexArr(b & 0xF))
wi += 3
} else {
escapedBytes.update(wi, b)
wi += 1
}
ri += 1
}
new String(escapedBytes, 0, wi, StandardCharsets.US_ASCII)
}