-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendian_api_linux.h
27 lines (22 loc) · 940 Bytes
/
endian_api_linux.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-LICENSE-IDENTIFIER: MIT
#ifndef KVARINT_ENDIAN_API_H
#define KVARINT_ENDIAN_API_H
#include <stdint.h>
#include <endian.h>
#include "macro.h"
// network byte order conversion function
/**
* To network byte order
*/
inline uint8_t kvarint_ToNetworkByteOrder8(uint8_t host8) { return host8; }
inline uint16_t kvarint_ToNetworkByteOrder16(uint16_t host16) { return htobe16(host16); }
inline uint32_t kvarint_ToNetworkByteOrder32(uint32_t host32) { return htobe32(host32); }
inline uint64_t kvarint_ToNetworkByteOrder64(uint64_t host64) { return htobe64(host64); }
/**
* To host byte order
*/
inline uint8_t kvarint_ToHostByteOrder8(uint8_t net8) { return net8; }
inline uint16_t kvarint_ToHostByteOrder16(uint16_t net16) { return be16toh(net16); }
inline uint32_t kvarint_ToHostByteOrder32(uint32_t net32) { return be32toh(net32); }
inline uint64_t kvarint_ToHostByteOrder64(uint64_t net64) { return be64toh(net64); }
#endif