From efe3d1d153314bd19005c5f0bd24986d4f12374a Mon Sep 17 00:00:00 2001 From: Egor Andreevici Date: Sat, 20 Apr 2019 13:53:58 -0400 Subject: [PATCH] Use indexing syntax with FieldBinding --- .../src/main/java/com/squareup/wire/MessageTypeAdapter.kt | 4 ++-- .../src/main/java/com/squareup/wire/MessageJsonAdapter.kt | 4 ++-- .../com/squareup/wire/internal/RuntimeMessageAdapter.kt | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.kt b/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.kt index a2f6925193..fc3d670f82 100644 --- a/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.kt +++ b/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.kt @@ -49,7 +49,7 @@ internal class MessageTypeAdapter, B : Message.Builder>( out.beginObject() for (tagBinding in messageAdapter.fieldBindings.values) { - val value = tagBinding.get(message) ?: continue + val value = tagBinding[message] ?: continue out.name(tagBinding.name) emitJson(out, value, tagBinding.singleAdapter(), tagBinding.label) } @@ -102,7 +102,7 @@ internal class MessageTypeAdapter, B : Message.Builder>( } else { val element = elementAdapter.read(input) val value = parseValue(fieldBinding, element) - fieldBinding.set(builder, value) + fieldBinding[builder] = value } } diff --git a/wire-moshi-adapter/src/main/java/com/squareup/wire/MessageJsonAdapter.kt b/wire-moshi-adapter/src/main/java/com/squareup/wire/MessageJsonAdapter.kt index 3c7a1db87e..390799bfee 100644 --- a/wire-moshi-adapter/src/main/java/com/squareup/wire/MessageJsonAdapter.kt +++ b/wire-moshi-adapter/src/main/java/com/squareup/wire/MessageJsonAdapter.kt @@ -56,7 +56,7 @@ internal class MessageJsonAdapter, B : Message.Builder>( out.beginObject() fieldBindings.forEachIndexed { index, fieldBinding -> out.name(fieldBinding.name) - val value = fieldBinding.get(message) + val value = fieldBinding[message] jsonAdapters[index]?.toJson(out, value) } out.endObject() @@ -87,7 +87,7 @@ internal class MessageJsonAdapter, B : Message.Builder>( // If the value was explicitly null we ignore it rather than forcing null into the field. // Otherwise malformed JSON that sets a list to null will create a malformed message, and // we'd rather just ignore that problem. - fieldBinding.set(builder, value) + fieldBinding[builder] = value } input.endObject() return builder.build() diff --git a/wire-runtime/src/main/java/com/squareup/wire/internal/RuntimeMessageAdapter.kt b/wire-runtime/src/main/java/com/squareup/wire/internal/RuntimeMessageAdapter.kt index 716d78b964..217ac92907 100644 --- a/wire-runtime/src/main/java/com/squareup/wire/internal/RuntimeMessageAdapter.kt +++ b/wire-runtime/src/main/java/com/squareup/wire/internal/RuntimeMessageAdapter.kt @@ -39,7 +39,7 @@ class RuntimeMessageAdapter, B : Builder>( var size = 0 for (fieldBinding in fieldBindings.values) { - val binding = fieldBinding.get(value) ?: continue + val binding = fieldBinding[value] ?: continue size += fieldBinding.adapter().encodedSizeWithTag(fieldBinding.tag, binding) } size += value.unknownFields().size @@ -51,7 +51,7 @@ class RuntimeMessageAdapter, B : Builder>( @Throws(IOException::class) override fun encode(writer: ProtoWriter, value: M) { for (fieldBinding in fieldBindings.values) { - val binding = fieldBinding.get(value) ?: continue + val binding = fieldBinding[value] ?: continue fieldBinding.adapter().encodeWithTag(writer, fieldBinding.tag, binding) } writer.writeBytes(value.unknownFields()) @@ -69,7 +69,7 @@ class RuntimeMessageAdapter, B : Builder>( val builderValue = fieldBinding.getFromBuilder(builder) if (builderValue != null) { val redactedValue = fieldBinding.adapter().redact(builderValue) - fieldBinding.set(builder, redactedValue!!) + fieldBinding[builder] = redactedValue!! } } else if (isMessage && fieldBinding.label.isRepeated) { @Suppress("UNCHECKED_CAST") @@ -91,7 +91,7 @@ class RuntimeMessageAdapter, B : Builder>( override fun toString(value: M): String = buildString { for (fieldBinding in fieldBindings.values) { - val binding = fieldBinding.get(value) + val binding = fieldBinding[value] if (binding != null) { append(", ") append(fieldBinding.name)