Skip to content

Commit 6ad8fd7

Browse files
committed
Fix size calculation for repeated fields
1 parent 05ecf32 commit 6ad8fd7

File tree

8 files changed

+87
-87
lines changed

8 files changed

+87
-87
lines changed

protobuf/protobuf-core/src/commonMain/generated-code/kotlin-multiplatform/com/google/protobuf/kotlin/_rpc_internal/Api.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ private fun com.google.protobuf.kotlin.ApiInternal.computeSize(): Int {
256256
}
257257

258258
if (methods.isNotEmpty()) {
259-
__result = methods.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(2, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
259+
__result += methods.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(2, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
260260
}
261261

262262
if (options.isNotEmpty()) {
263-
__result = options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(3, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
263+
__result += options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(3, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
264264
}
265265

266266
if (version.isNotEmpty()) {
@@ -272,7 +272,7 @@ private fun com.google.protobuf.kotlin.ApiInternal.computeSize(): Int {
272272
}
273273

274274
if (mixins.isNotEmpty()) {
275-
__result = mixins.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(6, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
275+
__result += mixins.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(6, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
276276
}
277277

278278
if (syntax != com.google.protobuf.kotlin.Syntax.SYNTAX_PROTO2) {
@@ -396,7 +396,7 @@ private fun com.google.protobuf.kotlin.MethodInternal.computeSize(): Int {
396396
}
397397

398398
if (options.isNotEmpty()) {
399-
__result = options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(6, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
399+
__result += options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(6, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
400400
}
401401

402402
if (syntax != com.google.protobuf.kotlin.Syntax.SYNTAX_PROTO2) {

protobuf/protobuf-core/src/commonMain/generated-code/kotlin-multiplatform/com/google/protobuf/kotlin/_rpc_internal/FieldMask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public fun com.google.protobuf.kotlin.FieldMaskInternal.Companion.decodeWith(msg
8181
private fun com.google.protobuf.kotlin.FieldMaskInternal.computeSize(): Int {
8282
var __result = 0
8383
if (paths.isNotEmpty()) {
84-
__result = paths.sumOf { kotlinx.rpc.protobuf.internal.WireSize.string(it) + kotlinx.rpc.protobuf.internal.WireSize.tag(1, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
84+
__result += paths.sumOf { kotlinx.rpc.protobuf.internal.WireSize.string(it) + kotlinx.rpc.protobuf.internal.WireSize.tag(1, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
8585
}
8686

8787
return __result

protobuf/protobuf-core/src/commonMain/generated-code/kotlin-multiplatform/com/google/protobuf/kotlin/_rpc_internal/Struct.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public fun com.google.protobuf.kotlin.ListValueInternal.Companion.decodeWith(msg
375375
private fun com.google.protobuf.kotlin.ListValueInternal.computeSize(): Int {
376376
var __result = 0
377377
if (values.isNotEmpty()) {
378-
__result = values.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(1, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
378+
__result += values.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(1, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
379379
}
380380

381381
return __result

protobuf/protobuf-core/src/commonMain/generated-code/kotlin-multiplatform/com/google/protobuf/kotlin/_rpc_internal/Type.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,15 @@ private fun com.google.protobuf.kotlin.TypeInternal.computeSize(): Int {
347347
}
348348

349349
if (fields.isNotEmpty()) {
350-
__result = fields.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(2, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
350+
__result += fields.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(2, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
351351
}
352352

353353
if (oneofs.isNotEmpty()) {
354-
__result = oneofs.sumOf { kotlinx.rpc.protobuf.internal.WireSize.string(it) + kotlinx.rpc.protobuf.internal.WireSize.tag(3, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
354+
__result += oneofs.sumOf { kotlinx.rpc.protobuf.internal.WireSize.string(it) + kotlinx.rpc.protobuf.internal.WireSize.tag(3, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
355355
}
356356

357357
if (options.isNotEmpty()) {
358-
__result = options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(4, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
358+
__result += options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(4, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
359359
}
360360

361361
if (presenceMask[0]) {
@@ -519,7 +519,7 @@ private fun com.google.protobuf.kotlin.FieldInternal.computeSize(): Int {
519519
}
520520

521521
if (options.isNotEmpty()) {
522-
__result = options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(9, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
522+
__result += options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(9, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
523523
}
524524

525525
if (jsonName.isNotEmpty()) {
@@ -639,11 +639,11 @@ private fun com.google.protobuf.kotlin.EnumInternal.computeSize(): Int {
639639
}
640640

641641
if (enumvalue.isNotEmpty()) {
642-
__result = enumvalue.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(2, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
642+
__result += enumvalue.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(2, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
643643
}
644644

645645
if (options.isNotEmpty()) {
646-
__result = options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(3, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
646+
__result += options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(3, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
647647
}
648648

649649
if (presenceMask[0]) {
@@ -731,7 +731,7 @@ private fun com.google.protobuf.kotlin.EnumValueInternal.computeSize(): Int {
731731
}
732732

733733
if (options.isNotEmpty()) {
734-
__result = options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(3, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
734+
__result += options.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(3, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
735735
}
736736

737737
return __result

protoc-gen/protobuf/src/main/kotlin/kotlinx/rpc/protoc/gen/ModelToProtobufKotlinCommonGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ class ModelToProtobufKotlinCommonGenerator(
734734
is FieldType.List -> when {
735735
// packed fields also have the tag + len
736736
field.dec.isPacked -> code("__result += $valueSize.let { $tagSize + ${int32SizeCall("it")} + it }")
737-
else -> code("__result = $valueSize")
737+
else -> code("__result += $valueSize")
738738
}
739739

740740
is FieldType.Message,

tests/protobuf-conformance/src/main/generated-code/kotlin-multiplatform/com/google/protobuf/conformance/_rpc_internal/Conformance.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fun com.google.protobuf.conformance.FailureSetInternal.Companion.decodeWith(msg:
321321
private fun com.google.protobuf.conformance.FailureSetInternal.computeSize(): Int {
322322
var __result = 0
323323
if (test.isNotEmpty()) {
324-
__result = test.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(2, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
324+
__result += test.sumOf { it.asInternal()._size + kotlinx.rpc.protobuf.internal.WireSize.tag(2, kotlinx.rpc.protobuf.internal.WireType.LENGTH_DELIMITED) }
325325
}
326326

327327
return __result

0 commit comments

Comments
 (0)