Skip to content

Commit

Permalink
Migrate to CodeGeneratorRequestWriter from base
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yevsyukov committed Jun 1, 2024
1 parent 9f4c538 commit 4d7ec58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
Expand Down Expand Up @@ -45,7 +45,7 @@ object Spine {
*
* @see <a href="https://github.com/SpineEventEngine/base">spine-base</a>
*/
const val base = "2.0.0-SNAPSHOT.202"
const val base = "2.0.0-SNAPSHOT.203"

/**
* The version of [Spine.reflect].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
Expand All @@ -30,14 +30,8 @@ package io.spine.tools.prototap.protoc

import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse
import io.spine.io.replaceExtension
import io.spine.type.toJson
import java.nio.file.StandardOpenOption.CREATE
import java.nio.file.StandardOpenOption.TRUNCATE_EXISTING
import java.util.Base64
import kotlin.io.path.Path
import kotlin.io.path.writeBytes
import kotlin.io.path.writeText
import io.spine.code.proto.CodeGeneratorRequestWriter
import java.util.*
import kotlin.text.Charsets.UTF_8

/**
Expand All @@ -51,23 +45,9 @@ import kotlin.text.Charsets.UTF_8
* [protocol](https://protobuf.dev/reference/cpp/api-docs/google.protobuf.compiler.plugin.pb/).
*/
public fun main() {
val request = CodeGeneratorRequest.parseFrom(System.`in`)
val requestFile = Path(request.parameter.decodeBase64())

val targetDir = requestFile.toFile().parentFile
targetDir.mkdirs()

requestFile.writeBytes(request.toByteArray(), CREATE, TRUNCATE_EXISTING)

val requestFileInJson = requestFile.replaceExtension("pb.json")
val json = request.toJson()
requestFileInJson.writeText(json)

val writer = CodeGeneratorRequestWriter(System.`in`)
writer.writeBinary()
writer.writeJson()
val emptyResponse = CodeGeneratorResponse.getDefaultInstance()
emptyResponse.writeTo(System.out)
}

private fun String.decodeBase64(): String {
val bytes = Base64.getDecoder().decode(this)
return String(bytes, UTF_8)
}

0 comments on commit 4d7ec58

Please sign in to comment.