element

fun element(elementName: String, descriptor: SerialDescriptor, annotations: List<Annotation> = emptyList(), isOptional: Boolean = false)(source)

Add an element with a given name, descriptor, type annotations and optionality the resulting descriptor.

Example of usage:

class Data(
val intField: Int? = null, // Optional, has default value
@ProtoNumber(1) val longField: Long
)

// Corresponding descriptor
SerialDescriptor("package.Data") {
element<Int?>("intField", isOptional = true)
element<Long>("longField", annotations = listOf(protoIdAnnotationInstance))
}