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

commonMain.protokt.v1.google.rpc.status.kt Maven / Gradle / Ivy

// Generated by protokt version 1.0.0-alpha.8. Do not modify.
// Source: google/rpc/status.proto
@file:Suppress("DEPRECATION")

package protokt.v1.google.rpc

import protokt.v1.AbstractKtDeserializer
import protokt.v1.AbstractKtMessage
import protokt.v1.Collections.copyList
import protokt.v1.Collections.unmodifiableList
import protokt.v1.KtBuilderDsl
import protokt.v1.KtMessageDeserializer
import protokt.v1.KtMessageSerializer
import protokt.v1.SizeCodecs.sizeOf
import protokt.v1.UnknownFieldSet
import kotlin.Boolean
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.MutableList
import kotlin.jvm.JvmStatic
import com.toasttab.protokt.rt.KtGeneratedMessage as RtKtGeneratedMessage
import kotlin.Any as KotlinAny
import protokt.v1.KtGeneratedMessage as V1KtGeneratedMessage
import protokt.v1.google.protobuf.Any as ProtobufAny

/**
 * 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).
 */
@V1KtGeneratedMessage("google.rpc.Status")
@RtKtGeneratedMessage("google.rpc.Status")
public class Status private constructor(
  /**
   * The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
   */
  public 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.
   */
  public val message: String,
  /**
   * A list of messages that carry the error details.  There is a common set of message types for
   * APIs to use.
   */
  public val details: List,
  public val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : AbstractKtMessage() {
  override val messageSize: Int by lazy { messageSize() }

  private fun messageSize(): Int {
    var result = 0
    if (code != 0) {
      result += sizeOf(8u) + sizeOf(code)
    }
    if (message.isNotEmpty()) {
      result += sizeOf(18u) + sizeOf(message)
    }
    if (details.isNotEmpty()) {
      result += (sizeOf(26u) * details.size) + details.sumOf { sizeOf(it) }
    }
    result += unknownFields.size()
    return result
  }

  override fun serialize(serializer: KtMessageSerializer) {
    if (code != 0) {
      serializer.writeTag(8u).write(code)
    }
    if (message.isNotEmpty()) {
      serializer.writeTag(18u).write(message)
    }
    details.forEach { serializer.writeTag(26u).write(it) }
    serializer.writeUnknown(unknownFields)
  }

  override fun equals(other: KotlinAny?): 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" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

  public fun copy(builder: Builder.() -> Unit): Status =
    Builder().apply {
      code = [email protected]
      message = [email protected]
      details = [email protected]
      unknownFields = [email protected]
      builder()
    }.build()

  @KtBuilderDsl
  public class Builder {
    public var code: Int = 0

    public var message: String = ""

    public var details: List = emptyList()
      set(newValue) {
        field = copyList(newValue)
      }

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): Status =
      Status(
        code,
        message,
        unmodifiableList(details),
        unknownFields
      )
  }

  public companion object Deserializer : AbstractKtDeserializer() {
    @JvmStatic
    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,
            unmodifiableList(details),
            UnknownFieldSet.from(unknownFields)
          )
          8 -> code = deserializer.readInt32()
          18 -> message = deserializer.readString()
          26 ->
            details =
              (details ?: mutableListOf()).apply {
                deserializer.readRepeated(false) {
                  add(deserializer.readMessage(ProtobufAny))
                }
              }
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(deserializer.readUnknown())
              }
        }
      }
    }

    @JvmStatic
    public operator fun invoke(dsl: Builder.() -> Unit): Status = Builder().apply(dsl).build()
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy