1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
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.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 * Copyright (C) 2014 Cloudius Systems, Ltd.
23 * Ceph - scalable distributed file system
25 * Copyright (C) 2015 XSky <haomai@xsky.com>
27 * Author: Haomai Wang <haomaiwang@gmail.com>
29 * This is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU Lesser General Public
31 * License version 2.1, as published by the Free Software
32 * Foundation. See file COPYING.
36 #ifndef CEPH_MSG_BYTEORDER_H_
37 #define CEPH_MSG_BYTEORDER_H_
39 #include <arpa/inet.h> // for ntohs() and friends
43 inline uint64_t ntohq(uint64_t v) {
44 return __builtin_bswap64(v);
46 inline uint64_t htonq(uint64_t v) {
47 return __builtin_bswap64(v);
53 inline uint8_t ntoh(uint8_t x) { return x; }
54 inline uint8_t hton(uint8_t x) { return x; }
55 inline uint16_t ntoh(uint16_t x) { return ntohs(x); }
56 inline uint16_t hton(uint16_t x) { return htons(x); }
57 inline uint32_t ntoh(uint32_t x) { return ntohl(x); }
58 inline uint32_t hton(uint32_t x) { return htonl(x); }
59 inline uint64_t ntoh(uint64_t x) { return ntohq(x); }
60 inline uint64_t hton(uint64_t x) { return htonq(x); }
62 inline int8_t ntoh(int8_t x) { return x; }
63 inline int8_t hton(int8_t x) { return x; }
64 inline int16_t ntoh(int16_t x) { return ntohs(x); }
65 inline int16_t hton(int16_t x) { return htons(x); }
66 inline int32_t ntoh(int32_t x) { return ntohl(x); }
67 inline int32_t hton(int32_t x) { return htonl(x); }
68 inline int64_t ntoh(int64_t x) { return ntohq(x); }
69 inline int64_t hton(int64_t x) { return htonq(x); }
71 #endif /* CEPH_MSG_BYTEORDER_H_ */