Skip to content

Commit

Permalink
CBOR: get labels only when preferred over serial names
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusMcCloud committed Jul 2, 2024
1 parent 13e2eb0 commit 2439e5e
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ internal sealed class CborWriter(
encodeByteArrayAsByteString = descriptor.isByteString(index)

val name = descriptor.getElementName(index)
val label = descriptor.getCborLabel(index)


if (!descriptor.hasArrayTag()) {
if (cbor.writeKeyTags) descriptor.getKeyTags(index)?.forEach { destination.encodeTag(it) }

if ((descriptor.kind !is StructureKind.LIST) && (descriptor.kind !is StructureKind.MAP) && (descriptor.kind !is PolymorphicKind)) {
//indices are put into the name field. we don't want to write those, as it would result in double writes
if (cbor.preferCborLabelsOverNames && label != null) {
destination.encodeNumber(label)
if (cbor.preferCborLabelsOverNames) {
descriptor.getCborLabel(index)?.let { destination.encodeNumber(it) }
} else {
destination.encodeString(name)
}
Expand Down

0 comments on commit 2439e5e

Please sign in to comment.