3 ms·
Zig is already great for this with ‘packed struct’ and arbitrary size ints. Allows for very clean protocol creation between systems with known properties. This
by allthetime 4mo ago
Zig is already great for this with ‘packed struct’ and arbitrary size ints. Allows for very clean protocol creation between systems with known properties. This is another great step in that direction.
- ulbu 4mo agoyou need different packed structs for little- and big-endian data. and casting with little-endian data is a nightmare - you need to reverse-cascade your struct fields to be in accordance with the little-endian bit-pattern. (or have a comptime function that does it for you, of course. but then you lose all declarations for the struct). what should be a simple writing down of a protocol is now a pedantic and error-prone ordeal.
- hrydgard 4mo agoOr you just go ahead and forget that big endian ever existed. It's not coming back.
- ulbu 4mo agoit’s little-endian protocols that require that you juggle your struct fields. plus, there are still big-endian protocols that will stay for a long time. for example, MIDI clip files in MIDI 2.0 are big-endian.
- charcircuit 4mo agoThis has been largely solved by everyone agreeing to use little endian. There aren't really use cases for wanting to convert between them.
- jstimpfle 4mo agoDoes that mean there are no file formats thatbuse big endian? And network byte order isn't a thing?
- teravor 4mo ago> there are no file formats thatbuse big endian if someone chooses to do that they own the problems. > network byte order isn't a thing if the network serializes/deserializes for you (kernel primitives) then you don't care what it does. if it doesn't and for some reason you choose to use big endian, again, you own the problem.
- dcrazy 4mo agoIf someone chooses to load a TIFF or a PSD or an AIFF or…
- teravor 4mo agothen you either use an existing C library (the most likely approach) or if you are determined to re-implement it you have to be careful parsing their bytes.
- lkjdsklf 4mo agoNetwork byte order has nothing to do with the kernel and you have to care about it It’s a standard because neither side of the connection knows the endianness of the other side so there must be a standard. That standard is big endian regardless of your architecture or kernel or anything else So any serialization intended go over the network should be big endian
- teravor 4mo agoright, so a zig app will just do little endian. in the very unlikely event you have it running on a big endian machine you have to do extra work.
- jstimpfle 4mo agoYou may have never done socket programming, or do you use wrapper libs in Zig? Because you have to send the kernel big endian port numbers for example. What do you do if you program a kernel in Zig, or just generally do low level networking? My point is to refute the statement that everyone has agreed to little endian, and so there aren't use cases to want to do conversion. Programs do not exist in a vacuum, most programs do not.
- deleted 4mo ago[deleted]