Implement Base64 without need of JDK8. (#78)
This commit is contained in:
+1
-8
@@ -116,14 +116,7 @@ internal interface ContextUtils {
|
||||
*/
|
||||
val String.globalHashBase64: String
|
||||
get() {
|
||||
val bytes = this.toByteArray(Charsets.UTF_8)
|
||||
val hashBytes = this.globalHashBytes
|
||||
|
||||
val base64Bytes = java.util.Base64.getEncoder().encode(globalHashBytes)
|
||||
// TODO: do not use JRE for base64
|
||||
// (it is impossible right now due to native interop limitations)
|
||||
|
||||
return String(base64Bytes, Charsets.US_ASCII)
|
||||
return base64Encode(globalHashBytes)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
@@ -21,4 +21,15 @@ internal fun globalHash(data: ByteArray, retValPlacement: Placement): GlobalHash
|
||||
return res
|
||||
}
|
||||
|
||||
internal fun base64Encode(data: ByteArray): String {
|
||||
memScoped {
|
||||
val resultSize = 4 * data.size / 3 + 3 + 1
|
||||
val result = alloc(NativeArray of Int8Box length resultSize)
|
||||
val bytes = allocNativeArrayOf(data)
|
||||
Base64Encode(bytes.ptr, data.size, result.ptr, resultSize)
|
||||
// TODO: any better way to do that without two copies?
|
||||
return CString.fromArray(result).toString()
|
||||
}
|
||||
}
|
||||
|
||||
internal class LocalHash(val value: Long) : ConstValue by Int64(value)
|
||||
|
||||
Reference in New Issue
Block a user