Byte Order of multi byte values

Skip to first unread message

Stefan Schmelz

Jan 19, 2023, 3:59:43 AMJan 19

Hey everyone,
Do you guys know if I have to ensure Byte Order for multi byte values and larger integers?
I was working on a project that did parts of the encoding themselves, so Big-/Little endianness would be ensured. 

Now I am refactoring a fork of that library for myself and wanted to remove anything that is unnecessary. Encoding a 64bit integer as an array of 8 bytes is a little excessive, so I would like to remove it.

Nonetheless I still need to ensure that Linux, windows, Mac OS work on all hardware platforms. I did read the documentation as if capnp would ensure that everything will be encoded and decoded correctly on every platform. 

I'm improving on prior work, but try to eliminate some naive mistakes we made the first time. By now I have written a schema generator and a primitive schema registry. You can create global schema that are stored in a central location and symlinked into your source. The central directory can be converted to a git repo, so it can be shared. You can also generate local schema, that are stored in your sources. 

The original project used python to generate wrapping C++ classes to automatically load from byte arrays and do some validation... At that time nothing like this was documented by Capnproto so we did everything ourselves. 

Kenton Varda

Jan 24, 2023, 2:01:20 PMJan 24
to Stefan Schmelz,
Hi Stefan,

Cap'n Proto automatically takes care of byte ordering. You do not need to worry about this.

Generally, all modern serialization libraries will take care of endianness automatically. The only time you need to worry about byte-swapping is if you are reading raw bytes from the wire and interpreting them as integers yourself, without the help of a serialization library like Cap'n Proto.

Note that Cap'n Proto uses little-endian encoding on the wire. Almost all processors in wide use these days are little-endian, so this issue hardly even comes up anymore. However, Cap'n Proto is designed to detect if it is running on a big-endian architecture and, if so, it'll swap the bytes automatically.


You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages