Skip to content

Commit 0542df5

Browse files
pdvriezeshanshin
authored andcommitted
Don't throw exception on the presence of a ProtoPacked annotation when it is not valid,
instead silently ignore it, the same as it would be by the serializer itself.
1 parent 9e2040b commit 0542df5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/schema/ProtoBufSchemaGenerator.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ public object ProtoBufSchemaGenerator {
200200
val isPackRequested = annotations.filterIsInstance<ProtoPacked>().singleOrNull() != null
201201

202202
when {
203-
!isPackRequested -> appendLine(';')
204-
!isList -> throw IllegalArgumentException("ProtoPacked annotation provided for ${messageDescriptor.getElementName(index)}: $fieldDescriptor, but packing is only valid on repeated fields (lists)")
205-
!fieldDescriptor.getElementDescriptor(0).isPackable -> throw IllegalArgumentException("ProtoPacked annotation provided for ${messageDescriptor.getElementName(index)}: $fieldDescriptor, but packed can only be applied to primitive numeric types")
203+
!isPackRequested ||
204+
!isList || // ignore as packed only meaningful on repeated types
205+
!fieldDescriptor.getElementDescriptor(0).isPackable // Ignore if the type is not allowed to be packed
206+
-> appendLine(';')
206207
else -> appendLine(" [packed=true];")
207208
}
208209
}

0 commit comments

Comments
 (0)