Skip to content

chuds: check body with a concept - #11

Merged
erics118 merged 2 commits into
mainfrom
chuds/wire-body-check
Oct 17, 2026
Merged

erics118 merged 2 commits into
mainfrom
chuds/wire-body-check

Conversation

@erics118

@erics118 erics118 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

What?

adds chuds::WireBody concept that defines what make_message and body_as
can accept. ie, opt-in marker, trivially copyable, standard layout, size is at most kMaxBody, no padding, no pointer

previously we would just require it to be is_standard_layout_v and is_trivially_copyable_v, as has_unique_object_representations doesn't work for floats.

we now have some compiler magic:

template <class T>
consteval bool has_no_padding_or_pointers() {
    for (const auto byte : std::bit_cast<std::array<unsigned char, sizeof(T)>>(T{})) {
        static_cast<void>(byte);
    }
    return true;
}

at compile time, we default construct an instance of T, and loop over each byte of it. we cannot bit_cast pointers at compile time. we also can't read a byte with an indeterminate at compile time. so, both pointers and padding now properly cause compile errors

rename chuds_wire_body to is_chuds_wire_body to read as a yes/no flag

added tests to assert WireBody works properly, and that bad bodies fail to compile through make_message and body_as

Why?

handles more cases that should be handled: pointers and padding. it would previously cause garbage data to be sent.

follows idiomatic c++

Verification Evidence

the tests pass.

we assert that the WireBody concept works for the shapes of structs that we want it to support, and it properly fails for the shapes that it shouldnt' work for.

we also test that things that should fail to compile do indeed fail to compile

ci also passes.

adds chuds::WireBody concept that defines what make_message and body_as
can accept. ie, opt-in marker, trivially copyable, standard layout, size
is less than kMaxBody, no padding, no pointer

the padding/pointer rule is new, and is something we were missing

rename chuds_wire_body to is_chuds_wire_body to match other c++ concepts

added tests to assert WireBody works properly, and fails to compile
@erics118
erics118 requested a balanced review from Copilot October 17, 2026 05:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@erics118

Copy link
Copy Markdown
Member Author

:/

@danielsapiary danielsapiary left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Small and well-documented and reasoned. Nice

@erics118
erics118 merged commit 495f3b8 into main Oct 17, 2026
8 checks passed
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.

3 participants