package core:encoding/endian
⌘K
Ctrl+K
or
/
Overview
A simple translation between bytes and numbers with specific endian encodings.
Example:
buf: [100]u8
put_u16(buf[:], .Little, 16) or_return
// You may ask yourself, why isn't `byte_order` platform Endianness by default, so we can write:
put_u16(buf[:], 16) or_return
// The answer is that very few file formats are written in native/platform endianness. Most of them specify the endianness of
// each of their fields, or use a header field which specifies it for the entire file.
// e.g. a file which specifies it at the top for all fields could do this:
file_order := .Little if buf[0] == 0 else .Big
field := get_u16(buf[1:], file_order) or_return
// If on the other hand a field is *always* Big-Endian, you're wise to explicitly state it for the benefit of the reader,
// be that your future self or someone else.
field := get_u16(buf[:], .Big) or_return
Index
Types (1)
Constants (1)
Variables (0)
This section is empty.
Procedures (42)
unchecked_… (20)
- unchecked_get_signed_be
- unchecked_get_signed_le
- unchecked_get_u16be
- unchecked_get_u16le
- unchecked_get_u32be
- unchecked_get_u32le
- unchecked_get_u64be
- unchecked_get_u64le
- unchecked_get_unsigned_be
- unchecked_get_unsigned_le
- unchecked_put_signed_be
- unchecked_put_signed_le
- unchecked_put_u16be
- unchecked_put_u16le
- unchecked_put_u32be
- unchecked_put_u32le
- unchecked_put_u64be
- unchecked_put_u64le
- unchecked_put_unsigned_be
- unchecked_put_unsigned_le
Procedure Groups (0)
This section is empty.
Types
Byte_Order ¶
Byte_Order :: enum u8 { Little, Big, }
Related Procedures With Parameters
Related Constants
Constants
PLATFORM_BYTE_ORDER ¶
PLATFORM_BYTE_ORDER :: Byte_Order.Little when ODIN_ENDIAN == .Little else Byte_Order.Big
Variables
This section is empty.
Procedures
get_f16 ¶
get_f16 :: proc "contextless" (b: []u8, order: Byte_Order) -> (f16, bool) {…}
get_f32 ¶
get_f32 :: proc "contextless" (b: []u8, order: Byte_Order) -> (f32, bool) {…}
get_f64 ¶
get_f64 :: proc "contextless" (b: []u8, order: Byte_Order) -> (f64, bool) {…}
get_i16 ¶
get_i16 :: proc "contextless" (b: []u8, order: Byte_Order) -> (i16, bool) {…}
get_i32 ¶
get_i32 :: proc "contextless" (b: []u8, order: Byte_Order) -> (i32, bool) {…}
get_i64 ¶
get_i64 :: proc "contextless" (b: []u8, order: Byte_Order) -> (i64, bool) {…}
get_signed ¶
get_signed :: proc "contextless" (b: []u8, order: Byte_Order, $N: int) -> (v: i64, ok: bool) {…}
get_u16 ¶
get_u16 :: proc "contextless" (b: []u8, order: Byte_Order) -> (v: u16, ok: bool) {…}
get_u32 ¶
get_u32 :: proc "contextless" (b: []u8, order: Byte_Order) -> (v: u32, ok: bool) {…}
get_u64 ¶
get_u64 :: proc "contextless" (b: []u8, order: Byte_Order) -> (v: u64, ok: bool) {…}
get_unsigned ¶
get_unsigned :: proc "contextless" (b: []u8, order: Byte_Order, $N: int) -> (v: u64, ok: bool) {…}
put_f16 ¶
put_f16 :: proc "contextless" (b: []u8, order: Byte_Order, v: f16) -> bool {…}
put_f32 ¶
put_f32 :: proc "contextless" (b: []u8, order: Byte_Order, v: f32) -> bool {…}
put_f64 ¶
put_f64 :: proc "contextless" (b: []u8, order: Byte_Order, v: f64) -> bool {…}
put_i16 ¶
put_i16 :: proc "contextless" (b: []u8, order: Byte_Order, v: i16) -> bool {…}
put_i32 ¶
put_i32 :: proc "contextless" (b: []u8, order: Byte_Order, v: i32) -> bool {…}
put_i64 ¶
put_i64 :: proc "contextless" (b: []u8, order: Byte_Order, v: i64) -> bool {…}
put_signed ¶
put_signed :: proc "contextless" (b: []u8, order: Byte_Order, v: i64, $N: int) -> bool {…}
put_u16 ¶
put_u16 :: proc "contextless" (b: []u8, order: Byte_Order, v: u16) -> bool {…}
put_u32 ¶
put_u32 :: proc "contextless" (b: []u8, order: Byte_Order, v: u32) -> bool {…}
put_u64 ¶
put_u64 :: proc "contextless" (b: []u8, order: Byte_Order, v: u64) -> bool {…}
put_unsigned ¶
put_unsigned :: proc "contextless" (b: []u8, order: Byte_Order, v: u64, $N: int) -> bool {…}
Procedure Groups
This section is empty.
Source Files
Generation Information
Generated with odin version dev-2026-10 (vendor "odin") Windows_amd64 @ 2026-10-23 23:43:08.089658900 +0000 UTC