Skip to content

refactor!: drop CT_ prefix from ContentFormat constants, change type to int (uint16) - #160

Open
szysas wants to merge 1 commit into
next-4from
next-5
Open

szysas wants to merge 1 commit into
next-4from
next-5

Conversation

@szysas

@szysas szysas commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

The prefix carried no information once the class name says it: ContentFormat.CT_APPLICATION_JSON stutters, ContentFormat.APPLICATION_JSON does not.

Fix three long-standing defects in their names:

CT_APPLICATION_LINK__FORMAT -> APPLICATION_LINK_FORMAT double underscore
CT_APPLICATION_OCTET__STREAM -> APPLICATION_OCTET_STREAM double underscore
CT_APPLICATION_CODE_* -> APPLICATION_COSE_* "CODE" is a typo for COSE

Pure rename, no behaviour or type change.

Content-Format is a uint16 in RFC 7252, but it was modelled as a signed short. Parsing did setContentFormat((short) data.toLong()), so any content format >= 32768 -- the whole upper half of the IANA registry, including the 65000+ experimental range -- was truncated to a negative number and re-serialized wrong. A round trip of 32768 produced 0.

Retype content format to int/Integer across the constants, header options, builders and factories. The parser assigns the field directly rather than going through the setter, so a malformed peer sending a value outside the uint16 range cannot throw out of the deserializer.

Fix the neighbouring types that cannot represent their domains either: the option-number constants (byte -> int, option numbers are uint), DEFAULT_MAX_AGE (short -> long, matching the Long maxAge field), CoapConstants.MAX_RETRANSMIT (Short -> int) and LinkFormat content type (Short -> Integer). Collapse the setAccept(short) / setAccept(Integer) overload trap into a single method.

BREAKING CHANGE: ContentFormat constants have lost the CT_ prefix, and the misspelled CT_APPLICATION_CODE_*, CT_APPLICATION_LINK__FORMAT and CT_APPLICATION_OCTET__STREAM names are corrected. Content format is Integer/int instead of Short/short across header options, builders and factories;

…to int (uint16)

The prefix carried no information once the class name says it:
`ContentFormat.CT_APPLICATION_JSON` stutters, `ContentFormat.APPLICATION_JSON`
does not.

Fix three long-standing defects in their names:

  CT_APPLICATION_LINK__FORMAT  -> APPLICATION_LINK_FORMAT   double underscore
  CT_APPLICATION_OCTET__STREAM -> APPLICATION_OCTET_STREAM  double underscore
  CT_APPLICATION_CODE_*        -> APPLICATION_COSE_*        "CODE" is a typo for COSE

Pure rename, no behaviour or type change.

Content-Format is a uint16 in RFC 7252, but it was modelled as a signed
short. Parsing did `setContentFormat((short) data.toLong())`, so any
content format >= 32768 -- the whole upper half of the IANA registry,
including the 65000+ experimental range -- was truncated to a negative
number and re-serialized wrong. A round trip of 32768 produced 0.

Retype content format to `int`/`Integer` across the constants, header
options, builders and factories. The parser assigns the field directly
rather than going through the setter, so a malformed peer sending a
value outside the uint16 range cannot throw out of the deserializer.

Fix the neighbouring types that cannot represent their domains either:
the option-number constants (byte -> int, option numbers are uint),
`DEFAULT_MAX_AGE` (short -> long, matching the `Long maxAge` field),
`CoapConstants.MAX_RETRANSMIT` (Short -> int) and `LinkFormat` content
type (Short -> Integer). Collapse the `setAccept(short)` /
`setAccept(Integer)` overload trap into a single method.

BREAKING CHANGE: `ContentFormat` constants have lost the `CT_` prefix, and
the misspelled `CT_APPLICATION_CODE_*`, `CT_APPLICATION_LINK__FORMAT` and
`CT_APPLICATION_OCTET__STREAM` names are corrected. Content format is `Integer`/`int` instead of
`Short`/`short` across header options, builders and factories;
@szysas
szysas added this pull request to stack #159 September 24, 2026 11:52
@szysas
szysas marked this pull request as ready for review September 24, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant