Add getExtensionOrNull utility for protobuf messages
This commit is contained in:
+1
-2
@@ -90,8 +90,7 @@ class AnnotationAndConstantLoaderImpl(
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: KotlinType
|
||||
): ConstantValue<*>? {
|
||||
if (!proto.hasExtension(protocol.compileTimeValue)) return null
|
||||
val value = proto.getExtension(protocol.compileTimeValue)
|
||||
val value = proto.getExtensionOrNull(protocol.compileTimeValue) ?: return null
|
||||
return deserializer.resolveValue(expectedType, value, container.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
|
||||
fun <M : GeneratedMessageLite.ExtendableMessage<M>, T> GeneratedMessageLite.ExtendableMessage<M>.getExtensionOrNull(
|
||||
extension: GeneratedMessageLite.GeneratedExtension<M, T>
|
||||
): T? = if (hasExtension(extension)) getExtension(extension) else null
|
||||
Reference in New Issue
Block a user