]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | /* | |
3 | * This file is open source software, licensed to you under the terms | |
4 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file | |
5 | * distributed with this work for additional information regarding copyright | |
6 | * ownership. You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | /* | |
20 | * Copyright (C) 2014 Cloudius Systems, Ltd. | |
21 | */ | |
7c673cae FG |
22 | |
23 | #ifndef CEPH_MSG_BYTEORDER_H_ | |
24 | #define CEPH_MSG_BYTEORDER_H_ | |
25 | ||
26 | #include <arpa/inet.h> // for ntohs() and friends | |
27 | #include <iosfwd> | |
28 | #include <utility> | |
29 | ||
30 | inline uint64_t ntohq(uint64_t v) { | |
31 | return __builtin_bswap64(v); | |
32 | } | |
33 | inline uint64_t htonq(uint64_t v) { | |
34 | return __builtin_bswap64(v); | |
35 | } | |
36 | ||
37 | inline void ntoh() {} | |
38 | inline void hton() {} | |
39 | ||
40 | inline uint8_t ntoh(uint8_t x) { return x; } | |
41 | inline uint8_t hton(uint8_t x) { return x; } | |
42 | inline uint16_t ntoh(uint16_t x) { return ntohs(x); } | |
43 | inline uint16_t hton(uint16_t x) { return htons(x); } | |
44 | inline uint32_t ntoh(uint32_t x) { return ntohl(x); } | |
45 | inline uint32_t hton(uint32_t x) { return htonl(x); } | |
46 | inline uint64_t ntoh(uint64_t x) { return ntohq(x); } | |
47 | inline uint64_t hton(uint64_t x) { return htonq(x); } | |
48 | ||
49 | inline int8_t ntoh(int8_t x) { return x; } | |
50 | inline int8_t hton(int8_t x) { return x; } | |
51 | inline int16_t ntoh(int16_t x) { return ntohs(x); } | |
52 | inline int16_t hton(int16_t x) { return htons(x); } | |
53 | inline int32_t ntoh(int32_t x) { return ntohl(x); } | |
54 | inline int32_t hton(int32_t x) { return htonl(x); } | |
55 | inline int64_t ntoh(int64_t x) { return ntohq(x); } | |
56 | inline int64_t hton(int64_t x) { return htonq(x); } | |
57 | ||
58 | #endif /* CEPH_MSG_BYTEORDER_H_ */ |