doc.odin 940 B

123456789101112131415161718192021222324
  1. /*
  2. Package endian implements a simple translation between bytes and numbers with
  3. specific endian encodings.
  4. Example:
  5. buf: [100]u8
  6. put_u16(buf[:], .Little, 16) or_return
  7. // You may ask yourself, why isn't `byte_order` platform Endianness by default, so we can write:
  8. put_u16(buf[:], 16) or_return
  9. // The answer is that very few file formats are written in native/platform endianness. Most of them specify the endianness of
  10. // each of their fields, or use a header field which specifies it for the entire file.
  11. // e.g. a file which specifies it at the top for all fields could do this:
  12. file_order := .Little if buf[0] == 0 else .Big
  13. field := get_u16(buf[1:], file_order) or_return
  14. // If on the other hand a field is *always* Big-Endian, you're wise to explicitly state it for the benefit of the reader,
  15. // be that your future self or someone else.
  16. field := get_u16(buf[:], .Big) or_return
  17. */
  18. package encoding_endian