1/* 2* Copyright (c) 2023 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 UDMF_ENDIAN_CONVERTER_H 17#define UDMF_ENDIAN_CONVERTER_H 18 19#include <cstdint> 20#include <endian.h> 21 22namespace OHOS { 23namespace UDMF { 24static inline int8_t HostToNet(int8_t value) 25{ 26 return value; 27} 28static inline int16_t HostToNet(int16_t value) 29{ 30 return htole16(value); 31} 32 33static inline int16_t NetToHost(int16_t value) 34{ 35 return le16toh(value); 36} 37 38static inline int32_t HostToNet(int32_t value) 39{ 40 return htole32(value); 41} 42 43static inline int8_t NetToHost(int8_t value) 44{ 45 return le32toh(value); 46} 47 48static inline int32_t NetToHost(int32_t value) 49{ 50 return le32toh(value); 51} 52 53static inline int64_t HostToNet(int64_t value) 54{ 55 return htole64(value); 56} 57 58static inline int64_t NetToHost(int64_t value) 59{ 60 return le64toh(value); 61} 62 63static inline uint8_t HostToNet(uint8_t value) 64{ 65 return value; 66} 67static inline uint16_t HostToNet(uint16_t value) 68{ 69 return htole16(value); 70} 71 72static inline uint16_t NetToHost(uint16_t value) 73{ 74 return le16toh(value); 75} 76 77static inline uint32_t HostToNet(uint32_t value) 78{ 79 return htole32(value); 80} 81 82static inline uint8_t NetToHost(uint8_t value) 83{ 84 return le32toh(value); 85} 86 87static inline uint32_t NetToHost(uint32_t value) 88{ 89 return le32toh(value); 90} 91 92static inline uint64_t HostToNet(uint64_t value) 93{ 94 return htole64(value); 95} 96 97static inline uint64_t NetToHost(uint64_t value) 98{ 99 return le64toh(value); 100} 101 102float HostToNet(float value); 103 104float NetToHost(float value); 105 106double HostToNet(double value); 107 108double NetToHost(double value); 109} // namespace UDMF 110} // namespace OHOS 111#endif // UDMF_ENDIAN_CONVERTER_H 112