Project
Loading...
Searching...
No Matches
BigEndian.h
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_FRAMEWORK_BIGENDIAN_H_
13#define O2_FRAMEWORK_BIGENDIAN_H_
14
15#include <bit>
16#include <cstddef>
17#include <cstdint>
18#include <cstring>
19
20namespace o2::framework
21{
22
26inline void bigEndianCopy(void* dest, const void* src, int count, size_t typeSize)
27{
28 auto const totalBytes = static_cast<size_t>(count) * typeSize;
29 if constexpr (std::endian::native == std::endian::big) {
30 std::memcpy(dest, src, totalBytes);
31 return;
32 }
33 switch (typeSize) {
34 case 2: {
35 auto* p = static_cast<uint16_t*>(dest);
36 auto* q = static_cast<const uint16_t*>(src);
37 for (int i = 0; i < count; ++i) {
38 p[i] = __builtin_bswap16(q[i]);
39 }
40 return;
41 }
42 case 4: {
43 auto* p = static_cast<uint32_t*>(dest);
44 auto* q = static_cast<const uint32_t*>(src);
45 for (int i = 0; i < count; ++i) {
46 p[i] = __builtin_bswap32(q[i]);
47 }
48 return;
49 }
50 case 8: {
51 auto* p = static_cast<uint64_t*>(dest);
52 auto* q = static_cast<const uint64_t*>(src);
53 for (int i = 0; i < count; ++i) {
54 p[i] = __builtin_bswap64(q[i]);
55 }
56 return;
57 }
58 }
59 std::memcpy(dest, src, totalBytes);
60}
61
62} // namespace o2::framework
63
64#endif // O2_FRAMEWORK_BIGENDIAN_H_
int32_t i
GLenum src
Definition glcorearb.h:1767
GLint GLsizei count
Definition glcorearb.h:399
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
void bigEndianCopy(void *dest, const void *src, int count, size_t typeSize)
Definition BigEndian.h:26