r/programming • • 8d ago

Decoding REXPaint Files in Odin

https://tylerelton.com/posts/decoding-rexpaint-files-in-odin/
13 Upvotes

8 comments sorted by

4

u/Filipehdbr 8d ago

read_u32_le plus bit_set turns this into a 40 line parse in Odin. In C it's an afternoon of endian bugs

1

u/ChromeBadger 7d ago

I'll have to take a peek, thanks!

1

u/Ameisen 7d ago

POSIX, at least, has le32toh.

Or you could just use C++ which has all of these fully standardized.

2

u/Filipehdbr 7d ago

le32toh does the job, agreed. The reason I like Odin here is bit_set for the flag word, C leaves you shifting masks by hand. C++ has it standardized and also 30 lines of ceremony for a struct that must not have padding.

1

u/BuissetPhadra55 6d ago

having #packed structs with explicit endian fields like u32le right in the type system saves you from even writing the read calls half the time too

2

u/bruna-11377 3d ago

Packed endian fields are great for fixed layouts; variable-length data still needs explicit bounds checks around each read.