Skip to content

Generating ProtoBuf schema using UInt fails #2089

Closed
@alexvas

Description

@alexvas

Unable to generate ProtoBuf schema from a data class containing UInt field. The error is:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid name of the field '[UNINITIALIZED]' in message 'UInt' for class with serial name 'kotlin.UInt'
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.checkIsValidIdentifier(ProtoBufSchemaGenerator.kt:538)
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.generateMessage(ProtoBufSchemaGenerator.kt:172)
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.generateProto2SchemaText(ProtoBufSchemaGenerator.kt:132)
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.generateSchemaText(ProtoBufSchemaGenerator.kt:84)
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.generateSchemaText$default(ProtoBufSchemaGenerator.kt:76)
	at mypackage.ProtocolGeneratorKt.main(ProtocolGenerator.kt:14)
	at mypackage.ProtocolGeneratorKt.main(ProtocolGenerator.kt)

To Reproduce

package mypackage

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator

@Serializable
data class Wrapper(
    val f: UInt,
)

@OptIn(ExperimentalSerializationApi::class)
fun main() {
    val schemas = ProtoBufSchemaGenerator.generateSchemaText(listOf(Wrapper.serializer().descriptor))
    println(schemas)
}

Expected behavior
Schema generated OK. Indeed this is the case after e.g. substitution of UInt with Long. Which is not desired.

Environment

  • Kotlin version: 1.7.10
  • Library version: 1.4.1
  • Kotlin platforms: JVM

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions