Created
April 28, 2025 18:24
-
-
Save culttm/0d6b5397d6a4b0243a983f258df9c0fe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
inline fun <reified T : Message> protoFromJson(json: String): T { | |
val builder = T::class.java.getDeclaredMethod("newBuilder").invoke(null) as Message.Builder | |
JsonFormat.parser().merge(json, builder) | |
return builder.build() as T | |
} | |
inline fun <reified T : Message> protoToJson(message: T): String { | |
val builder = T::class.java.getDeclaredMethod("newBuilder", message::class.java).invoke(null, message) as Message.Builder | |
return JsonFormat.printer().print(builder) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment