src/nint128/nint128_endians

Source   Edit  

This module copies the structure of the stew/endians2 package, as well as uses it.

Procs

func fromBE(x: UInt128): UInt128 {.inline, ...raises: [], tags: [], forbids: [].}
Convert a big endian value to a native endian. Same as toBE(). Source   Edit  
func fromBytes(T: typedesc[UInt128]; x: openArray[byte];
               endian: Endianness = system.cpuEndian): UInt128 {.inline.}

Converts the sequence of bytes in x to a UInt128 according to the given endianness.

Note: The default value of system.cpuEndian is not portable across machines.

Panics when len(x) < 16. For shorter buffers, copy the data to an array, taking care to zero-fill at the right end - usually the beginning for big endian and the end for little endian, but this depends on the serialization of the bytes.

Source   Edit  
func fromBytesBE(T: typedesc[UInt128]; x: openArray[byte]): UInt128 {.inline.}
Converts a sequence of big endian bytes to a UInt128. x must be at least 16 bytes long. Source   Edit  
func fromBytesLE(T: typedesc[UInt128]; x: openArray[byte]): UInt128 {.inline.}
Converts a sequence of little endian bytes to a UInt128. x must be at least 16 bytes long. Source   Edit  
func fromLE(x: UInt128): UInt128 {.inline, ...raises: [], tags: [], forbids: [].}
Convert a little endian value to a native endian. Same as toLE(). Source   Edit  
func swapBytes(x: UInt128): UInt128 {.inline, ...raises: [], tags: [], forbids: [].}
Returns x with the order of the bytes reversed. Source   Edit  
func toBE(x: UInt128): UInt128 {.inline, ...raises: [], tags: [], forbids: [].}
Convert a native endian value to big endian. Consider toBytesBE() instead which may prevent some confusion. Source   Edit  
func toBytes(x: UInt128; endian: Endianness = system.cpuEndian): array[16, byte] {.
    inline, ...raises: [], tags: [], forbids: [].}
Convert x to its corresponding byte sequence using the chosen endianness. By default, native endianness is used which is not portable! Source   Edit  
func toBytesBE(x: UInt128): array[16, byte] {.inline, ...raises: [], tags: [],
    forbids: [].}
Convert a native endian integer to a big endian byte sequence. Source   Edit  
func toBytesLE(x: UInt128): array[16, byte] {.inline, ...raises: [], tags: [],
    forbids: [].}
Convert a native endian integer to a little endian byte sequence. Source   Edit  
func toLE(x: UInt128): UInt128 {.inline, ...raises: [], tags: [], forbids: [].}
Convert a native endian value to little endian. Consider toBytesLE() instead which may prevent some confusion. Source   Edit