WebURL Documentation Beta

Enumeration Octet​Arrangement

public enum OctetArrangement 

The way in which octets are arranged to form a multi-byte integer.

Applications should prefer to work with individual octets wherever possible, as octets have a consistent numeric interpretation and binary representation across machines of different endianness.

When combining octets in to larger (e.g. 16- or 32-bit) integers, we have to consider that machines have a choice in how their octets are arranged in memory. For instance, the first piece of the IPv6 address 2608::3:5 consists of 2 octets, 0x26 and 0x08; if we created a 16-bit integer with those same octets arranged in that order, a big-endian machine would read this as having numeric value 9736 (for the purposes of integer-level operations, such as addition), whereas a little-endian machine would consider the same octets to contain the numeric value 2086.

Hence there are 2 ways to combine octets in to larger integers:

  1. With the same octets in the same order in memory. We call this the binary interpretation, although it is more-commonly known as "network" byte order, or big-endian. As noted above, integers derived from the same address using the binary interpretation may have different numeric values on different machines.

  2. By rearranging octets to give a consistent numeric value. We call this the numeric interpretation, although it is more-comonly known as "host" byte-order. For instance, when reading the first 16-bit piece of the above address on a little-endian machine, the octets 0x26 0x08 will be reordered to 0x08 0x26, so that the numeric value (9736) is the same as the hexadecimal number 0x2608. Assigning a group of octets using the numeric integer 9736 will similarly reorder the octets, so that they appear as the octet sequence 0x26 0x08 in the address.

Enumeration Cases

numeric

case numeric

Offers consistent numeric values across machines of different endianness, by adjusting the binary representation when reading or writing multi-byte integers. Also known as host byte order (i.e. the integers that you read and write are expected to be in host byte order).

binary

case binary

Offers consistent binary representations across machines of different endianness, although each machine may interpret those bits as a different numeric value. Also known as network byte order (i.e. the integers that you read and write are expected to be in network byte order).

Properties

host​Order

@inlinable public static var hostOrder: Self 

A synonym for .numeric.

network​Order

@inlinable public static var networkOrder: Self 

A synonym for .binary.