-
Notifications
You must be signed in to change notification settings - Fork 578
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
Add support for mutable messages in Wire's Kotlin Generator. #3217
Conversation
wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt
Outdated
Show resolved
Hide resolved
9d2090c
to
83c75b8
Compare
7946e6e
to
5f09272
Compare
wire-golden-files/src/main/kotlin/squareup/wire/mutable/MutableHeader.kt
Outdated
Show resolved
Hide resolved
wire-golden-files/src/main/kotlin/squareup/wire/mutable/MutableHeader.kt
Outdated
Show resolved
Hide resolved
wire-golden-files/src/main/kotlin/squareup/wire/mutable/MutableHeader.kt
Outdated
Show resolved
Hide resolved
5f09272
to
75ab3de
Compare
wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt
Outdated
Show resolved
Hide resolved
* Sometimes its very useful to avoid needing to create new object graph instances when all we need to do is to serialize the object graph into a `ProtoSink`. * Mutable messages solves for this, for code that is particularly performance sensitive where a large number of objects would have otherwise been created which adds unnecesssary GC pressure. * Mutable messages should be **used very carefully**. There are **no guarantees of safety whatsoever**. * When using mutable messages, `hashCode()` is no longer cached. * Mutable messages don't support `redact()`. Test: Added a unit test in KotlinGeneratorTest
* `newBuilder()` throws an `UnsupportedOperationException` instead. Thanks @oldergod. * Updated the `KotlinGeneratorTest` to use the renamed option in the `KotlinGenerator`. * Update goldens to include the new error message. * Update API files for `wire-compiler`.
* `Mutable` messsages now have access to mutable `unknownFields`. Test: Updated KotlinGeneratorTest and the golden tests.
* `Mutable` messsages now have access to mutable `unknownFields`. Test: Updated KotlinGeneratorTest and the golden tests.
* Regenerate golden files. * Update API files for `wire-gradle-plugin`. * Update API files for `wire-kotlin-generator`. * Spotless checks.
8fbb653
to
88666f2
Compare
wire-golden-files/src/main/kotlin/squareup/wire/mutable/MutableHeader.kt
Show resolved
Hide resolved
) | ||
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 comment
The 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is rad
ProtoSink
.Builder
s and sonewBuilder()
throws anUnsupportedOperationException()
.copy(...)
.hashCode()
is no longer cached.redact()
.Test: Added a unit test in
KotlinGeneratorTest
.