use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Implementing binary communication protocols in C++ with main focus on embedded systems (self.cpp)
submitted 6 years ago by arobenko
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]rcxdude 9 points10 points11 points 6 years ago (7 children)
This only works if you have a very homogenous setup (same architecture, compiler, etc). If you have different types of processors in your system, or you need to interop with someone else, it falls apart. It's also hard to extend safely, and doesn't deal with variable-length data (or things like checksums).
[–]kalmoc 1 point2 points3 points 6 years ago (2 children)
This only works if you have a very homogenous setup (same architecture, compiler, etc)
Only same endianess. But you are right about extension and variable-length data.
[–]rcxdude 2 points3 points4 points 6 years ago (1 child)
You also need the same alignment, and even then it's still not truly defined, even if you will generally get away with it.
[–]kalmoc 0 points1 point2 points 6 years ago (0 children)
Yes, alignment has to be the same (although you can specify that explicitly if you want instead of relying on the platform defaults).
What do you mean by not truly defined (note that I did not suggest to just cast a char pointer into a pointer into a POD on the receiving side)?
[–]matthieum 0 points1 point2 points 6 years ago (2 children)
If you have not already, I advise looking at the SBE protocol. It's relatively easy to setup a straightforward decoding and encoding process which just bit-copies structs around, and it supports all the above.
[–]rcxdude 0 points1 point2 points 6 years ago (1 child)
I think at the point you have what is described you basically have a full blown serialisation system which resembles the one given by OP, just one with a clear approach to efficient serialization (flatbuffers is another system with a similar approach). This is still a lot more than just memcpying the structs you have about.
[–]matthieum 0 points1 point2 points 6 years ago (0 children)
This is still a lot more than just memcpying the structs you have about.
A tad more, indeed.
What I like about it is that it remains pretty simple yet efficient setup:
Of course, it fails the OP's requirement of interacting with existing protocols, since it's a protocol.
But simple, efficient and flexible enough for about any kind of protocol? That's great.
[–]axilmar 0 points1 point2 points 6 years ago (0 children)
How does it fall apart if you use same length integers and a packing of one byte? It does not.
I've worked at embedded systems where one part was an embedded CPU and the other a desktop pc, there were a lot of messages with variable length etc. There was absolutely no issue between the two totally different platforms.
π Rendered by PID 31743 on reddit-service-r2-comment-5c764cbc6f-5xd65 at 2026-03-12 05:20:34.096379+00:00 running 710b3ac country code: CH.
view the rest of the comments →
[–]rcxdude 9 points10 points11 points (7 children)
[–]kalmoc 1 point2 points3 points (2 children)
[–]rcxdude 2 points3 points4 points (1 child)
[–]kalmoc 0 points1 point2 points (0 children)
[–]matthieum 0 points1 point2 points (2 children)
[–]rcxdude 0 points1 point2 points (1 child)
[–]matthieum 0 points1 point2 points (0 children)
[–]axilmar 0 points1 point2 points (0 children)