All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bybutter.sisyphus.test.Extension.kt Maven / Gradle / Ivy

There is a newer version: 2.1.22
Show newest version
package com.bybutter.sisyphus.test

import com.bybutter.sisyphus.security.base64
import com.bybutter.sisyphus.security.base64Decode
import io.grpc.Metadata

fun Metadata.mergeFrom(data: Map): Metadata {
    for ((k, v) in data) {
        if (k.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
            put(Metadata.Key.of(k, Metadata.BINARY_BYTE_MARSHALLER), v.base64Decode())
        } else {
            put(Metadata.Key.of(k, Metadata.ASCII_STRING_MARSHALLER), v)
        }
    }
    return this
}

fun Metadata.toMap(): Map {
    val result = mutableMapOf()
    for (k in keys()) {
        if (k.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
            get(Metadata.Key.of(k, Metadata.BINARY_BYTE_MARSHALLER))?.base64()?.let {
                result[k] = it
            }
        } else {
            get(Metadata.Key.of(k, Metadata.ASCII_STRING_MARSHALLER))?.let {
                result[k] = it
            }
        }
    }
    return result
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy