Skip to content

protocol: Make T_DATUM_PROTOCOL_HEADER serialisation explicit#185

Open
luke-jr wants to merge 1 commit intoOCEAN-xyz:masterfrom
luke-jr:port_explicit_header_pk
Open

protocol: Make T_DATUM_PROTOCOL_HEADER serialisation explicit#185
luke-jr wants to merge 1 commit intoOCEAN-xyz:masterfrom
luke-jr:port_explicit_header_pk

Conversation

@luke-jr
Copy link
Copy Markdown
Contributor

@luke-jr luke-jr commented Apr 6, 2026

Should improve portability

In particular, this fixes big endian systems, as well as:
warning: bit-field ___ of type ___ has a different storage size than the preceding bit-field and will not be packed under the Microsoft ABI [-Wms-bitfield-padding]

Should improve portability

In particular, this fixes big endian systems, as well as:
	warning: bit-field ___ of type ___ has a different storage size than the preceding bit-field and will not be packed under the Microsoft ABI  [-Wms-bitfield-padding]
@luke-jr luke-jr requested review from Copilot and wizkid057 April 6, 2026 22:28
@luke-jr luke-jr added the portability Issues relating to running DATUM Gateway on new platforms label Apr 6, 2026
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

This PR makes T_DATUM_PROTOCOL_HEADER wire serialization/deserialization explicit (fixed 4-byte little-endian value), improving portability across big-endian systems and avoiding MS ABI bit-field packing warnings.

Changes:

  • Replace packed/bitfield-based header wire layout with explicit pack/unpack helpers (datum_header_pk / datum_header_upk).
  • Introduce T_DATUM_PROTOCOL_HEADER_WIRE_BYTES and update send/recv paths to use the explicit 4-byte wire header.
  • Remove the old in-place XOR-on-struct helper that depended on casting the header to uint32_t.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/datum_protocol.h Updates header struct fields and defines the fixed wire header size.
src/datum_protocol.c Adds explicit header pack/unpack functions and switches protocol I/O to use them.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/datum_protocol.h
Comment thread src/datum_protocol.c
Comment on lines +1740 to 1743
if ((n + (sizeof(wire_h) - protocol_state)) != sizeof(wire_h)) {
if ((n+protocol_state) > 4) {
DLOG_DEBUG("recv() issue. too many header bytes. protocol_state=%d, n=%d, errno=%d (%s)", protocol_state, n, errno, strerror(errno));
break_again = true; break;
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

This check uses a hard-coded header size (4). Since the header size is now abstracted via wire_h/T_DATUM_PROTOCOL_HEADER_WIRE_BYTES, use sizeof(wire_h) (or the macro) here too to avoid future inconsistencies if the wire header size changes.

Copilot uses AI. Check for mistakes.
Comment thread src/datum_protocol.c
}
if (n != sizeof(T_DATUM_PROTOCOL_HEADER)) {
if (n != sizeof(wire_h)) {
if (n > 4) {
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

This branch still hard-codes 4 as the maximum header byte count. For consistency with the rest of this state machine, replace it with sizeof(wire_h) (or T_DATUM_PROTOCOL_HEADER_WIRE_BYTES).

Suggested change
if (n > 4) {
if (n > sizeof(wire_h)) {

Copilot uses AI. Check for mistakes.
Comment thread src/datum_protocol.c
}

protocol_state = sizeof(T_DATUM_PROTOCOL_HEADER) - n - (sizeof(T_DATUM_PROTOCOL_HEADER) - protocol_state); // should give us a state equal to the number of. consoluted to show the process. (compiler optimizes)
protocol_state = sizeof(wire_h) - n - (sizeof(wire_h) - protocol_state); // should give us a state equal to the number of. consoluted to show the process. (compiler optimizes)
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

Typo in comment: “consoluted” should be “convoluted”.

Suggested change
protocol_state = sizeof(wire_h) - n - (sizeof(wire_h) - protocol_state); // should give us a state equal to the number of. consoluted to show the process. (compiler optimizes)
protocol_state = sizeof(wire_h) - n - (sizeof(wire_h) - protocol_state); // should give us a state equal to the number of. convoluted to show the process. (compiler optimizes)

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

portability Issues relating to running DATUM Gateway on new platforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants