Fix serialization of native integral types - #11
Open
swdaa wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes MsgPack serialization for native integral types (e.g., std::size_t) whose underlying type may not be one of the fixed-width integer typedefs, preventing them from incorrectly falling into the custom-object pack()/unpack() fallback.
Changes:
- Added
pack_type/unpack_typeoverloads to route otherwise-unhandledstd::integraltypes through existing fixed-width integer serialization. - Excluded integral types from the custom-object fallback overloads so they don’t attempt
value.pack()/value.unpack().
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+754
to
+764
| void unpack_type(T &value) { | ||
| if constexpr (std::signed_integral<T>) { | ||
| std::int64_t tmp{}; | ||
| unpack_type(tmp); | ||
| value = static_cast<T>(tmp); | ||
| } else { | ||
| std::uint64_t tmp{}; | ||
| unpack_type(tmp); | ||
| value = static_cast<T>(tmp); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix serialization of native integral types that are not aliases of the
fixed-width integer types handled by the existing overloads.
On macOS,
std::size_tisunsigned long, whilestd::uint64_tmay bea different underlying type. As a result,
std::size_tcould fall throughto the custom-object overload and attempt to call
value.pack()/value.unpack().This change routes otherwise-unhandled integral types through the existing
fixed-width integer serialization overloads and excludes integral types from
the custom-object fallback.
Testing
std::vector<std::size_t>array test now compilesctest --test-dir build --output-on-failure