1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DISTRIBUTEDDATAMGR_ENDIAN_CONVERTER_H 17 #define DISTRIBUTEDDATAMGR_ENDIAN_CONVERTER_H 18 19 #include <endian.h> 20 21 namespace OHOS::DistributedData { 22 // use little endian byteorder by default HostToNet(uint16_t value)23static inline uint16_t HostToNet(uint16_t value) 24 { 25 return htole16(value); 26 } 27 NetToHost(uint16_t value)28static inline uint16_t NetToHost(uint16_t value) 29 { 30 return le16toh(value); 31 } 32 HostToNet(uint32_t value)33static inline uint32_t HostToNet(uint32_t value) 34 { 35 return htole32(value); 36 } 37 NetToHost(uint32_t value)38static inline uint32_t NetToHost(uint32_t value) 39 { 40 return le32toh(value); 41 } 42 HostToNet(uint64_t value)43static inline uint64_t HostToNet(uint64_t value) 44 { 45 return htole64(value); 46 } 47 NetToHost(uint64_t value)48static inline uint64_t NetToHost(uint64_t value) 49 { 50 return le64toh(value); 51 } 52 } // namespace OHOS::DistributedData 53 #endif // DISTRIBUTEDDATAMGR_ENDIAN_CONVERTER_H 54