protokt.com.google.api.context.kt Maven / Gradle / Ivy
// Generated by protokt version 0.9.0. Do not modify.
// Source: google/api/context.proto
package com.google.api
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.Any
import kotlin.Boolean
import kotlin.Int
import kotlin.String
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.MutableList
/**
* `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.
*/
@KtGeneratedMessage("google.api.Context")
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.
*/
val rules: List,
val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : KtMessage {
override val messageSize: Int by lazy { messageSize() }
private fun messageSize(): Int {
var result = 0
if (rules.isNotEmpty()) {
result += (sizeof(Tag(1)) * rules.size) + rules.sumOf { sizeof(it) }
}
result += unknownFields.size()
return result
}
override fun serialize(serializer: KtMessageSerializer) {
if (rules.isNotEmpty()) {
rules.forEach { serializer.write(Tag(10)).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, " +
"unknownFields=$unknownFields)"
fun copy(dsl: ContextDsl.() -> Unit): Context = Context.Deserializer {
rules = [email protected]
unknownFields = [email protected]
dsl()
}
class ContextDsl {
var rules: List = emptyList()
set(newValue) {
field = copyList(newValue)
}
var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
fun build(): Context = Context(finishList(rules),
unknownFields)
}
companion object Deserializer : KtDeserializer, (ContextDsl.() -> Unit) ->
Context {
override fun deserialize(deserializer: KtMessageDeserializer): Context {
var rules : MutableList? = null
var unknownFields: UnknownFieldSet.Builder? = null
while (true) {
when(deserializer.readTag()) {
0 -> return Context(finishList(rules),
UnknownFieldSet.from(unknownFields))
10 -> rules = (rules ?: mutableListOf()).apply {
deserializer.readRepeated(false) {
add(deserializer.readMessage(com.google.api.ContextRule))
}
}
else -> unknownFields = (unknownFields ?:
UnknownFieldSet.Builder()).also {it.add(deserializer.readUnknown()) }
}
}
}
override fun invoke(dsl: ContextDsl.() -> Unit): Context =
ContextDsl().apply(dsl).build()
}
}
/**
* A context rule provides information about the context for an individual API element.
*/
@KtGeneratedMessage("google.api.ContextRule")
class ContextRule private constructor(
/**
* Selects the methods to which this rule applies.
*
* Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
*/
val selector: String,
/**
* A list of full type names of requested contexts.
*/
val requested: List,
/**
* A list of full type names of provided contexts.
*/
val provided: List,
/**
* A list of full type names or extension IDs of extensions allowed in grpc side channel from
* client to backend.
*/
val allowedRequestExtensions: List,
/**
* A list of full type names or extension IDs of extensions allowed in grpc side channel from
* backend to client.
*/
val allowedResponseExtensions: List,
val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : KtMessage {
override val messageSize: Int by lazy { messageSize() }
private fun messageSize(): Int {
var result = 0
if (selector.isNotEmpty()) {
result += sizeof(Tag(1)) + sizeof(selector)
}
if (requested.isNotEmpty()) {
result += (sizeof(Tag(2)) * requested.size) + requested.sumOf { sizeof(it) }
}
if (provided.isNotEmpty()) {
result += (sizeof(Tag(3)) * provided.size) + provided.sumOf { sizeof(it) }
}
if (allowedRequestExtensions.isNotEmpty()) {
result += (sizeof(Tag(4)) * allowedRequestExtensions.size) +
allowedRequestExtensions.sumOf { sizeof(it) }
}
if (allowedResponseExtensions.isNotEmpty()) {
result += (sizeof(Tag(5)) * allowedResponseExtensions.size) +
allowedResponseExtensions.sumOf { sizeof(it) }
}
result += unknownFields.size()
return result
}
override fun serialize(serializer: KtMessageSerializer) {
if (selector.isNotEmpty()) {
serializer.write(Tag(10)).write(selector)
}
if (requested.isNotEmpty()) {
requested.forEach { serializer.write(Tag(18)).write(it) }
}
if (provided.isNotEmpty()) {
provided.forEach { serializer.write(Tag(26)).write(it) }
}
if (allowedRequestExtensions.isNotEmpty()) {
allowedRequestExtensions.forEach { serializer.write(Tag(34)).write(it) }
}
if (allowedResponseExtensions.isNotEmpty()) {
allowedResponseExtensions.forEach { serializer.write(Tag(42)).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, " +
"unknownFields=$unknownFields)"
fun copy(dsl: ContextRuleDsl.() -> Unit): ContextRule = ContextRule.Deserializer {
selector = [email protected]
requested = [email protected]
provided = [email protected]
allowedRequestExtensions = [email protected]
allowedResponseExtensions = [email protected]
unknownFields = [email protected]
dsl()
}
class ContextRuleDsl {
var selector: String = ""
var requested: List = emptyList()
set(newValue) {
field = copyList(newValue)
}
var provided: List = emptyList()
set(newValue) {
field = copyList(newValue)
}
var allowedRequestExtensions: List = emptyList()
set(newValue) {
field = copyList(newValue)
}
var allowedResponseExtensions: List = emptyList()
set(newValue) {
field = copyList(newValue)
}
var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
fun build(): ContextRule = ContextRule(selector,
finishList(requested),
finishList(provided),
finishList(allowedRequestExtensions),
finishList(allowedResponseExtensions),
unknownFields)
}
companion object Deserializer : KtDeserializer, (ContextRuleDsl.() ->
Unit) -> ContextRule {
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,
finishList(requested),
finishList(provided),
finishList(allowedRequestExtensions),
finishList(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()) }
}
}
}
override fun invoke(dsl: ContextRuleDsl.() -> Unit): ContextRule =
ContextRuleDsl().apply(dsl).build()
}
}