Visualizing type layouts with C++ reflection
I frequently deal with binary data transfer protocols in my job, often represented in code as packed structs. It would be nice to have a visual representation of these structs for documentation and when analyzing logs and network dumps. I read through the proposal for reflection in C++26 earlier this year and thought reflection could be a good way to inspect type layouts. I wrote a small library to generate mermaid.js packet diagrams like the one below.
The first step was to get a compiler that supports reflection. At the time of writing this, P2996 is approved for C++26 but not officially implemented in clang or gcc. Fortunately, there is a clang fork developed by Bloomberg that implements experimental support.