package core:encoding/endian
⌘K
Ctrl+K
or
/
Overview
Package endian implements 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 (30)
- get_f16
- get_f32
- get_f64
- get_i16
- get_i32
- get_i64
- get_u16
- get_u32
- get_u64
- put_f16
- put_f32
- put_f64
- put_i16
- put_i32
- put_i64
- put_u16
- put_u32
- put_u64
- unchecked_get_u16be
- unchecked_get_u16le
- unchecked_get_u32be
- unchecked_get_u32le
- unchecked_get_u64be
- unchecked_get_u64le
- unchecked_put_u16be
- unchecked_put_u16le
- unchecked_put_u32be
- unchecked_put_u32le
- unchecked_put_u64be
- unchecked_put_u64le
Procedure Groups (0)
This section is empty.
Types
Byte_Order ¶
Byte_Order :: enum u8 { Little, Big, }
Related Procedures With Parameters
- get_f16
- get_f32
- get_f64
- get_i16
- get_i32
- get_i64
- get_u16
- get_u32
- get_u64
- put_f16
- put_f32
- put_f64
- put_i16
- put_i32
- put_i64
- put_u16
- put_u32
- put_u64
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_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) {…}
Procedure Groups
This section is empty.
Source Files
Generation Information
Generated with odin version dev-2024-11 (vendor "odin") Windows_amd64 @ 2024-11-20 21:11:50.552921700 +0000 UTC