Skip to content

Commit

Permalink
CBOR: fix EncodingUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusMcCloud committed Jul 1, 2024
1 parent d7397b2 commit 897ff72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ internal class CborDecoder(private val input: ByteArrayInput) {
input.readExactNBytes(strLen)
}

@SuppressAnimalSniffer
private fun processTags(tags: ULongArray?): ULongArray? {
var index = 0
val collectedTags = mutableListOf<ULong>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,21 @@ internal fun SerialDescriptor.isInlineByteString(): Boolean {
}

@OptIn(ExperimentalSerializationApi::class)
internal fun SerialDescriptor.getValueTags(index: Int): ULongArray? {
return kotlin.runCatching { (getElementAnnotations(index).find { it is ValueTags } as ValueTags?)?.tags }
.getOrNull()
}
internal fun SerialDescriptor.getValueTags(index: Int): ULongArray? = findAnnotation<ValueTags>(index)?.tags


@OptIn(ExperimentalSerializationApi::class)
internal fun SerialDescriptor.getKeyTags(index: Int): ULongArray? {
return kotlin.runCatching { (getElementAnnotations(index).find { it is KeyTags } as KeyTags?)?.tags }.getOrNull()
}
internal fun SerialDescriptor.getKeyTags(index: Int): ULongArray? = findAnnotation<KeyTags>(index)?.tags

@OptIn(ExperimentalSerializationApi::class)
internal fun SerialDescriptor.getCborLabel(index: Int): Long? {
return kotlin.runCatching { getElementAnnotations(index).filterIsInstance<CborLabel>().firstOrNull()?.label }
.getOrNull()
}
internal fun SerialDescriptor.getCborLabel(index: Int): Long? = findAnnotation<CborLabel>(index)?.label

@OptIn(ExperimentalSerializationApi::class)
internal fun SerialDescriptor.hasArrayTag(): Boolean {
return annotations.filterIsInstance<CborArray>().isNotEmpty()
return annotations.any { it is CborArray }
}

@OptIn(ExperimentalSerializationApi::class)
internal inline fun <reified A : Annotation> SerialDescriptor.findAnnotation(elementIndex: Int): A? =
getElementAnnotations(elementIndex).firstOrNull { it is A } as A?

0 comments on commit 897ff72

Please sign in to comment.