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

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

The newest version!
// Generated by protokt version 1.0.0-beta.2. Do not modify.
// Source: google/api/quota.proto
@file:Suppress("DEPRECATION")

package protokt.v1.google.api

import protokt.v1.AbstractDeserializer
import protokt.v1.AbstractMessage
import protokt.v1.BuilderDsl
import protokt.v1.Collections.copyList
import protokt.v1.Collections.copyMap
import protokt.v1.Collections.unmodifiableList
import protokt.v1.Collections.unmodifiableMap
import protokt.v1.GeneratedMessage
import protokt.v1.GeneratedProperty
import protokt.v1.Reader
import protokt.v1.SizeCodecs.sizeOf
import protokt.v1.UnknownFieldSet
import protokt.v1.Writer
import kotlin.Any
import kotlin.Boolean
import kotlin.Int
import kotlin.Long
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

/**
 * Quota configuration helps to achieve fairness and budgeting in service usage.
 *
 *  The metric based quota configuration works this way: - The service configuration defines a set
 * of metrics. - For API calls, the quota.metric_rules maps methods to metrics with   corresponding
 * costs. - The quota.limits defines limits on the metrics, which will be used for   quota checks at
 * runtime.
 *
 *  An example quota configuration in yaml format:
 *
 *     quota:      limits:
 *
 *       - name: apiWriteQpsPerProject        metric: library.googleapis.com/write_calls
 * unit: "1/min/{project}"  # rate limit for consumer projects        values:          STANDARD: 10000
 *
 *
 *
 *       (The metric rules bind all methods to the read_calls metric,       except for the
 * UpdateBook and DeleteBook methods. These two methods       are mapped to the write_calls metric,
 * with the UpdateBook method       consuming at twice rate as the DeleteBook method.)
 * metric_rules:      - selector: "*"        metric_costs:          library.googleapis.com/read_calls:
 * 1      - selector: google.example.library.v1.LibraryService.UpdateBook        metric_costs:
 * library.googleapis.com/write_calls: 2      - selector:
 * google.example.library.v1.LibraryService.DeleteBook        metric_costs:
 * library.googleapis.com/write_calls: 1
 *
 *   Corresponding Metric definition:
 *
 *       metrics:      - name: library.googleapis.com/read_calls        display_name: Read requests
 *       metric_kind: DELTA        value_type: INT64
 *
 *       - name: library.googleapis.com/write_calls        display_name: Write requests
 * metric_kind: DELTA        value_type: INT64
 *
 *
 */
@GeneratedMessage("google.api.Quota")
public class Quota private constructor(
  /**
   * List of QuotaLimit definitions for the service.
   */
  @GeneratedProperty(3)
  public val limits: List,
  /**
   * List of MetricRule definitions, each one mapping a selected method to one or more metrics.
   */
  @GeneratedProperty(4)
  public val metricRules: List,
  public val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : AbstractMessage() {
  private val `$messageSize`: Int by lazy {
    var result = 0
    if (limits.isNotEmpty()) {
      result += (sizeOf(26u) * limits.size) + limits.sumOf { sizeOf(it) }
    }
    if (metricRules.isNotEmpty()) {
      result += (sizeOf(34u) * metricRules.size) + metricRules.sumOf { sizeOf(it) }
    }
    result += unknownFields.size()
    result
  }

  override fun messageSize(): Int = `$messageSize`

  override fun serialize(writer: Writer) {
    limits.forEach { writer.writeTag(26u).write(it) }
    metricRules.forEach { writer.writeTag(34u).write(it) }
    writer.writeUnknown(unknownFields)
  }

  override fun equals(other: Any?): Boolean =
    other is Quota &&
      other.limits == limits &&
      other.metricRules == metricRules &&
      other.unknownFields == unknownFields

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

  override fun toString(): String =
    "Quota(" +
      "limits=$limits, " +
      "metricRules=$metricRules" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

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

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

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

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): Quota =
      Quota(
        unmodifiableList(limits),
        unmodifiableList(metricRules),
        unknownFields
      )
  }

  public companion object Deserializer : AbstractDeserializer() {
    @JvmStatic
    override fun deserialize(reader: Reader): Quota {
      var limits: MutableList? = null
      var metricRules: MutableList? = null
      var unknownFields: UnknownFieldSet.Builder? = null

      while (true) {
        when (reader.readTag()) {
          0u -> return Quota(
            unmodifiableList(limits),
            unmodifiableList(metricRules),
            UnknownFieldSet.from(unknownFields)
          )
          26u ->
            limits =
              (limits ?: mutableListOf()).apply {
                reader.readRepeated(false) {
                  add(reader.readMessage(QuotaLimit))
                }
              }
          34u ->
            metricRules =
              (metricRules ?: mutableListOf()).apply {
                reader.readRepeated(false) {
                  add(reader.readMessage(MetricRule))
                }
              }
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(reader.readUnknown())
              }
        }
      }
    }

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

/**
 * Bind API methods to metrics. Binding a method to a metric causes that metric's configured quota
 * behaviors to apply to the method call.
 */
@GeneratedMessage("google.api.MetricRule")
public class MetricRule private constructor(
  /**
   * Selects the methods to which this rule applies.
   *
   *  Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
   */
  @GeneratedProperty(1)
  public val selector: String,
  /**
   * Metrics to update when the selected methods are called, and the associated cost applied to each
   * metric.
   *
   *  The key of the map is the metric name, and the values are the amount increased for the metric
   * against which the quota limits are defined. The value must not be negative.
   */
  @GeneratedProperty(2)
  public val metricCosts: Map,
  public val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : AbstractMessage() {
  private val `$messageSize`: Int by lazy {
    var result = 0
    if (selector.isNotEmpty()) {
      result += sizeOf(10u) + sizeOf(selector)
    }
    if (metricCosts.isNotEmpty()) {
      result +=
        sizeOf(metricCosts, 18u) { k, v ->
          MetricCostsEntry.entrySize(k, v)
        }
    }
    result += unknownFields.size()
    result
  }

  override fun messageSize(): Int = `$messageSize`

  override fun serialize(writer: Writer) {
    if (selector.isNotEmpty()) {
      writer.writeTag(10u).write(selector)
    }
    metricCosts.entries.forEach {
      writer.writeTag(18u).write(MetricCostsEntry(it.key, it.value))
    }
    writer.writeUnknown(unknownFields)
  }

  override fun equals(other: Any?): Boolean =
    other is MetricRule &&
      other.selector == selector &&
      other.metricCosts == metricCosts &&
      other.unknownFields == unknownFields

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

  override fun toString(): String =
    "MetricRule(" +
      "selector=$selector, " +
      "metricCosts=$metricCosts" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

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

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

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

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): MetricRule =
      MetricRule(
        selector,
        unmodifiableMap(metricCosts),
        unknownFields
      )
  }

  public companion object Deserializer : AbstractDeserializer() {
    @JvmStatic
    override fun deserialize(reader: Reader): MetricRule {
      var selector = ""
      var metricCosts: MutableMap? = null
      var unknownFields: UnknownFieldSet.Builder? = null

      while (true) {
        when (reader.readTag()) {
          0u -> return MetricRule(
            selector,
            unmodifiableMap(metricCosts),
            UnknownFieldSet.from(unknownFields)
          )
          10u -> selector = reader.readString()
          18u ->
            metricCosts =
              (metricCosts ?: mutableMapOf()).apply {
                reader.readRepeated(false) {
                  reader.readMessage(MetricCostsEntry).let {
                    put(it.key, it.value)
                  }
                }
              }
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(reader.readUnknown())
              }
        }
      }
    }

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

  private class MetricCostsEntry(
    public val key: String,
    public val `value`: Long
  ) : AbstractMessage() {
    override fun messageSize(): Int = entrySize(key, value)

    override fun serialize(writer: Writer) {
      writer.writeTag(10u).write(key)
      writer.writeTag(16u).write(`value`)
    }

    public companion object Deserializer : AbstractDeserializer() {
      public fun entrySize(
        key: String,
        `value`: Long
      ): Int =
        sizeOf(10u) + sizeOf(key) +
          sizeOf(16u) + sizeOf(`value`)

      override fun deserialize(reader: Reader): MetricCostsEntry {
        var key = ""
        var value = 0L

        while (true) {
          when (reader.readTag()) {
            0u -> return MetricCostsEntry(key, value)
            10u -> key = reader.readString()
            16u -> value = reader.readInt64()
          }
        }
      }
    }
  }
}

/**
 * `QuotaLimit` defines a specific limit that applies over a specified duration for a limit type.
 * There can be at most one limit for a duration and limit type combination defined within a
 * `QuotaGroup`.
 */
@GeneratedMessage("google.api.QuotaLimit")
public class QuotaLimit private constructor(
  /**
   * Optional. User-visible, extended description for this quota limit. Should be used only when
   * more context is needed to understand this limit than provided by the limit's display name (see:
   * `display_name`).
   */
  @GeneratedProperty(2)
  public val description: String,
  /**
   * Default number of tokens that can be consumed during the specified duration. This is the number
   * of tokens assigned when a client application developer activates the service for his/her project.
   *
   *  Specifying a value of 0 will block all requests. This can be used if you are provisioning
   * quota to selected consumers and blocking others. Similarly, a value of -1 will indicate an
   * unlimited quota. No other negative values are allowed.
   *
   *  Used by group-based quotas only.
   */
  @GeneratedProperty(3)
  public val defaultLimit: Long,
  /**
   * Maximum number of tokens that can be consumed during the specified duration. Client application
   * developers can override the default limit up to this maximum. If specified, this value cannot be
   * set to a value less than the default limit. If not specified, it is set to the default limit.
   *
   *  To allow clients to apply overrides with no upper bound, set this to -1, indicating unlimited
   * maximum quota.
   *
   *  Used by group-based quotas only.
   */
  @GeneratedProperty(4)
  public val maxLimit: Long,
  /**
   * Duration of this limit in textual notation. Must be "100s" or "1d".
   *
   *  Used by group-based quotas only.
   */
  @GeneratedProperty(5)
  public val duration: String,
  /**
   * Name of the quota limit.
   *
   *  The name must be provided, and it must be unique within the service. The name can only include
   * alphanumeric characters as well as '-'.
   *
   *  The maximum length of the limit name is 64 characters.
   */
  @GeneratedProperty(6)
  public val name: String,
  /**
   * Free tier value displayed in the Developers Console for this limit. The free tier is the number
   * of tokens that will be subtracted from the billed amount when billing is enabled. This field can
   * only be set on a limit with duration "1d", in a billable group; it is invalid on any other limit.
   * If this field is not set, it defaults to 0, indicating that there is no free tier for this
   * service.
   *
   *  Used by group-based quotas only.
   */
  @GeneratedProperty(7)
  public val freeTier: Long,
  /**
   * The name of the metric this quota limit applies to. The quota limits with the same metric will
   * be checked together during runtime. The metric must be defined within the service config.
   */
  @GeneratedProperty(8)
  public val metric: String,
  /**
   * Specify the unit of the quota limit. It uses the same syntax as [Metric.unit][]. The supported
   * unit kinds are determined by the quota backend system.
   *
   *  Here are some examples: * "1/min/{project}" for quota per minute per project.
   *
   *  Note: the order of unit components is insignificant. The "1" at the beginning is required to
   * follow the metric unit syntax.
   */
  @GeneratedProperty(9)
  public val unit: String,
  /**
   * Tiered limit values. You must specify this as a key:value pair, with an integer value that is
   * the maximum number of requests allowed for the specified unit. Currently only STANDARD is
   * supported.
   */
  @GeneratedProperty(10)
  public val values: Map,
  /**
   * User-visible display name for this limit. Optional. If not set, the UI will provide a default
   * display name based on the quota configuration. This field can be used to override the default
   * display name generated from the configuration.
   */
  @GeneratedProperty(12)
  public val displayName: String,
  public val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : AbstractMessage() {
  private val `$messageSize`: Int by lazy {
    var result = 0
    if (description.isNotEmpty()) {
      result += sizeOf(18u) + sizeOf(description)
    }
    if (defaultLimit != 0L) {
      result += sizeOf(24u) + sizeOf(defaultLimit)
    }
    if (maxLimit != 0L) {
      result += sizeOf(32u) + sizeOf(maxLimit)
    }
    if (duration.isNotEmpty()) {
      result += sizeOf(42u) + sizeOf(duration)
    }
    if (name.isNotEmpty()) {
      result += sizeOf(50u) + sizeOf(name)
    }
    if (freeTier != 0L) {
      result += sizeOf(56u) + sizeOf(freeTier)
    }
    if (metric.isNotEmpty()) {
      result += sizeOf(66u) + sizeOf(metric)
    }
    if (unit.isNotEmpty()) {
      result += sizeOf(74u) + sizeOf(unit)
    }
    if (values.isNotEmpty()) {
      result +=
        sizeOf(values, 82u) { k, v ->
          ValuesEntry.entrySize(k, v)
        }
    }
    if (displayName.isNotEmpty()) {
      result += sizeOf(98u) + sizeOf(displayName)
    }
    result += unknownFields.size()
    result
  }

  override fun messageSize(): Int = `$messageSize`

  override fun serialize(writer: Writer) {
    if (description.isNotEmpty()) {
      writer.writeTag(18u).write(description)
    }
    if (defaultLimit != 0L) {
      writer.writeTag(24u).write(defaultLimit)
    }
    if (maxLimit != 0L) {
      writer.writeTag(32u).write(maxLimit)
    }
    if (duration.isNotEmpty()) {
      writer.writeTag(42u).write(duration)
    }
    if (name.isNotEmpty()) {
      writer.writeTag(50u).write(name)
    }
    if (freeTier != 0L) {
      writer.writeTag(56u).write(freeTier)
    }
    if (metric.isNotEmpty()) {
      writer.writeTag(66u).write(metric)
    }
    if (unit.isNotEmpty()) {
      writer.writeTag(74u).write(unit)
    }
    values.entries.forEach {
      writer.writeTag(82u).write(ValuesEntry(it.key, it.value))
    }
    if (displayName.isNotEmpty()) {
      writer.writeTag(98u).write(displayName)
    }
    writer.writeUnknown(unknownFields)
  }

  override fun equals(other: Any?): Boolean =
    other is QuotaLimit &&
      other.description == description &&
      other.defaultLimit == defaultLimit &&
      other.maxLimit == maxLimit &&
      other.duration == duration &&
      other.name == name &&
      other.freeTier == freeTier &&
      other.metric == metric &&
      other.unit == unit &&
      other.values == values &&
      other.displayName == displayName &&
      other.unknownFields == unknownFields

  override fun hashCode(): Int {
    var result = unknownFields.hashCode()
    result = 31 * result + description.hashCode()
    result = 31 * result + defaultLimit.hashCode()
    result = 31 * result + maxLimit.hashCode()
    result = 31 * result + duration.hashCode()
    result = 31 * result + name.hashCode()
    result = 31 * result + freeTier.hashCode()
    result = 31 * result + metric.hashCode()
    result = 31 * result + unit.hashCode()
    result = 31 * result + values.hashCode()
    result = 31 * result + displayName.hashCode()
    return result
  }

  override fun toString(): String =
    "QuotaLimit(" +
      "description=$description, " +
      "defaultLimit=$defaultLimit, " +
      "maxLimit=$maxLimit, " +
      "duration=$duration, " +
      "name=$name, " +
      "freeTier=$freeTier, " +
      "metric=$metric, " +
      "unit=$unit, " +
      "values=$values, " +
      "displayName=$displayName" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

  public fun copy(builder: Builder.() -> Unit): QuotaLimit =
    Builder().apply {
      description = [email protected]
      defaultLimit = [email protected]
      maxLimit = [email protected]
      duration = [email protected]
      name = [email protected]
      freeTier = [email protected]
      metric = [email protected]
      unit = [email protected]
      values = [email protected]
      displayName = [email protected]
      unknownFields = [email protected]
      builder()
    }.build()

  @BuilderDsl
  public class Builder {
    public var description: String = ""

    public var defaultLimit: Long = 0L

    public var maxLimit: Long = 0L

    public var duration: String = ""

    public var name: String = ""

    public var freeTier: Long = 0L

    public var metric: String = ""

    public var unit: String = ""

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

    public var displayName: String = ""

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): QuotaLimit =
      QuotaLimit(
        description,
        defaultLimit,
        maxLimit,
        duration,
        name,
        freeTier,
        metric,
        unit,
        unmodifiableMap(values),
        displayName,
        unknownFields
      )
  }

  public companion object Deserializer : AbstractDeserializer() {
    @JvmStatic
    override fun deserialize(reader: Reader): QuotaLimit {
      var description = ""
      var defaultLimit = 0L
      var maxLimit = 0L
      var duration = ""
      var name = ""
      var freeTier = 0L
      var metric = ""
      var unit = ""
      var values: MutableMap? = null
      var displayName = ""
      var unknownFields: UnknownFieldSet.Builder? = null

      while (true) {
        when (reader.readTag()) {
          0u -> return QuotaLimit(
            description,
            defaultLimit,
            maxLimit,
            duration,
            name,
            freeTier,
            metric,
            unit,
            unmodifiableMap(values),
            displayName,
            UnknownFieldSet.from(unknownFields)
          )
          18u -> description = reader.readString()
          24u -> defaultLimit = reader.readInt64()
          32u -> maxLimit = reader.readInt64()
          42u -> duration = reader.readString()
          50u -> name = reader.readString()
          56u -> freeTier = reader.readInt64()
          66u -> metric = reader.readString()
          74u -> unit = reader.readString()
          82u ->
            values =
              (values ?: mutableMapOf()).apply {
                reader.readRepeated(false) {
                  reader.readMessage(ValuesEntry).let {
                    put(it.key, it.value)
                  }
                }
              }
          98u -> displayName = reader.readString()
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(reader.readUnknown())
              }
        }
      }
    }

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

  private class ValuesEntry(
    public val key: String,
    public val `value`: Long
  ) : AbstractMessage() {
    override fun messageSize(): Int = entrySize(key, value)

    override fun serialize(writer: Writer) {
      writer.writeTag(10u).write(key)
      writer.writeTag(16u).write(`value`)
    }

    public companion object Deserializer : AbstractDeserializer() {
      public fun entrySize(
        key: String,
        `value`: Long
      ): Int =
        sizeOf(10u) + sizeOf(key) +
          sizeOf(16u) + sizeOf(`value`)

      override fun deserialize(reader: Reader): ValuesEntry {
        var key = ""
        var value = 0L

        while (true) {
          when (reader.readTag()) {
            0u -> return ValuesEntry(key, value)
            10u -> key = reader.readString()
            16u -> value = reader.readInt64()
          }
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy