forked from caosiyang/websocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.h
51 lines (34 loc) · 1002 Bytes
/
tools.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
*
* filename: tools.h
* summary:
* author: caosiyang
* email: [email protected]
*
*/
#ifndef TOOLS_H
#define TOOLS_H
#include <stdio.h>
#include <stdint.h>
#include <iostream>
using namespace std;
#define LOG(format, args...) fprintf(stdout, format"\n", ##args)
inline uint16_t myhtons(uint16_t n) {
return ((n & 0xff00) >> 8) | ((n & 0x00ff) << 8);
}
inline uint16_t myntohs(uint16_t n) {
return ((n & 0xff00) >> 8) | ((n & 0x00ff) << 8);
}
inline uint32_t myhtonl(uint32_t n) {
return ((n & 0xff000000) >> 24) | ((n & 0x00ff0000) >> 8) | ((n & 0x0000ff00) << 8) | ((n & 0x000000ff) << 24);
}
inline uint32_t myntohl(uint32_t n) {
return ((n & 0xff000000) >> 24) | ((n & 0x00ff0000) >> 8) | ((n & 0x0000ff00) << 8) | ((n & 0x000000ff) << 24);
}
inline uint64_t myhtonll(uint64_t n) {
return (uint64_t)myhtonl(n >> 32) | ((uint64_t)myhtonl(n) << 32);
}
inline uint64_t myntohll(uint64_t n) {
return (uint64_t)myhtonl(n >> 32) | ((uint64_t)myhtonl(n) << 32);
}
#endif