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

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

// Generated by protokt version 1.0.0-alpha.8. Do not modify.
// Source: google/api/context.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.unmodifiableList
import protokt.v1.KtBuilderDsl
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.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 protokt.v1.KtGeneratedMessage as V1KtGeneratedMessage

/**
 * `Context` defines which contexts an API requests.
 *
 *  Example:
 *
 *      context:       rules:       - selector: "*"         requested:         -
 * google.rpc.context.ProjectContext         - google.rpc.context.OriginContext
 *
 *  The above specifies that all methods in the API request `google.rpc.context.ProjectContext` and
 * `google.rpc.context.OriginContext`.
 *
 *  Available context types are defined in package `google.rpc.context`.
 *
 *  This also provides mechanism to allowlist any protobuf message extension that can be sent in
 * grpc metadata using “x-goog-ext--bin” and “x-goog-ext--jspb” format. For
 * example, list any service specific protobuf types that can appear in grpc metadata as follows in
 * your yaml file:
 *
 *  Example:
 *
 *      context:       rules:        - selector:
 * "google.example.library.v1.LibraryService.CreateBook"
 * allowed_request_extensions:          - google.foo.v1.NewExtension
 * allowed_response_extensions:          - google.foo.v1.NewExtension
 *
 *  You can also specify extension ID instead of fully qualified extension name here.
 */
@V1KtGeneratedMessage("google.api.Context")
@RtKtGeneratedMessage("google.api.Context")
public class Context private constructor(
  /**
   * A list of RPC context 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 Context &&
      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 =
    "Context(" +
      "rules=$rules" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

  public fun copy(builder: Builder.() -> Unit): Context =
    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(): Context =
      Context(
        unmodifiableList(rules),
        unknownFields
      )
  }

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

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

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

/**
 * A context rule provides information about the context for an individual API element.
 */
@V1KtGeneratedMessage("google.api.ContextRule")
@RtKtGeneratedMessage("google.api.ContextRule")
public class ContextRule private constructor(
  /**
   * Selects the methods to which this rule applies.
   *
   *  Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
   */
  public val selector: String,
  /**
   * A list of full type names of requested contexts.
   */
  public val requested: List,
  /**
   * A list of full type names of provided contexts.
   */
  public val provided: List,
  /**
   * A list of full type names or extension IDs of extensions allowed in grpc side channel from
   * client to backend.
   */
  public val allowedRequestExtensions: List,
  /**
   * A list of full type names or extension IDs of extensions allowed in grpc side channel from
   * backend to client.
   */
  public val allowedResponseExtensions: List,
  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 (requested.isNotEmpty()) {
      result += (sizeOf(18u) * requested.size) + requested.sumOf { sizeOf(it) }
    }
    if (provided.isNotEmpty()) {
      result += (sizeOf(26u) * provided.size) + provided.sumOf { sizeOf(it) }
    }
    if (allowedRequestExtensions.isNotEmpty()) {
      result += (sizeOf(34u) * allowedRequestExtensions.size) +
        allowedRequestExtensions.sumOf { sizeOf(it) }
    }
    if (allowedResponseExtensions.isNotEmpty()) {
      result += (sizeOf(42u) * allowedResponseExtensions.size) +
        allowedResponseExtensions.sumOf { sizeOf(it) }
    }
    result += unknownFields.size()
    return result
  }

  override fun serialize(serializer: KtMessageSerializer) {
    if (selector.isNotEmpty()) {
      serializer.writeTag(10u).write(selector)
    }
    requested.forEach { serializer.writeTag(18u).write(it) }
    provided.forEach { serializer.writeTag(26u).write(it) }
    allowedRequestExtensions.forEach { serializer.writeTag(34u).write(it) }
    allowedResponseExtensions.forEach { serializer.writeTag(42u).write(it) }
    serializer.writeUnknown(unknownFields)
  }

  override fun equals(other: Any?): Boolean =
    other is ContextRule &&
      other.selector == selector &&
      other.requested == requested &&
      other.provided == provided &&
      other.allowedRequestExtensions == allowedRequestExtensions &&
      other.allowedResponseExtensions == allowedResponseExtensions &&
      other.unknownFields == unknownFields

  override fun hashCode(): Int {
    var result = unknownFields.hashCode()
    result = 31 * result + selector.hashCode()
    result = 31 * result + requested.hashCode()
    result = 31 * result + provided.hashCode()
    result = 31 * result + allowedRequestExtensions.hashCode()
    result = 31 * result + allowedResponseExtensions.hashCode()
    return result
  }

  override fun toString(): String =
    "ContextRule(" +
      "selector=$selector, " +
      "requested=$requested, " +
      "provided=$provided, " +
      "allowedRequestExtensions=$allowedRequestExtensions, " +
      "allowedResponseExtensions=$allowedResponseExtensions" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

  public fun copy(builder: Builder.() -> Unit): ContextRule =
    Builder().apply {
      selector = [email protected]
      requested = [email protected]
      provided = [email protected]
      allowedRequestExtensions = [email protected]
      allowedResponseExtensions = [email protected]
      unknownFields = [email protected]
      builder()
    }.build()

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

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

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

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

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

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): ContextRule =
      ContextRule(
        selector,
        unmodifiableList(requested),
        unmodifiableList(provided),
        unmodifiableList(allowedRequestExtensions),
        unmodifiableList(allowedResponseExtensions),
        unknownFields
      )
  }

  public companion object Deserializer : AbstractKtDeserializer() {
    @JvmStatic
    override fun deserialize(deserializer: KtMessageDeserializer): ContextRule {
      var selector = ""
      var requested: MutableList? = null
      var provided: MutableList? = null
      var allowedRequestExtensions: MutableList? = null
      var allowedResponseExtensions: MutableList? = null
      var unknownFields: UnknownFieldSet.Builder? = null

      while (true) {
        when (deserializer.readTag()) {
          0 -> return ContextRule(
            selector,
            unmodifiableList(requested),
            unmodifiableList(provided),
            unmodifiableList(allowedRequestExtensions),
            unmodifiableList(allowedResponseExtensions),
            UnknownFieldSet.from(unknownFields)
          )
          10 -> selector = deserializer.readString()
          18 ->
            requested =
              (requested ?: mutableListOf()).apply {
                deserializer.readRepeated(false) {
                  add(deserializer.readString())
                }
              }
          26 ->
            provided =
              (provided ?: mutableListOf()).apply {
                deserializer.readRepeated(false) {
                  add(deserializer.readString())
                }
              }
          34 ->
            allowedRequestExtensions =
              (allowedRequestExtensions ?: mutableListOf()).apply {
                deserializer.readRepeated(false) {
                  add(deserializer.readString())
                }
              }
          42 ->
            allowedResponseExtensions =
              (allowedResponseExtensions ?: mutableListOf()).apply {
                deserializer.readRepeated(false) {
                  add(deserializer.readString())
                }
              }
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(deserializer.readUnknown())
              }
        }
      }
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy