23#ifndef LSST_SPHGEOM_CODEC_H_
24#define LSST_SPHGEOM_CODEC_H_
27#if defined(__x86_64__) or (defined(__aarch64__) and defined(__LITTLE_ENDIAN__))
28#define OPTIMIZED_LITTLE_ENDIAN
31#ifdef NO_OPTIMIZED_PATHS
32#undef OPTIMIZED_LITTLE_ENDIAN
46inline void encodeDouble(
double item, std::vector<uint8_t> & buffer) {
47#ifdef OPTIMIZED_LITTLE_ENDIAN
48 auto ptr =
reinterpret_cast<uint8_t
const *
>(&item);
49 buffer.insert(buffer.end(), ptr, ptr + 8);
51 union { uint64_t u;
double d; };
53 buffer.push_back(
static_cast<uint8_t
>(u));
54 buffer.push_back(
static_cast<uint8_t
>(u >> 8));
55 buffer.push_back(
static_cast<uint8_t
>(u >> 16));
56 buffer.push_back(
static_cast<uint8_t
>(u >> 24));
57 buffer.push_back(
static_cast<uint8_t
>(u >> 32));
58 buffer.push_back(
static_cast<uint8_t
>(u >> 40));
59 buffer.push_back(
static_cast<uint8_t
>(u >> 48));
60 buffer.push_back(
static_cast<uint8_t
>(u >> 56));
67#ifdef OPTIMIZED_LITTLE_ENDIAN
68 return *
reinterpret_cast<double const *
>(buffer);
70 union { uint64_t u;
double d; };
71 u =
static_cast<uint64_t
>(buffer[0]) +
72 (
static_cast<uint64_t
>(buffer[1]) << 8) +
73 (
static_cast<uint64_t
>(buffer[2]) << 16) +
74 (
static_cast<uint64_t
>(buffer[3]) << 24) +
75 (
static_cast<uint64_t
>(buffer[4]) << 32) +
76 (
static_cast<uint64_t
>(buffer[5]) << 40) +
77 (
static_cast<uint64_t
>(buffer[6]) << 48) +
78 (
static_cast<uint64_t
>(buffer[7]) << 56);
void encodeDouble(double item, std::vector< uint8_t > &buffer)
Definition: codec.h:46
double decodeDouble(uint8_t const *buffer)
Definition: codec.h:66