Skip to content

[DRAFT] Add TRICK_ENUMERATED type#182

Draft
simnaut wants to merge 1 commit intonasa:masterfrom
simnaut:181
Draft

[DRAFT] Add TRICK_ENUMERATED type#182
simnaut wants to merge 1 commit intonasa:masterfrom
simnaut:181

Conversation

@simnaut
Copy link
Copy Markdown
Contributor

@simnaut simnaut commented Oct 7, 2025

Adding in the TRICK_ENUMERATED type as if it was a TRICK_INTEGER type. (However, not including it to the logical time de/encoding)

Could you check to make sure this isn't a naïve change? I am not able to test this yet, but for now just mean to prompt the conversation and will update here when I have it tested.

#181

Copilot AI review requested due to automatic review settings October 7, 2025 00:19
@simnaut simnaut marked this pull request as draft October 7, 2025 00:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for a new TRICK_ENUMERATED attribute type, handling it similarly to existing integral types, while explicitly excluding it from logical time de/encoding.

  • Add TRICK_ENUMERATED to initialize and is_supported_attribute_type switch cases
  • Handle TRICK_ENUMERATED in byteswap_buffer_copy the same as TRICK_INTEGER (32-bit)
  • No changes to logical time encode/decode paths

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}
break;
}
case TRICK_ENUMERATED:
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This treats TRICK_ENUMERATED as a 32-bit int by casting to int. If TRICK_ENUMERATED is not guaranteed to be 32-bit across platforms, this can produce incorrect byte-swapping. Consider either (a) documenting and guarding the assumption with a compile-time check (e.g., a static_assert that TRICK_ENUMERATED maps to a 4-byte encoding), or (b) selecting the swap width based on the attribute's encoded size (2/4/8 bytes) to make this portable.

Suggested change
case TRICK_ENUMERATED:
case TRICK_ENUMERATED: {
// Swap based on the actual size of TRICK_ENUMERATED.
size_t elem_size = num_bytes / length;
if (elem_size == sizeof(short)) {
short const *e_src = static_cast<short const *>(src);
short *e_dest = static_cast<short *>(dest);
for (int k = 0; k < length; ++k) {
e_dest[k] = Utilities::byteswap_short(e_src[k]);
}
} else if (elem_size == sizeof(int)) {
int const *e_src = static_cast<int const *>(src);
int *e_dest = static_cast<int *>(dest);
for (int k = 0; k < length; ++k) {
e_dest[k] = Utilities::byteswap_int(e_src[k]);
}
} else if (elem_size == sizeof(long long)) {
long long const *e_src = static_cast<long long const *>(src);
long long *e_dest = static_cast<long long *>(dest);
for (int k = 0; k < length; ++k) {
e_dest[k] = Utilities::byteswap_long_long(e_src[k]);
}
} else {
// Unknown size, just copy.
memcpy(dest, src, num_bytes);
}
break;
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

@simnaut simnaut Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good comment. Looking at the trick project, here is their assumption about TRICK_ENUMERATED. Not a full list, and while there appears to be some cases where the enum could be something other than int, it seems more often than not TRICK_ENUMERATED is assumed to be exclusively int.

Comment on lines 351 to +355
case TRICK_LONG:
case TRICK_UNSIGNED_LONG:
case TRICK_LONG_LONG:
case TRICK_UNSIGNED_LONG_LONG: {
case TRICK_UNSIGNED_LONG_LONG:
case TRICK_ENUMERATED: {
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] TRICK_ENUMERATED is grouped with long/long long here, but in byteswap_buffer_copy it is grouped with TRICK_INTEGER. If the behavior is intended to mirror TRICK_INTEGER, consider grouping consistently (or add a brief comment) to avoid confusion about the expected width/semantics for TRICK_ENUMERATED in different code paths.

Copilot uses AI. Check for mistakes.
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.

2 participants