protokt.com.google.rpc.status.kt Maven / Gradle / Ivy
// Generated by protokt version 0.9.0. Do not modify.
// Source: google/rpc/status.proto
package com.google.rpc
import com.toasttab.protokt.Any
import com.toasttab.protokt.rt.Int32
import com.toasttab.protokt.rt.KtDeserializer
import com.toasttab.protokt.rt.KtGeneratedMessage
import com.toasttab.protokt.rt.KtMessage
import com.toasttab.protokt.rt.KtMessageDeserializer
import com.toasttab.protokt.rt.KtMessageSerializer
import com.toasttab.protokt.rt.Tag
import com.toasttab.protokt.rt.UnknownFieldSet
import com.toasttab.protokt.rt.copyList
import com.toasttab.protokt.rt.finishList
import com.toasttab.protokt.rt.sizeof
import kotlin.Boolean
import kotlin.Int
import kotlin.String
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.MutableList
/**
* The `Status` type defines a logical error model that is suitable for different programming
* environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each
* `Status` message contains three pieces of data: error code, error message, and error details.
*
* You can find out more about this error model and how to work with it in the [API Design
* Guide](https://cloud.google.com/apis/design/errors).
*/
@KtGeneratedMessage("google.rpc.Status")
class Status private constructor(
/**
* The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
*/
val code: Int,
/**
* A developer-facing error message, which should be in English. Any user-facing error message
* should be localized and sent in the [google.rpc.Status.details][google.rpc.Status.details]
* field, or localized by the client.
*/
val message: String,
/**
* A list of messages that carry the error details. There is a common set of message types for
* APIs to use.
*/
val details: List,
val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : KtMessage {
override val messageSize: Int by lazy { messageSize() }
private fun messageSize(): Int {
var result = 0
if (code != 0) {
result += sizeof(Tag(1)) + sizeof(Int32(code))
}
if (message.isNotEmpty()) {
result += sizeof(Tag(2)) + sizeof(message)
}
if (details.isNotEmpty()) {
result += (sizeof(Tag(3)) * details.size) + details.sumOf { sizeof(it) }
}
result += unknownFields.size()
return result
}
override fun serialize(serializer: KtMessageSerializer) {
if (code != 0) {
serializer.write(Tag(8)).write(Int32(code))
}
if (message.isNotEmpty()) {
serializer.write(Tag(18)).write(message)
}
if (details.isNotEmpty()) {
details.forEach { serializer.write(Tag(26)).write(it) }
}
serializer.writeUnknown(unknownFields)
}
override fun equals(other: kotlin.Any?): Boolean = other is Status &&
other.code == code &&
other.message == message &&
other.details == details &&
other.unknownFields == unknownFields
override fun hashCode(): Int {
var result = unknownFields.hashCode()
result = 31 * result + code.hashCode()
result = 31 * result + message.hashCode()
result = 31 * result + details.hashCode()
return result
}
override fun toString(): String = "Status(" +
"code=$code, " +
"message=$message, " +
"details=$details, " +
"unknownFields=$unknownFields)"
fun copy(dsl: StatusDsl.() -> Unit): Status = Status.Deserializer {
code = [email protected]
message = [email protected]
details = [email protected]
unknownFields = [email protected]
dsl()
}
class StatusDsl {
var code: Int = 0
var message: String = ""
var details: List = emptyList()
set(newValue) {
field = copyList(newValue)
}
var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
fun build(): Status = Status(code,
message,
finishList(details),
unknownFields)
}
companion object Deserializer : KtDeserializer, (StatusDsl.() -> Unit) -> Status
{
override fun deserialize(deserializer: KtMessageDeserializer): Status {
var code = 0
var message = ""
var details : MutableList? = null
var unknownFields: UnknownFieldSet.Builder? = null
while (true) {
when(deserializer.readTag()) {
0 -> return Status(code,
message,
finishList(details),
UnknownFieldSet.from(unknownFields))
8 -> code = deserializer.readInt32()
18 -> message = deserializer.readString()
26 -> details = (details ?: mutableListOf()).apply {
deserializer.readRepeated(false) {
add(deserializer.readMessage(com.toasttab.protokt.Any))
}
}
else -> unknownFields = (unknownFields ?:
UnknownFieldSet.Builder()).also {it.add(deserializer.readUnknown()) }
}
}
}
override fun invoke(dsl: StatusDsl.() -> Unit): Status =
StatusDsl().apply(dsl).build()
}
}