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

commonMain.protokt.v1.google.api.backend.kt Maven / Gradle / Ivy

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

package protokt.v1.google.api

import protokt.v1.AbstractKtDeserializer
import protokt.v1.AbstractKtMessage
import protokt.v1.Collections.copyList
import protokt.v1.Collections.copyMap
import protokt.v1.Collections.unmodifiableList
import protokt.v1.Collections.unmodifiableMap
import protokt.v1.KtBuilderDsl
import protokt.v1.KtEnum
import protokt.v1.KtEnumDeserializer
import protokt.v1.KtMessageDeserializer
import protokt.v1.KtMessageSerializer
import protokt.v1.SizeCodecs.sizeOf
import protokt.v1.UnknownFieldSet
import kotlin.Any
import kotlin.Boolean
import kotlin.Deprecated
import kotlin.Double
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.Map
import kotlin.collections.MutableList
import kotlin.collections.MutableMap
import kotlin.jvm.JvmStatic
import com.toasttab.protokt.rt.KtGeneratedMessage as RtKtGeneratedMessage
import protokt.v1.KtGeneratedMessage as V1KtGeneratedMessage

/**
 * `Backend` defines the backend configuration for a service.
 */
@V1KtGeneratedMessage("google.api.Backend")
@RtKtGeneratedMessage("google.api.Backend")
public class Backend private constructor(
  /**
   * A list of API backend rules that apply to individual API methods.
   *
   *  **NOTE:** All service configuration rules follow "last one wins" order.
   */
  public val rules: List,
  public val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : AbstractKtMessage() {
  override val messageSize: Int by lazy { messageSize() }

  private fun messageSize(): Int {
    var result = 0
    if (rules.isNotEmpty()) {
      result += (sizeOf(10u) * rules.size) + rules.sumOf { sizeOf(it) }
    }
    result += unknownFields.size()
    return result
  }

  override fun serialize(serializer: KtMessageSerializer) {
    rules.forEach { serializer.writeTag(10u).write(it) }
    serializer.writeUnknown(unknownFields)
  }

  override fun equals(other: Any?): Boolean =
    other is Backend &&
      other.rules == rules &&
      other.unknownFields == unknownFields

  override fun hashCode(): Int {
    var result = unknownFields.hashCode()
    result = 31 * result + rules.hashCode()
    return result
  }

  override fun toString(): String =
    "Backend(" +
      "rules=$rules" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

  public fun copy(builder: Builder.() -> Unit): Backend =
    Builder().apply {
      rules = [email protected]
      unknownFields = [email protected]
      builder()
    }.build()

  @KtBuilderDsl
  public class Builder {
    public var rules: List = emptyList()
      set(newValue) {
        field = copyList(newValue)
      }

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): Backend =
      Backend(
        unmodifiableList(rules),
        unknownFields
      )
  }

  public companion object Deserializer : AbstractKtDeserializer() {
    @JvmStatic
    override fun deserialize(deserializer: KtMessageDeserializer): Backend {
      var rules: MutableList? = null
      var unknownFields: UnknownFieldSet.Builder? = null

      while (true) {
        when (deserializer.readTag()) {
          0 -> return Backend(
            unmodifiableList(rules),
            UnknownFieldSet.from(unknownFields)
          )
          10 ->
            rules =
              (rules ?: mutableListOf()).apply {
                deserializer.readRepeated(false) {
                  add(deserializer.readMessage(BackendRule))
                }
              }
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(deserializer.readUnknown())
              }
        }
      }
    }

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

/**
 * A backend rule provides configuration for an individual API element.
 */
@V1KtGeneratedMessage("google.api.BackendRule")
@RtKtGeneratedMessage("google.api.BackendRule")
public class BackendRule private constructor(
  /**
   * Selects the methods to which this rule applies.
   *
   *  Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
   */
  public val selector: String,
  /**
   * The address of the API backend.
   *
   *  The scheme is used to determine the backend protocol and security. The following schemes are
   * accepted:
   *
   *     SCHEME        PROTOCOL    SECURITY    http://       HTTP        None    https://      HTTP
   *       TLS    grpc://       gRPC        None    grpcs://      gRPC        TLS
   *
   *  It is recommended to explicitly include a scheme. Leaving out the scheme may cause
   * constrasting behaviors across platforms.
   *
   *  If the port is unspecified, the default is: - 80 for schemes without TLS - 443 for schemes
   * with TLS
   *
   *  For HTTP backends, use [protocol][google.api.BackendRule.protocol] to specify the protocol
   * version.
   */
  public val address: String,
  /**
   * The number of seconds to wait for a response from a request. The default varies based on the
   * request protocol and deployment environment.
   */
  public val deadline: Double,
  /**
   * Deprecated, do not use.
   */
  @Deprecated("deprecated in proto")
  public val minDeadline: Double,
  /**
   * The number of seconds to wait for the completion of a long running operation. The default is no
   * deadline.
   */
  public val operationDeadline: Double,
  public val pathTranslation: PathTranslation,
  /**
   * Authentication settings used by the backend.
   *
   *  These are typically used to provide service management functionality to a backend served on a
   * publicly-routable URL. The `authentication` details should match the authentication behavior used
   * by the backend.
   *
   *  For example, specifying `jwt_audience` implies that the backend expects authentication via a
   * JWT.
   *
   *  When authentication is unspecified, the resulting behavior is the same as `disable_auth` set
   * to `true`.
   *
   *  Refer to https://developers.google.com/identity/protocols/OpenIDConnect for JWT ID token.
   */
  public val authentication: Authentication?,
  /**
   * The protocol used for sending a request to the backend. The supported values are "http/1.1" and
   * "h2".
   *
   *  The default value is inferred from the scheme in the [address][google.api.BackendRule.address]
   * field:
   *
   *     SCHEME        PROTOCOL    http://       http/1.1    https://      http/1.1    grpc://
   * h2    grpcs://      h2
   *
   *  For secure HTTP backends (https://) that support HTTP/2, set this field to "h2" for improved
   * performance.
   *
   *  Configuring this field to non-default values is only supported for secure HTTP backends. This
   * field will be ignored for all other backends.
   *
   *  See
   * https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids
   * for more details on the supported values.
   */
  public val protocol: String,
  /**
   * The map between request protocol and the backend address.
   */
  public val overridesByRequestProtocol: Map,
  public val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : AbstractKtMessage() {
  override val messageSize: Int by lazy { messageSize() }

  private fun messageSize(): Int {
    var result = 0
    if (selector.isNotEmpty()) {
      result += sizeOf(10u) + sizeOf(selector)
    }
    if (address.isNotEmpty()) {
      result += sizeOf(18u) + sizeOf(address)
    }
    if (deadline != 0.0) {
      result += sizeOf(25u) + 8
    }
    if (minDeadline != 0.0) {
      result += sizeOf(33u) + 8
    }
    if (operationDeadline != 0.0) {
      result += sizeOf(41u) + 8
    }
    if (pathTranslation.value != 0) {
      result += sizeOf(48u) + sizeOf(pathTranslation)
    }
    when (authentication) {
      is Authentication.JwtAudience ->
        result += sizeOf(58u) + sizeOf(authentication.jwtAudience)
      is Authentication.DisableAuth ->
        result += sizeOf(64u) + 1
      null -> Unit
    }
    if (protocol.isNotEmpty()) {
      result += sizeOf(74u) + sizeOf(protocol)
    }
    if (overridesByRequestProtocol.isNotEmpty()) {
      result +=
        sizeOf(overridesByRequestProtocol, 82u) { k, v ->
          OverridesByRequestProtocolEntry.entrySize(k, v)
        }
    }
    result += unknownFields.size()
    return result
  }

  override fun serialize(serializer: KtMessageSerializer) {
    if (selector.isNotEmpty()) {
      serializer.writeTag(10u).write(selector)
    }
    if (address.isNotEmpty()) {
      serializer.writeTag(18u).write(address)
    }
    if (deadline != 0.0) {
      serializer.writeTag(25u).write(deadline)
    }
    if (minDeadline != 0.0) {
      serializer.writeTag(33u).write(minDeadline)
    }
    if (operationDeadline != 0.0) {
      serializer.writeTag(41u).write(operationDeadline)
    }
    if (pathTranslation.value != 0) {
      serializer.writeTag(48u).write(pathTranslation)
    }
    when (authentication) {
      is Authentication.JwtAudience ->
        serializer.writeTag(58u).write(authentication.jwtAudience)
      is Authentication.DisableAuth ->
        serializer.writeTag(64u).write(authentication.disableAuth)
      null -> Unit
    }
    if (protocol.isNotEmpty()) {
      serializer.writeTag(74u).write(protocol)
    }
    overridesByRequestProtocol.entries.forEach {
      serializer.writeTag(82u).write(OverridesByRequestProtocolEntry(it.key, it.value))
    }
    serializer.writeUnknown(unknownFields)
  }

  override fun equals(other: Any?): Boolean =
    other is BackendRule &&
      other.selector == selector &&
      other.address == address &&
      other.deadline == deadline &&
      other.minDeadline == minDeadline &&
      other.operationDeadline == operationDeadline &&
      other.pathTranslation == pathTranslation &&
      other.authentication == authentication &&
      other.protocol == protocol &&
      other.overridesByRequestProtocol == overridesByRequestProtocol &&
      other.unknownFields == unknownFields

  override fun hashCode(): Int {
    var result = unknownFields.hashCode()
    result = 31 * result + selector.hashCode()
    result = 31 * result + address.hashCode()
    result = 31 * result + deadline.hashCode()
    result = 31 * result + minDeadline.hashCode()
    result = 31 * result + operationDeadline.hashCode()
    result = 31 * result + pathTranslation.hashCode()
    result = 31 * result + authentication.hashCode()
    result = 31 * result + protocol.hashCode()
    result = 31 * result + overridesByRequestProtocol.hashCode()
    return result
  }

  override fun toString(): String =
    "BackendRule(" +
      "selector=$selector, " +
      "address=$address, " +
      "deadline=$deadline, " +
      "minDeadline=$minDeadline, " +
      "operationDeadline=$operationDeadline, " +
      "pathTranslation=$pathTranslation, " +
      "authentication=$authentication, " +
      "protocol=$protocol, " +
      "overridesByRequestProtocol=$overridesByRequestProtocol" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

  public fun copy(builder: Builder.() -> Unit): BackendRule =
    Builder().apply {
      selector = [email protected]
      address = [email protected]
      deadline = [email protected]
      minDeadline = [email protected]
      operationDeadline = [email protected]
      pathTranslation = [email protected]
      authentication = [email protected]
      protocol = [email protected]
      overridesByRequestProtocol = [email protected]
      unknownFields = [email protected]
      builder()
    }.build()

  public sealed class Authentication {
    /**
     * The JWT audience is used when generating a JWT ID token for the backend. This ID token will
     * be added in the HTTP "authorization" header, and sent to the backend.
     */
    public data class JwtAudience(
      public val jwtAudience: String
    ) : Authentication()

    /**
     * When disable_auth is true, a JWT ID token won't be generated and the original "Authorization"
     * HTTP header will be preserved. If the header is used to carry the original token and is expected
     * by the backend, this field must be set to true to preserve the header.
     */
    public data class DisableAuth(
      public val disableAuth: Boolean
    ) : Authentication()
  }

  @KtBuilderDsl
  public class Builder {
    public var selector: String = ""

    public var address: String = ""

    public var deadline: Double = 0.0

    @Deprecated("deprecated in proto")
    public var minDeadline: Double = 0.0

    public var operationDeadline: Double = 0.0

    public var pathTranslation: PathTranslation = PathTranslation.from(0)

    public var authentication: Authentication? = null

    public var protocol: String = ""

    public var overridesByRequestProtocol: Map = emptyMap()
      set(newValue) {
        field = copyMap(newValue)
      }

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): BackendRule =
      BackendRule(
        selector,
        address,
        deadline,
        minDeadline,
        operationDeadline,
        pathTranslation,
        authentication,
        protocol,
        unmodifiableMap(overridesByRequestProtocol),
        unknownFields
      )
  }

  public companion object Deserializer : AbstractKtDeserializer() {
    @JvmStatic
    override fun deserialize(deserializer: KtMessageDeserializer): BackendRule {
      var selector = ""
      var address = ""
      var deadline = 0.0
      var minDeadline = 0.0
      var operationDeadline = 0.0
      var pathTranslation = PathTranslation.from(0)
      var authentication: Authentication? = null
      var protocol = ""
      var overridesByRequestProtocol: MutableMap? = null
      var unknownFields: UnknownFieldSet.Builder? = null

      while (true) {
        when (deserializer.readTag()) {
          0 -> return BackendRule(
            selector,
            address,
            deadline,
            minDeadline,
            operationDeadline,
            pathTranslation,
            authentication,
            protocol,
            unmodifiableMap(overridesByRequestProtocol),
            UnknownFieldSet.from(unknownFields)
          )
          10 -> selector = deserializer.readString()
          18 -> address = deserializer.readString()
          25 -> deadline = deserializer.readDouble()
          33 -> minDeadline = deserializer.readDouble()
          41 -> operationDeadline = deserializer.readDouble()
          48 -> pathTranslation = deserializer.readEnum(PathTranslation)
          58 -> authentication = Authentication.JwtAudience(deserializer.readString())
          64 -> authentication = Authentication.DisableAuth(deserializer.readBool())
          74 -> protocol = deserializer.readString()
          82 ->
            overridesByRequestProtocol =
              (overridesByRequestProtocol ?: mutableMapOf()).apply {
                deserializer.readRepeated(false) {
                  deserializer.readMessage(OverridesByRequestProtocolEntry).let {
                    put(it.key, it.value)
                  }
                }
              }
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(deserializer.readUnknown())
              }
        }
      }
    }

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

  /**
   * Path Translation specifies how to combine the backend address with the request path in order to
   * produce the appropriate forwarding URL for the request.
   *
   *  Path Translation is applicable only to HTTP-based backends. Backends which do not accept
   * requests over HTTP/HTTPS should leave `path_translation` unspecified.
   */
  public sealed class PathTranslation(
    override val `value`: Int,
    override val name: String
  ) : KtEnum() {
    public object PATH_TRANSLATION_UNSPECIFIED : PathTranslation(0, "PATH_TRANSLATION_UNSPECIFIED")

    /**
     * Use the backend address as-is, with no modification to the path. If the URL pattern contains
     * variables, the variable names and values will be appended to the query string. If a query string
     * parameter and a URL pattern variable have the same name, this may result in duplicate keys in
     * the query string.
     *
     *  # Examples
     *
     *  Given the following operation config:
     *
     *      Method path:        /api/company/{cid}/user/{uid}     Backend address:
     * https://example.cloudfunctions.net/getUser
     *
     *  Requests to the following request paths will call the backend at the translated path:
     *
     *      Request path: /api/company/widgetworks/user/johndoe     Translated:
     * https://example.cloudfunctions.net/getUser?cid=widgetworks&uid=johndoe
     *
     *      Request path: /api/company/widgetworks/user/johndoe?timezone=EST     Translated:
     * https://example.cloudfunctions.net/getUser?timezone=EST&cid=widgetworks&uid=johndoe
     */
    public object CONSTANT_ADDRESS : PathTranslation(1, "CONSTANT_ADDRESS")

    /**
     * The request path will be appended to the backend address.
     *
     *  # Examples
     *
     *  Given the following operation config:
     *
     *      Method path:        /api/company/{cid}/user/{uid}     Backend address:
     * https://example.appspot.com
     *
     *  Requests to the following request paths will call the backend at the translated path:
     *
     *      Request path: /api/company/widgetworks/user/johndoe     Translated:
     * https://example.appspot.com/api/company/widgetworks/user/johndoe
     *
     *      Request path: /api/company/widgetworks/user/johndoe?timezone=EST     Translated:
     * https://example.appspot.com/api/company/widgetworks/user/johndoe?timezone=EST
     */
    public object APPEND_PATH_TO_ADDRESS : PathTranslation(2, "APPEND_PATH_TO_ADDRESS")

    public class UNRECOGNIZED(
      `value`: Int
    ) : PathTranslation(value, "UNRECOGNIZED")

    public companion object Deserializer : KtEnumDeserializer {
      override fun from(`value`: Int): PathTranslation =
        when (value) {
          0 -> PATH_TRANSLATION_UNSPECIFIED
          1 -> CONSTANT_ADDRESS
          2 -> APPEND_PATH_TO_ADDRESS
          else -> UNRECOGNIZED(value)
        }
    }
  }

  private class OverridesByRequestProtocolEntry(
    public val key: String,
    public val `value`: BackendRule
  ) : AbstractKtMessage() {
    override val messageSize: Int
      get() = entrySize(key, value)

    override fun serialize(serializer: KtMessageSerializer) {
      serializer.writeTag(10u).write(key)
      serializer.writeTag(18u).write(`value`)
    }

    public companion object Deserializer : AbstractKtDeserializer() {
      public fun entrySize(
        key: String,
        `value`: BackendRule
      ): Int =
        sizeOf(10u) + sizeOf(key) +
          sizeOf(18u) + sizeOf(`value`)

      override fun deserialize(deserializer: KtMessageDeserializer): OverridesByRequestProtocolEntry {
        var key = ""
        var value: BackendRule? = null

        while (true) {
          when (deserializer.readTag()) {
            0 -> return OverridesByRequestProtocolEntry(key, value ?: BackendRule {})
            10 -> key = deserializer.readString()
            18 -> value = deserializer.readMessage(BackendRule)
          }
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy