Skip to content

Commit

Permalink
Add mutableTypes to Wire plugin and set golden file
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod committed Dec 18, 2024
1 parent 85dd4f3 commit 9d2090c
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ data class KotlinTarget(
* when targeting Kotlin/JS, where `Long` cursors are inefficient.
*/
private val emitProtoReader32: Boolean = false,

/**
* If true, the generated classes will be mutable..
*/
private val mutableTypes: Boolean = false,
) : Target() {
override fun newHandler(): SchemaHandler {
return KotlinSchemaHandler(
Expand All @@ -159,6 +164,7 @@ data class KotlinTarget(
escapeKotlinKeywords = escapeKotlinKeywords,
enumMode = enumMode,
emitProtoReader32 = emitProtoReader32,
mutableTypes = mutableTypes,
)
}

Expand Down
6 changes: 6 additions & 0 deletions wire-golden-files/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ plugins {
}

wire {
kotlin {
includes = listOf("squareup.wire.mutable.*")
out = "src/main/kotlin"
mutableTypes = true
}

kotlin {
includes = listOf("squareup.wire.unrecognized_constant.*")
out = "src/main/kotlin"
Expand Down
3 changes: 0 additions & 3 deletions wire-golden-files/src/main/kotlin/HundredsFields.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import kotlin.String
import kotlin.Suppress
import okio.ByteString

/**
* import "google/protobuf/descriptor.proto";
*/
public class HundredsFields(
@field:WireField(
tag = 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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.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,
unknownFields: ByteString = ByteString.EMPTY,
) : Message<MutableHeader, Nothing>(ADAPTER, unknownFields) {
override fun equals(other: Any?): Boolean {
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,119 @@
// 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.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,
unknownFields: ByteString = ByteString.EMPTY,
) : Message<MutablePacket, Nothing>(ADAPTER, unknownFields) {
override fun equals(other: Any?): Boolean {
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source: squareup.wire.mutable.Payload 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.Int
import kotlin.Long
import kotlin.Nothing
import kotlin.String
import kotlin.Suppress
import kotlin.UnsupportedOperationException
import okio.ByteString

public class MutablePayload(
@field:WireField(
tag = 1,
adapter = "com.squareup.wire.ProtoAdapter#BYTES",
schemaIndex = 0,
)
public var content: ByteString? = null,
unknownFields: ByteString = ByteString.EMPTY,
) : Message<MutablePayload, Nothing>(ADAPTER, unknownFields) {
override fun equals(other: Any?): Boolean {
if (other !is MutablePayload) return false
if (unknownFields != other.unknownFields) return false
if (content != other.content) return false
return true
}

override fun hashCode(): Int {
var result = 0
result = unknownFields.hashCode()
result = result * 37 + (content?.hashCode() ?: 0)
return result
}

override fun toString(): String {
val result = mutableListOf<String>()
if (content != null) result += """content=$content"""
return result.joinToString(prefix = "MutablePayload{", separator = ", ", postfix = "}")
}

public companion object {
@JvmField
public val ADAPTER: ProtoAdapter<MutablePayload> = object : ProtoAdapter<MutablePayload>(
FieldEncoding.LENGTH_DELIMITED,
MutablePayload::class,
"type.googleapis.com/squareup.wire.mutable.Payload",
PROTO_2,
null,
"squareup/wire/mutable_types.proto"
) {
override fun encodedSize(`value`: MutablePayload): Int {
var size = value.unknownFields.size
size += ProtoAdapter.BYTES.encodedSizeWithTag(1, value.content)
return size
}

override fun encode(writer: ProtoWriter, `value`: MutablePayload) {
ProtoAdapter.BYTES.encodeWithTag(writer, 1, value.content)
writer.writeBytes(value.unknownFields)
}

override fun encode(writer: ReverseProtoWriter, `value`: MutablePayload) {
writer.writeBytes(value.unknownFields)
ProtoAdapter.BYTES.encodeWithTag(writer, 1, value.content)
}

override fun decode(reader: ProtoReader): MutablePayload {
var content: ByteString? = null
val unknownFields = reader.forEachTag { tag ->
when (tag) {
1 -> content = ProtoAdapter.BYTES.decode(reader)
else -> reader.readUnknownField(tag)
}
}
return MutablePayload(
content = content,
unknownFields = unknownFields
)
}

override fun redact(`value`: MutablePayload): MutablePayload = 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
@@ -1,7 +1,5 @@
syntax = "proto3";

// import "google/protobuf/descriptor.proto";

message HundredsFields {
Field field1 = 1;
Field field2 = 2;
Expand Down
16 changes: 16 additions & 0 deletions wire-golden-files/src/main/proto/squareup/wire/mutable_types.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto2";

package squareup.wire.mutable;

message Header {
optional uint64 id = 1;
}

message Payload {
optional bytes content = 1;
}

message Packet {
optional Header header = 1;
optional Payload payload = 2;
}
Loading

0 comments on commit 9d2090c

Please sign in to comment.