Menu

Byte order belongs at the call site, not in a library default
📰

Byte order belongs at the call site, not in a library default

DEV Community: cpp·polycratia·1 day ago
#3GPC7Cjk
#devtocpp#devto#dev#order#endian
Long article (2071 words) — no AI summary yet.
Reading 0:00
15s threshold

A wire format fixes its byte order. The host it runs on has one of its own, and the two agree only by accident. When a binary parsing library lets the order go unstated (a u16() with no argument, a packed struct, a memcpy into a uint32_t ), the host answers a question that only the format's specification is allowed to answer, and the code is correct on the machine it was written on. Make the order a required argument of every multi-byte read and write and that answer moves into the call site, which is the only place a reviewer can hold it next to the spec.

I have been shipping payments and crypto systems since 2018: card rails and account-to-account flows, custodial wallet services for BTC and ETH, an on-chain payment system, e-signature document workflows. Underneath all of it sits the same shape, a record that arrives as bytes (a tag, a version, a length, a body), and the orders are not uniform.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.