com.github.frtu.kotlin.protobuf.BaseFieldMetadataHelper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lib-serdes-protobuf Show documentation
Show all versions of lib-serdes-protobuf Show documentation
Library for adding metadata to protobuf
package com.github.frtu.kotlin.protobuf
import com.google.protobuf.DescriptorProtos.FieldOptions
import com.google.protobuf.Descriptors
import com.google.protobuf.GeneratedMessage
import java.util.*
open class BaseFieldMetadataHelper(
private val fieldExtention: GeneratedMessage.GeneratedExtension,
) {
fun getExtension(fieldDescriptor: Descriptors.FieldDescriptor?): T? {
if (fieldDescriptor == null) {
return null
}
val options = fieldDescriptor.options
return options.getExtension(fieldExtention)
}
fun hasExtension(fieldDescriptor: Descriptors.FieldDescriptor?): Boolean {
return getExtension(fieldDescriptor) != null
}
}