AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Endian.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_ENDIAN_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_ENDIAN_H_
18 
19 #include <cstdint>
20 
21 namespace alexaClientSDK {
22 namespace avsCommon {
23 namespace utils {
24 
26 inline bool littleEndianMachine() {
27  uint16_t original = 1;
28  uint8_t* words = reinterpret_cast<uint8_t*>(&original);
29  return words[0] == 1;
30 }
31 
32 // Function used to swap endian of uint16_t
33 inline uint16_t swapEndian(uint16_t input) {
34  return ((input & 0x00ff) << 8 | (input & 0xff00) >> 8);
35 }
36 
37 // Function used to swap endian of uint32_t
38 inline uint32_t swapEndian(uint32_t input) {
39  return (
40  (input & 0xff000000) >> 24 | // move byte 3 to byte 0
41  (input & 0x0000ff00) << 8 | // move byte 1 to byte 2
42  (input & 0x00ff0000) >> 8 | // move byte 2 to byte 1
43  (input & 0x000000ff) << 24); // byte 0 to byte 3
44 }
45 
46 } // namespace utils
47 } // namespace avsCommon
48 } // namespace alexaClientSDK
49 
50 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_ENDIAN_H_
uint16_t swapEndian(uint16_t input)
Definition: Endian.h:33
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool littleEndianMachine()
Function used to check the machine endianness.
Definition: Endian.h:26

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0