Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public final class CBORConstants
*/
public final static int TAG_ID_SELF_DESCRIBE = 55799;

/**
* Tag denoting a namespace for string references in the following value.
* @since 2.15
*/
public final static int TAG_ID_STRINGREF_NAMESPACE = 256;

/**
* Tag denoting the next integer value should be an index for a previous string.
* @since 2.15
*/
public final static int TAG_ID_STRINGREF = 25;

/*
/**********************************************************
/* Actual type and marker bytes
Expand Down Expand Up @@ -141,4 +153,13 @@ public static boolean hasMajorType(int expType, byte encoded) {
int actual = (encoded & MASK_MAJOR_TYPE) >> 5;
return (actual == expType);
}

public static boolean shouldReferenceString(int index, int stringBytes) {
// See table in specification: http://cbor.schmorp.de/stringref
// Only support 32-bit indices.
return (index >= 0 && index <= 23 && stringBytes >= 3) ||
(index >= 24 && index <= 255 && stringBytes >= 4) ||
(index >= 256 && index <= 65535 && stringBytes >= 5) ||
(index >= 65536 && stringBytes >= 7);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ private final CBORGenerator _createCBORGenerator(IOContext ctxt,
if (CBORGenerator.Feature.WRITE_TYPE_HEADER.enabledIn(formatFeat)) {
gen.writeTag(CBORConstants.TAG_ID_SELF_DESCRIBE);
}
if (CBORGenerator.Feature.STRINGREF.enabledIn(formatFeat)) {
gen.writeTag(CBORConstants.TAG_ID_STRINGREF_NAMESPACE);
}
return gen;
}

Expand Down
Loading