Skip to content

net.conv #


net.conv provides a convenient way to convert number values to, and from the network byte order format (which is always big endian).

When communicating across a network, it is possible that the machines use different byte orders, since the host format of each system can vary, depending on the CPU, and on most systems, is usually little endian.

To avoid mismatches due to that, the network byte order is used by convention to send network data in a manner that will be received coherently, regardless of the endianness of the sender system and the receiver system.

fn htn16 #

deprecated: use hton16() instead
deprecated_after: 2023-12-31
fn htn16(host u16) u16

htn16 - DON'T USE, use hton16 instead

fn htn32 #

deprecated: use hton32() instead
deprecated_after: 2023-12-31
fn htn32(host u32) u32

htn32 - DON'T USE, use hton32 instead

fn htn64 #

deprecated: use hton64() instead
deprecated_after: 2023-12-31
fn htn64(host u64) u64

htn64 - DON'T USE, use hton64 instead

fn hton16 #

fn hton16(host u16) u16

hton16 converts the 16 bit value host to the net format (htons)

fn hton32 #

fn hton32(host u32) u32

hton32 converts the 32 bit value host to the net format (htonl)

fn hton64 #

fn hton64(host u64) u64

hton64 converts the 64 bit value host to the net format (htonll)

fn htonf32 #

fn htonf32(host f32) f32

htonf32 converts the 32 bit double host to the net format

fn htonf64 #

fn htonf64(host f64) f64

htonf64 converts the 64 bit double host to the net format

fn nth16 #

deprecated: use ntoh16() instead
deprecated_after: 2023-12-31
fn nth16(net u16) u16

nth16 - DON'T USE, use ntoh16 instead

fn nth32 #

deprecated: use ntoh32() instead
deprecated_after: 2023-12-31
fn nth32(net u32) u32

nth32 - DON'T USE, use ntoh32 instead

fn nth64 #

deprecated: use ntoh64() instead
deprecated_after: 2023-12-31
fn nth64(net u64) u64

nth64 - DON'T USE, use ntoh64 instead

fn ntoh16 #

fn ntoh16(net u16) u16

ntoh16 converts the 16 bit value net to the host format (ntohs)

fn ntoh32 #

fn ntoh32(net u32) u32

ntoh32 converts the 32 bit value net to the host format (ntohl)

fn ntoh64 #

fn ntoh64(net u64) u64

ntoh64 converts the 64 bit value net to the host format (ntohll)

fn u64tovarint #

fn u64tovarint(n u64) ![]u8

u64tovarint converts the given 64 bit number n, where n < 2^62 to a byte array, using the variable length unsigned integer encoding from: . The returned array length .len, will be in [1,2,4,8] .

fn varinttou64 #

fn varinttou64(b []u8) !(u64, u8)

varinttou64 parses a variable length number from the start of the given byte array b. If it succeeds, it returns the decoded number, and the length of the parsed byte span.