Skip to content

encoding.binary #

Description

encoding.binary contains utility functions for converting between an array of bytes ([]u8) and unsigned integers of various widths (u16, u32, and u64).

There are two ways in which bytes can be encoded:

  1. Little endian: The least significant bytes are stored first, followed by the mostsignificant bytes.2. Big endian: The most significant bytes are stored first, opposite to the little endianconvention.

For example, let us take the number 0x12345678. In little endian, the bytes are extracted as 0x78, 0x56, 0x34, and 0x12. In big endian, the bytes are 0x12, 0x34, 0x56, and 0x78.

We follow a similar procedure when we want to go the other way around. Consider the second sequence of bytes in the previous example: 0x12, 0x34, 0x56, and 0x78. If we encode this sequence in little endian format, we get the integer 0x78563412. If we encode this sequence in big endian, we get 0x12345678.

Note > The functions in this module assume appropriately sized u8 arrays. If the sizes > are not valid, the functions will panic.

fn big_endian_get_u16 #

fn big_endian_get_u16(v u16) []u8

big_endian_get_u16 creates u8 array from the unsigned 16-bit integer v in big endian order.

fn big_endian_get_u32 #

fn big_endian_get_u32(v u32) []u8

big_endian_get_u32 creates u8 array from the unsigned 32-bit integer v in big endian order.

fn big_endian_get_u64 #

fn big_endian_get_u64(v u64) []u8

big_endian_get_u64 creates u8 array from the unsigned 64-bit integer v in big endian order.

fn big_endian_put_u16 #

fn big_endian_put_u16(mut b []u8, v u16)

big_endian_put_u16 writes a u16 to the first two bytes in the array b in big endian order.

fn big_endian_put_u16_at #

fn big_endian_put_u16_at(mut b []u8, v u16, o int)

big_endian_put_u16_at writes a u16 to the two bytes in the array b at the specified offset in big endian order.

fn big_endian_put_u16_end #

fn big_endian_put_u16_end(mut b []u8, v u16)

big_endian_put_u16_end writes a u16 to the last two bytes in the array b in big endian order.

fn big_endian_put_u16_fixed #

fn big_endian_put_u16_fixed(mut b [2]u8, v u16)

big_endian_put_u16_fixed writes a u16 to the fixed array b in big endian order.

fn big_endian_put_u32 #

fn big_endian_put_u32(mut b []u8, v u32)

big_endian_put_u32 writes a u32 to the first four bytes in the array b in big endian order.

fn big_endian_put_u32_at #

fn big_endian_put_u32_at(mut b []u8, v u32, o int)

big_endian_put_u32_at writes a u32 to four bytes in the array b at the specified offset in big endian order.

fn big_endian_put_u32_end #

fn big_endian_put_u32_end(mut b []u8, v u32)

big_endian_put_u32_end writes a u32 to the last four bytes in the array b in big endian order.

fn big_endian_put_u32_fixed #

fn big_endian_put_u32_fixed(mut b [4]u8, v u32)

big_endian_put_u32_fixed writes a u32 to the fixed array b in big endian order.

fn big_endian_put_u64 #

fn big_endian_put_u64(mut b []u8, v u64)

big_endian_put_u64 writes a u64 to the first eight bytes in the array b in big endian order.

fn big_endian_put_u64_at #

fn big_endian_put_u64_at(mut b []u8, v u64, o int)

big_endian_put_u64_at writes a u64 to eight bytes in the array b at the specified offset in big endian order.

fn big_endian_put_u64_end #

fn big_endian_put_u64_end(mut b []u8, v u64)

big_endian_put_u64_end writes a u64 to the last eight bytes in the array b at the specified offset in big endian order.

fn big_endian_put_u64_fixed #

fn big_endian_put_u64_fixed(mut b [8]u8, v u64)

big_endian_put_u64_fixed writes a u64 to the fixed array b in big endian order.

fn big_endian_u16 #

fn big_endian_u16(b []u8) u16

big_endian_u16 creates a u16 from the first two bytes in the array b in big endian order.

fn big_endian_u16_at #

fn big_endian_u16_at(b []u8, o int) u16

big_endian_u16_at creates a u16 from two bytes in the array b at the specified offset in big endian order.

fn big_endian_u16_end #

fn big_endian_u16_end(b []u8) u16

big_endian_u16_end creates a u16 from two bytes in the array b at the specified offset in big endian order.

fn big_endian_u16_fixed #

fn big_endian_u16_fixed(b [2]u8) u16

big_endian_u16_fixed creates a u16 from the first two bytes in the fixed array b in big endian order.

fn big_endian_u32 #

fn big_endian_u32(b []u8) u32

big_endian_u32 creates a u32 from four bytes in the array b in big endian order.

fn big_endian_u32_at #

fn big_endian_u32_at(b []u8, o int) u32

big_endian_u32_at creates a u32 from four bytes in the array b at the specified offset in big endian order.

fn big_endian_u32_end #

fn big_endian_u32_end(b []u8) u32

big_endian_u32_end creates a u32 from the last four bytes in the array b in big endian order.

fn big_endian_u32_fixed #

fn big_endian_u32_fixed(b [4]u8) u32

big_endian_u32_fixed creates a u32 from four bytes in the fixed array b in big endian order.

fn big_endian_u64 #

fn big_endian_u64(b []u8) u64

big_endian_u64 creates a u64 from the first eight bytes in the array b in big endian order.

fn big_endian_u64_at #

fn big_endian_u64_at(b []u8, o int) u64

big_endian_u64_at creates a u64 from eight bytes in the array b at the specified offset in big endian order.

fn big_endian_u64_end #

fn big_endian_u64_end(b []u8) u64

big_endian_u64_end creates a u64 from the last eight bytes in the array b in big endian order.

fn big_endian_u64_fixed #

fn big_endian_u64_fixed(b [8]u8) u64

big_endian_u64_fixed creates a u64 from the fixed array b in big endian order.

fn little_endian_f32_at #

fn little_endian_f32_at(b []u8, o int) f32

fn little_endian_get_u16 #

fn little_endian_get_u16(v u16) []u8

little_endian_get_u16 creates u8 array from the unsigned 16-bit integer v in little endian order.

fn little_endian_get_u32 #

fn little_endian_get_u32(v u32) []u8

little_endian_get_u32 creates u8 array from the unsigned 32-bit integer v in little endian order.

fn little_endian_get_u64 #

fn little_endian_get_u64(v u64) []u8

little_endian_get_u64 creates u8 array from the unsigned 64-bit integer v in little endian order.

fn little_endian_put_u16 #

fn little_endian_put_u16(mut b []u8, v u16)

little_endian_put_u16 writes a u16 to the first two bytes in the array b in little endian order.

fn little_endian_put_u16_at #

fn little_endian_put_u16_at(mut b []u8, v u16, o int)

little_endian_put_u16_at writes a u16 to the two bytes in the array b at the specified offset in little endian order.

fn little_endian_put_u16_end #

fn little_endian_put_u16_end(mut b []u8, v u16)

little_endian_put_u16_end writes a u16 to the last two bytes of the array b in little endian order.

fn little_endian_put_u16_fixed #

fn little_endian_put_u16_fixed(mut b [2]u8, v u16)

little_endian_put_u16_fixed writes a u16 to the fixed array b in little endian order.

fn little_endian_put_u32 #

fn little_endian_put_u32(mut b []u8, v u32)

little_endian_put_u32 writes a u32 to the first four bytes in the array b in little endian order.

fn little_endian_put_u32_at #

fn little_endian_put_u32_at(mut b []u8, v u32, o int)

little_endian_put_u32_at writes a u32 to the four bytes in the array b at the specified offset in little endian order.

fn little_endian_put_u32_end #

fn little_endian_put_u32_end(mut b []u8, v u32)

little_endian_put_u32_end writes a u32 to the last four bytes in the array b in little endian order.

fn little_endian_put_u32_fixed #

fn little_endian_put_u32_fixed(mut b [4]u8, v u32)

little_endian_put_u32_fixed writes a u32 to the fixed array b in little endian order.

fn little_endian_put_u64 #

fn little_endian_put_u64(mut b []u8, v u64)

little_endian_put_u64 writes a u64 to the first eight bytes in the array b in little endian order.

fn little_endian_put_u64_at #

fn little_endian_put_u64_at(mut b []u8, v u64, o int)

little_endian_put_u64_at writes a u64 to the eight bytes in the array b at the specified offset in little endian order.

fn little_endian_put_u64_end #

fn little_endian_put_u64_end(mut b []u8, v u64)

little_endian_put_u64_end writes a u64 to the last eight bytes in the array b at in little endian order.

fn little_endian_put_u64_fixed #

fn little_endian_put_u64_fixed(mut b [8]u8, v u64)

little_endian_put_u64_fixed writes a u64 to the fixed array b in little endian order.

fn little_endian_u16 #

fn little_endian_u16(b []u8) u16

little_endian_u16 creates a u16 from the first two bytes in the array b in little endian order.

fn little_endian_u16_at #

fn little_endian_u16_at(b []u8, o int) u16

little_endian_u16_at creates a u16 from two bytes in the array b at the specified offset in little endian order.

fn little_endian_u16_end #

fn little_endian_u16_end(b []u8) u16

little_endian_u16_end creates a u16 from the last two bytes of the array b in little endian order.

fn little_endian_u16_fixed #

fn little_endian_u16_fixed(b [2]u8) u16

little_endian_u16_fixed creates a u16 from the fixed array b in little endian order.

fn little_endian_u32 #

fn little_endian_u32(b []u8) u32

little_endian_u32 creates a u32 from the first four bytes in the array b in little endian order.

fn little_endian_u32_at #

fn little_endian_u32_at(b []u8, o int) u32

little_endian_u32_at creates a u32 from four bytes in the array b at the specified offset in little endian order.

fn little_endian_u32_end #

fn little_endian_u32_end(b []u8) u32

little_endian_u32_end creates a u32 from the last four bytes in the array b in little endian order.

fn little_endian_u32_fixed #

fn little_endian_u32_fixed(b [4]u8) u32

little_endian_u32_fixed creates a u32 from the fixed array b in little endian order.

fn little_endian_u64 #

fn little_endian_u64(b []u8) u64

little_endian_u64 creates a u64 from the first eight bytes in the array b in little endian order.

fn little_endian_u64_at #

fn little_endian_u64_at(b []u8, o int) u64

little_endian_u64_at creates a u64 from eight bytes in the array b at the specified offset in little endian order.

fn little_endian_u64_end #

fn little_endian_u64_end(b []u8) u64

little_endian_u64_end creates a u64 from the last eight bytes in the array b in little endian order.

fn little_endian_u64_fixed #

fn little_endian_u64_fixed(b [8]u8) u64

little_endian_u64_fixed creates a u64 from the fixed array b in little endian order.