com.google.api.httpbody.kt Maven / Gradle / Ivy
// Generated by protokt version 0.10.0. Do not modify.
// Source: google/api/httpbody.proto
package com.google.api
import com.toasttab.protokt.Any
import com.toasttab.protokt.rt.Bytes
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.Boolean
import kotlin.Int
import kotlin.String
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.MutableList
/**
* Message that represents an arbitrary HTTP body. It should only be used for payload formats that
* can't be represented as JSON, such as raw binary or an HTML page.
*
*
*
* This message can be used both in streaming and non-streaming API methods in the request as well
* as the response.
*
* It can be used as a top-level request field, which is convenient if one wants to extract
* parameters from either the URL or HTTP template into the request fields and also want access to the
* raw HTTP body.
*
* Example:
*
* message GetResourceRequest { // A unique request id. string request_id = 1;
*
* // The raw HTTP body is bound to this field. google.api.HttpBody http_body = 2;
*
* }
*
* service ResourceService { rpc GetResource(GetResourceRequest) returns
* (google.api.HttpBody); rpc UpdateResource(google.api.HttpBody) returns
* (google.protobuf.Empty);
*
* }
*
* Example with streaming methods:
*
* service CaldavService { rpc GetCalendar(stream google.api.HttpBody) returns
* (stream google.api.HttpBody); rpc UpdateCalendar(stream google.api.HttpBody) returns
* (stream google.api.HttpBody);
*
* }
*
* Use of this type only changes how the request and response bodies are handled, all other
* features will continue to work unchanged.
*/
@KtGeneratedMessage("google.api.HttpBody")
class HttpBody private constructor(
/**
* The HTTP Content-Type header value specifying the content type of the body.
*/
val contentType: String,
/**
* The HTTP request/response body as raw binary.
*/
val `data`: Bytes,
/**
* Application specific response metadata. Must be set in the first response for streaming APIs.
*/
val extensions: List,
val unknownFields: UnknownFieldSet = UnknownFieldSet.empty(),
) : KtMessage {
override val messageSize: Int by lazy { messageSize() }
private fun messageSize(): Int {
var result = 0
if (contentType.isNotEmpty()) {
result += sizeof(Tag(1)) + sizeof(contentType)
}
if (data.isNotEmpty()) {
result += sizeof(Tag(2)) + sizeof(data)
}
if (extensions.isNotEmpty()) {
result += (sizeof(Tag(3)) * extensions.size) + extensions.sumOf { sizeof(it) }
}
result += unknownFields.size()
return result
}
override fun serialize(serializer: KtMessageSerializer) {
if (contentType.isNotEmpty()) {
serializer.write(Tag(10)).write(contentType)
}
if (data.isNotEmpty()) {
serializer.write(Tag(18)).write(data)
}
if (extensions.isNotEmpty()) {
extensions.forEach { serializer.write(Tag(26)).write(it) }
}
serializer.writeUnknown(unknownFields)
}
override fun equals(other: kotlin.Any?): Boolean = other is HttpBody &&
other.contentType == contentType &&
other.data == data &&
other.extensions == extensions &&
other.unknownFields == unknownFields
override fun hashCode(): Int {
var result = unknownFields.hashCode()
result = 31 * result + contentType.hashCode()
result = 31 * result + data.hashCode()
result = 31 * result + extensions.hashCode()
return result
}
override fun toString(): String = "HttpBody(" +
"contentType=$contentType, " +
"data=$data, " +
"extensions=$extensions, " +
"unknownFields=$unknownFields)"
fun copy(dsl: HttpBodyDsl.() -> Unit): HttpBody = HttpBody.Deserializer {
contentType = [email protected]
data = [email protected]
extensions = [email protected]
unknownFields = [email protected]
dsl()
}
class HttpBodyDsl {
var contentType: String = ""
var `data`: Bytes = Bytes.empty()
var extensions: List = emptyList()
set(newValue) {
field = copyList(newValue)
}
var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
fun build(): HttpBody = HttpBody(contentType,
data,
finishList(extensions),
unknownFields)
}
companion object Deserializer : KtDeserializer,
(HttpBodyDsl.() -> Unit) -> HttpBody {
override fun deserialize(deserializer: KtMessageDeserializer): HttpBody {
var contentType = ""
var data = Bytes.empty()
var extensions : MutableList? = null
var unknownFields: UnknownFieldSet.Builder? = null
while (true) {
when(deserializer.readTag()) {
0 -> return HttpBody(contentType,
data,
finishList(extensions),
UnknownFieldSet.from(unknownFields))
10 -> contentType = deserializer.readString()
18 -> data = deserializer.readBytes()
26 -> extensions = (extensions ?: mutableListOf()).apply {
deserializer.readRepeated(false) {
add(deserializer.readMessage(com.toasttab.protokt.Any))
}
}
else -> unknownFields = (unknownFields ?:
UnknownFieldSet.Builder()).also {it.add(deserializer.readUnknown()) }
}
}
}
override fun invoke(dsl: HttpBodyDsl.() -> Unit): HttpBody =
HttpBodyDsl().apply(dsl).build()
}
}