Created
July 6, 2024 11:32
-
-
Save ksharma-xyz/595d1bc33453def7bb19c0eef30626de to your computer and use it in GitHub Desktop.
Kotlin Class generated from proto using wire plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code generated by Wire protocol buffer compiler, do not edit. | |
// Source: User in xyz/ksharma/pokemon/user.proto | |
@file:Suppress("DEPRECATION") | |
package xyz.ksharma.user | |
import com.squareup.wire.FieldEncoding | |
import com.squareup.wire.Message | |
import com.squareup.wire.ProtoAdapter | |
import com.squareup.wire.ProtoReader | |
import com.squareup.wire.ProtoWriter | |
import com.squareup.wire.ReverseProtoWriter | |
import com.squareup.wire.Syntax.PROTO_3 | |
import com.squareup.wire.WireField | |
import com.squareup.wire.`internal`.JvmField | |
import com.squareup.wire.`internal`.JvmSynthetic | |
import com.squareup.wire.`internal`.sanitize | |
import kotlin.Any | |
import kotlin.Boolean | |
import kotlin.Int | |
import kotlin.Long | |
import kotlin.String | |
import kotlin.Suppress | |
import kotlin.Unit | |
import okio.ByteString | |
public class User( | |
@field:WireField( | |
tag = 1, | |
adapter = "com.squareup.wire.ProtoAdapter#STRING", | |
label = WireField.Label.OMIT_IDENTITY, | |
schemaIndex = 0, | |
) | |
@JvmField | |
public val id: String = "", | |
@field:WireField( | |
tag = 2, | |
adapter = "com.squareup.wire.ProtoAdapter#STRING", | |
label = WireField.Label.OMIT_IDENTITY, | |
schemaIndex = 1, | |
) | |
@JvmField | |
public val name: String = "", | |
@field:WireField( | |
tag = 3, | |
adapter = "com.squareup.wire.ProtoAdapter#INT32", | |
label = WireField.Label.OMIT_IDENTITY, | |
schemaIndex = 2, | |
) | |
@JvmField | |
public val age: Int = 0, | |
unknownFields: ByteString = ByteString.EMPTY, | |
) : Message<User, User.Builder>(ADAPTER, unknownFields) { | |
override fun newBuilder(): Builder { | |
val builder = Builder() | |
builder.id = id | |
builder.name = name | |
builder.age = age | |
builder.addUnknownFields(unknownFields) | |
return builder | |
} | |
override fun equals(other: Any?): Boolean { | |
if (other === this) return true | |
if (other !is User) return false | |
if (unknownFields != other.unknownFields) return false | |
if (id != other.id) return false | |
if (name != other.name) return false | |
if (age != other.age) return false | |
return true | |
} | |
override fun hashCode(): Int { | |
var result = super.hashCode | |
if (result == 0) { | |
result = unknownFields.hashCode() | |
result = result * 37 + id.hashCode() | |
result = result * 37 + name.hashCode() | |
result = result * 37 + age.hashCode() | |
super.hashCode = result | |
} | |
return result | |
} | |
override fun toString(): String { | |
val result = mutableListOf<String>() | |
result += """id=${sanitize(id)}""" | |
result += """name=${sanitize(name)}""" | |
result += """age=$age""" | |
return result.joinToString(prefix = "User{", separator = ", ", postfix = "}") | |
} | |
public fun copy( | |
id: String = this.id, | |
name: String = this.name, | |
age: Int = this.age, | |
unknownFields: ByteString = this.unknownFields, | |
): User = User(id, name, age, unknownFields) | |
public class Builder : Message.Builder<User, Builder>() { | |
@JvmField | |
public var id: String = "" | |
@JvmField | |
public var name: String = "" | |
@JvmField | |
public var age: Int = 0 | |
public fun id(id: String): Builder { | |
this.id = id | |
return this | |
} | |
public fun name(name: String): Builder { | |
this.name = name | |
return this | |
} | |
public fun age(age: Int): Builder { | |
this.age = age | |
return this | |
} | |
override fun build(): User = User( | |
id = id, | |
name = name, | |
age = age, | |
unknownFields = buildUnknownFields() | |
) | |
} | |
public companion object { | |
@JvmField | |
public val ADAPTER: ProtoAdapter<User> = object : ProtoAdapter<User>( | |
FieldEncoding.LENGTH_DELIMITED, | |
User::class, | |
"type.googleapis.com/User", | |
PROTO_3, | |
null, | |
"xyz/ksharma/pokemon/user.proto" | |
) { | |
override fun encodedSize(`value`: User): Int { | |
var size = value.unknownFields.size | |
if (value.id != "") { | |
size += ProtoAdapter.STRING.encodedSizeWithTag(1, value.id) | |
} | |
if (value.name != "") { | |
size += ProtoAdapter.STRING.encodedSizeWithTag(2, value.name) | |
} | |
if (value.age != 0) { | |
size += ProtoAdapter.INT32.encodedSizeWithTag(3, value.age) | |
} | |
return size | |
} | |
override fun encode(writer: ProtoWriter, `value`: User) { | |
if (value.id != "") { | |
ProtoAdapter.STRING.encodeWithTag(writer, 1, value.id) | |
} | |
if (value.name != "") { | |
ProtoAdapter.STRING.encodeWithTag(writer, 2, value.name) | |
} | |
if (value.age != 0) { | |
ProtoAdapter.INT32.encodeWithTag(writer, 3, value.age) | |
} | |
writer.writeBytes(value.unknownFields) | |
} | |
override fun encode(writer: ReverseProtoWriter, `value`: User) { | |
writer.writeBytes(value.unknownFields) | |
if (value.age != 0) { | |
ProtoAdapter.INT32.encodeWithTag(writer, 3, value.age) | |
} | |
if (value.name != "") { | |
ProtoAdapter.STRING.encodeWithTag(writer, 2, value.name) | |
} | |
if (value.id != "") { | |
ProtoAdapter.STRING.encodeWithTag(writer, 1, value.id) | |
} | |
} | |
override fun decode(reader: ProtoReader): User { | |
var id: String = "" | |
var name: String = "" | |
var age: Int = 0 | |
val unknownFields = reader.forEachTag { tag -> | |
when (tag) { | |
1 -> id = ProtoAdapter.STRING.decode(reader) | |
2 -> name = ProtoAdapter.STRING.decode(reader) | |
3 -> age = ProtoAdapter.INT32.decode(reader) | |
else -> reader.readUnknownField(tag) | |
} | |
} | |
return User( | |
id = id, | |
name = name, | |
age = age, | |
unknownFields = unknownFields | |
) | |
} | |
override fun redact(`value`: User): User = value.copy( | |
unknownFields = ByteString.EMPTY | |
) | |
} | |
private const val serialVersionUID: Long = 0L | |
@JvmSynthetic | |
public inline fun build(body: Builder.() -> Unit): User = Builder().apply(body).build() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment