-
Notifications
You must be signed in to change notification settings - Fork 599
Add support for mutable messages in Wire's Kotlin Generator. #3217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fd9bfb9
00a9852
93fe2e8
dc31133
ad6d312
88666f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Code generated by Wire protocol buffer compiler, do not edit. | ||
| // Source: squareup.wire.mutable.Header in squareup/wire/mutable_types.proto | ||
| @file:Suppress( | ||
| "DEPRECATION", | ||
| "RUNTIME_ANNOTATION_NOT_SUPPORTED", | ||
| ) | ||
|
|
||
| package squareup.wire.mutable | ||
|
|
||
| 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_2 | ||
| import com.squareup.wire.WireField | ||
| import com.squareup.wire.`internal`.JvmField | ||
| import kotlin.Any | ||
| import kotlin.Boolean | ||
| import kotlin.Deprecated | ||
| import kotlin.DeprecationLevel | ||
| import kotlin.Int | ||
| import kotlin.Long | ||
| import kotlin.Nothing | ||
| import kotlin.String | ||
| import kotlin.Suppress | ||
| import kotlin.UnsupportedOperationException | ||
| import okio.ByteString | ||
|
|
||
| public class MutableHeader( | ||
| @field:WireField( | ||
| tag = 1, | ||
| adapter = "com.squareup.wire.ProtoAdapter#UINT64", | ||
| schemaIndex = 0, | ||
| ) | ||
| public var id: Long? = null, | ||
| override var unknownFields: ByteString = ByteString.EMPTY, | ||
| ) : Message<MutableHeader, Nothing>(ADAPTER, unknownFields) { | ||
| @Deprecated( | ||
| message = "Shouldn't be used in Kotlin", | ||
| level = DeprecationLevel.HIDDEN, | ||
| ) | ||
| override fun newBuilder(): Nothing = throw UnsupportedOperationException("newBuilder() is unsupported for mutable message types") | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be by-identity rather than by-value? Equals is weird on mutable things
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean that we should only support referential equality ? I think it's also okay for us to also compare the values. Otherwise it might just end up being confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. |
||
| if (other === this) return true | ||
| if (other !is MutableHeader) return false | ||
| if (unknownFields != other.unknownFields) return false | ||
| if (id != other.id) return false | ||
| return true | ||
| } | ||
|
|
||
| override fun hashCode(): Int { | ||
| var result = 0 | ||
| result = unknownFields.hashCode() | ||
| result = result * 37 + (id?.hashCode() ?: 0) | ||
| return result | ||
| } | ||
|
|
||
| override fun toString(): String { | ||
| val result = mutableListOf<String>() | ||
| if (id != null) result += """id=$id""" | ||
| return result.joinToString(prefix = "MutableHeader{", separator = ", ", postfix = "}") | ||
| } | ||
|
|
||
| public companion object { | ||
| @JvmField | ||
| public val ADAPTER: ProtoAdapter<MutableHeader> = object : ProtoAdapter<MutableHeader>( | ||
| FieldEncoding.LENGTH_DELIMITED, | ||
| MutableHeader::class, | ||
| "type.googleapis.com/squareup.wire.mutable.Header", | ||
| PROTO_2, | ||
| null, | ||
| "squareup/wire/mutable_types.proto" | ||
| ) { | ||
| override fun encodedSize(`value`: MutableHeader): Int { | ||
| var size = value.unknownFields.size | ||
| size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.id) | ||
| return size | ||
| } | ||
|
|
||
| override fun encode(writer: ProtoWriter, `value`: MutableHeader) { | ||
| ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.id) | ||
| writer.writeBytes(value.unknownFields) | ||
| } | ||
|
|
||
| override fun encode(writer: ReverseProtoWriter, `value`: MutableHeader) { | ||
| writer.writeBytes(value.unknownFields) | ||
| ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.id) | ||
| } | ||
|
|
||
| override fun decode(reader: ProtoReader): MutableHeader { | ||
| var id: Long? = null | ||
| val unknownFields = reader.forEachTag { tag -> | ||
| when (tag) { | ||
| 1 -> id = ProtoAdapter.UINT64.decode(reader) | ||
| else -> reader.readUnknownField(tag) | ||
| } | ||
| } | ||
| return MutableHeader( | ||
| id = id, | ||
| unknownFields = unknownFields | ||
| ) | ||
| } | ||
|
|
||
| override fun redact(`value`: MutableHeader): MutableHeader = throw UnsupportedOperationException("redact() is unsupported for mutable message types") | ||
| } | ||
|
|
||
| private const val serialVersionUID: Long = 0L | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Code generated by Wire protocol buffer compiler, do not edit. | ||
| // Source: squareup.wire.mutable.Packet in squareup/wire/mutable_types.proto | ||
| @file:Suppress( | ||
| "DEPRECATION", | ||
| "RUNTIME_ANNOTATION_NOT_SUPPORTED", | ||
| ) | ||
|
|
||
| package squareup.wire.mutable | ||
|
|
||
| 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_2 | ||
| import com.squareup.wire.WireField | ||
| import com.squareup.wire.`internal`.JvmField | ||
| import kotlin.Any | ||
| import kotlin.Boolean | ||
| import kotlin.Deprecated | ||
| import kotlin.DeprecationLevel | ||
| import kotlin.Int | ||
| import kotlin.Long | ||
| import kotlin.Nothing | ||
| import kotlin.String | ||
| import kotlin.Suppress | ||
| import kotlin.UnsupportedOperationException | ||
| import okio.ByteString | ||
|
|
||
| public class MutablePacket( | ||
| @field:WireField( | ||
| tag = 1, | ||
| adapter = "squareup.wire.mutable.MutableHeader#ADAPTER", | ||
| declaredName = "header", | ||
| schemaIndex = 0, | ||
| ) | ||
| public var header_: MutableHeader? = null, | ||
| @field:WireField( | ||
| tag = 2, | ||
| adapter = "squareup.wire.mutable.MutablePayload#ADAPTER", | ||
| schemaIndex = 1, | ||
| ) | ||
| public var payload: MutablePayload? = null, | ||
| override var unknownFields: ByteString = ByteString.EMPTY, | ||
| ) : Message<MutablePacket, Nothing>(ADAPTER, unknownFields) { | ||
| @Deprecated( | ||
| message = "Shouldn't be used in Kotlin", | ||
| level = DeprecationLevel.HIDDEN, | ||
| ) | ||
| override fun newBuilder(): Nothing = throw UnsupportedOperationException("newBuilder() is unsupported for mutable message types") | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
| if (other === this) return true | ||
| if (other !is MutablePacket) return false | ||
| if (unknownFields != other.unknownFields) return false | ||
| if (header_ != other.header_) return false | ||
| if (payload != other.payload) return false | ||
| return true | ||
| } | ||
|
|
||
| override fun hashCode(): Int { | ||
| var result = 0 | ||
| result = unknownFields.hashCode() | ||
| result = result * 37 + (header_?.hashCode() ?: 0) | ||
| result = result * 37 + (payload?.hashCode() ?: 0) | ||
| return result | ||
| } | ||
|
|
||
| override fun toString(): String { | ||
| val result = mutableListOf<String>() | ||
| if (header_ != null) result += """header_=$header_""" | ||
| if (payload != null) result += """payload=$payload""" | ||
| return result.joinToString(prefix = "MutablePacket{", separator = ", ", postfix = "}") | ||
| } | ||
|
|
||
| public companion object { | ||
| @JvmField | ||
| public val ADAPTER: ProtoAdapter<MutablePacket> = object : ProtoAdapter<MutablePacket>( | ||
| FieldEncoding.LENGTH_DELIMITED, | ||
| MutablePacket::class, | ||
| "type.googleapis.com/squareup.wire.mutable.Packet", | ||
| PROTO_2, | ||
| null, | ||
| "squareup/wire/mutable_types.proto" | ||
| ) { | ||
| override fun encodedSize(`value`: MutablePacket): Int { | ||
| var size = value.unknownFields.size | ||
| size += MutableHeader.ADAPTER.encodedSizeWithTag(1, value.header_) | ||
| size += MutablePayload.ADAPTER.encodedSizeWithTag(2, value.payload) | ||
| return size | ||
| } | ||
|
|
||
| override fun encode(writer: ProtoWriter, `value`: MutablePacket) { | ||
| MutableHeader.ADAPTER.encodeWithTag(writer, 1, value.header_) | ||
| MutablePayload.ADAPTER.encodeWithTag(writer, 2, value.payload) | ||
| writer.writeBytes(value.unknownFields) | ||
| } | ||
|
|
||
| override fun encode(writer: ReverseProtoWriter, `value`: MutablePacket) { | ||
| writer.writeBytes(value.unknownFields) | ||
| MutablePayload.ADAPTER.encodeWithTag(writer, 2, value.payload) | ||
| MutableHeader.ADAPTER.encodeWithTag(writer, 1, value.header_) | ||
| } | ||
|
|
||
| override fun decode(reader: ProtoReader): MutablePacket { | ||
| var header_: MutableHeader? = null | ||
| var payload: MutablePayload? = null | ||
| val unknownFields = reader.forEachTag { tag -> | ||
| when (tag) { | ||
| 1 -> header_ = MutableHeader.ADAPTER.decode(reader) | ||
| 2 -> payload = MutablePayload.ADAPTER.decode(reader) | ||
| else -> reader.readUnknownField(tag) | ||
| } | ||
| } | ||
| return MutablePacket( | ||
| header_ = header_, | ||
| payload = payload, | ||
| unknownFields = unknownFields | ||
| ) | ||
| } | ||
|
|
||
| override fun redact(`value`: MutablePacket): MutablePacket = throw UnsupportedOperationException("redact() is unsupported for mutable message types") | ||
| } | ||
|
|
||
| private const val serialVersionUID: Long = 0L | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.