3 ms·
This is innovative and kind of brilliant, I'm impressed! - Binary message formatting for efficiency and data integrity (float to/from string is messy) - Famil
by unwind 2y ago
This is innovative and kind of brilliant, I'm impressed!
- Binary message formatting for efficiency and data integrity (float to/from string is messy)
- Familiar printf()-style format strings that the compiler can check[*] gives type safety!
- No preprocessing and/or code generation from message templates or anything like that.
Really nice!
Edits: markdown and grammar.
[*]: This uses an extension I think to mark the argument as a format string
- lelanthran 2y ago> This is innovative and kind of brilliant, I'm impressed! As someone who is not the author of this blog post, I'm glad you are impressed: I wrote pretty much the same thing around 7 years ago: https://www.lelanthran.com/chap2/content.html https://www.lelanthran.com/chap2/content.html The difference with mine is that I intended for the library to be endian-independent, so usable over a network transmission to a different endian machine.[1] Great minds ... (everyone knows how the rest of it goes). [1] I also eschewed using `%` for the format string specifiers, because (in my words at the time): > Our parameterised functions must take a specification that tells it how each field should be written, very similar to the printf and scanf family of functions. While it is indeed possible to reuse the standard format specifiers as our own field specifiers it might not be a good idea to do so as this would break The Principle of Least Astonishment.1 This is because anyone who is changing the code and who sees a string literal with well-known format specifiers such as %02x and %c would naturally (but incorrectly) assume that all format specifiers are supported. We do not wish to confuse the reader.
- thechao 2y agoYou can use `funopencookie` to create a binding of a socket to a `FILE*`; in that case you could literally use fprintf and fscanf to send messages...
- shawn_w 2y ago`fdopen()` is a lot simpler.
- pjmlp 2y agoNot really inovative, this used to be common in C libraries for network programming, back when C paint was still rather fresh.