This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Base64Codecs { | |
private val base64Encoder = Base64.getEncoder | |
private val base64Decoder = Base64.getDecoder | |
private def toBase64String(bytes: Array[Byte]): String = { | |
base64Encoder.encodeToString(bytes) | |
} | |
private def parseBase64String(s: String): Array[Byte] = { | |
base64Decoder.decode(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ByteStringConverters { | |
implicit val DefaultByteOrder = ByteOrder.BIG_ENDIAN | |
implicit class UUIDWithToByteString(uuid: UUID) { | |
def toByteString = ByteString( | |
ByteBuffer | |
.allocate(16) | |
.putLong(uuid.getMostSignificantBits) | |
.putLong(8, uuid.getLeastSignificantBits) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object HexCodecs { | |
private def parseHexChar(c: Char): Int = { | |
val b = | |
if (c >= '0' && c <= '9') | |
c - '0' | |
else if (c >= 'a' && c <= 'f') | |
(c - 'a') + 10 | |
else if (c >= 'A' && c <= 'F') | |
(c - 'A') + 10 | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.UUID | |
import java.nio.ByteBuffer | |
object UuidConverters { | |
implicit class BigIntToUuid(v: BigInt) { | |
def toUuid: UUID = { | |
val bb: ByteBuffer = ByteBuffer.wrap(v.toByteArray) | |
val high: Long = bb.getLong | |
val low: Long = bb.getLong | |
new UUID(high, low) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.slf4j.MDC; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.function.*; | |
public final class DiagnosticsContext { | |
private final Map<String, String> context = new HashMap<>(); |