| 1 | #ifndef AWS_COMMON_BYTE_ORDER_H |
|---|---|
| 2 | #define AWS_COMMON_BYTE_ORDER_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"). |
| 8 | * You may not use this file except in compliance with the License. |
| 9 | * A copy of the License is located at |
| 10 | * |
| 11 | * http://aws.amazon.com/apache2.0 |
| 12 | * |
| 13 | * or in the "license" file accompanying this file. This file is distributed |
| 14 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 15 | * express or implied. See the License for the specific language governing |
| 16 | * permissions and limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #include <aws/common/common.h> |
| 20 | |
| 21 | AWS_EXTERN_C_BEGIN |
| 22 | |
| 23 | /** |
| 24 | * Returns 1 if machine is big endian, 0 if little endian. |
| 25 | * If you compile with even -O1 optimization, this check is completely optimized |
| 26 | * out at compile time and code which calls "if (aws_is_big_endian())" will do |
| 27 | * the right thing without branching. |
| 28 | */ |
| 29 | AWS_STATIC_IMPL int aws_is_big_endian(void); |
| 30 | /** |
| 31 | * Convert 64 bit integer from host to network byte order. |
| 32 | */ |
| 33 | AWS_STATIC_IMPL uint64_t aws_hton64(uint64_t x); |
| 34 | /** |
| 35 | * Convert 64 bit integer from network to host byte order. |
| 36 | */ |
| 37 | AWS_STATIC_IMPL uint64_t aws_ntoh64(uint64_t x); |
| 38 | |
| 39 | /** |
| 40 | * Convert 32 bit integer from host to network byte order. |
| 41 | */ |
| 42 | AWS_STATIC_IMPL uint32_t aws_hton32(uint32_t x); |
| 43 | |
| 44 | /** |
| 45 | * Convert 32 bit float from host to network byte order. |
| 46 | */ |
| 47 | AWS_STATIC_IMPL float aws_htonf32(float x); |
| 48 | |
| 49 | /** |
| 50 | * Convert 64 bit double from host to network byte order. |
| 51 | */ |
| 52 | AWS_STATIC_IMPL double aws_htonf64(double x); |
| 53 | |
| 54 | /** |
| 55 | * Convert 32 bit integer from network to host byte order. |
| 56 | */ |
| 57 | AWS_STATIC_IMPL uint32_t aws_ntoh32(uint32_t x); |
| 58 | |
| 59 | /** |
| 60 | * Convert 32 bit float from network to host byte order. |
| 61 | */ |
| 62 | AWS_STATIC_IMPL float aws_ntohf32(float x); |
| 63 | /** |
| 64 | * Convert 32 bit float from network to host byte order. |
| 65 | */ |
| 66 | AWS_STATIC_IMPL double aws_ntohf64(double x); |
| 67 | |
| 68 | /** |
| 69 | * Convert 24 bit integer from host to network byte order. |
| 70 | */ |
| 71 | AWS_STATIC_IMPL uint32_t aws_hton24(uint32_t x); |
| 72 | |
| 73 | /** |
| 74 | * Convert 24 bit integer from network to host byte order. |
| 75 | */ |
| 76 | AWS_STATIC_IMPL uint32_t aws_ntoh24(uint32_t x); |
| 77 | |
| 78 | /** |
| 79 | * Convert 16 bit integer from host to network byte order. |
| 80 | */ |
| 81 | AWS_STATIC_IMPL uint16_t aws_hton16(uint16_t x); |
| 82 | |
| 83 | /** |
| 84 | * Convert 16 bit integer from network to host byte order. |
| 85 | */ |
| 86 | AWS_STATIC_IMPL uint16_t aws_ntoh16(uint16_t x); |
| 87 | |
| 88 | #ifndef AWS_NO_STATIC_IMPL |
| 89 | # include <aws/common/byte_order.inl> |
| 90 | #endif /* AWS_NO_STATIC_IMPL */ |
| 91 | |
| 92 | AWS_EXTERN_C_END |
| 93 | |
| 94 | #endif /* AWS_COMMON_BYTE_ORDER_H */ |
| 95 |