23 #ifndef LSST_SPHGEOM_CODEC_H_
24 #define LSST_SPHGEOM_CODEC_H_
38 inline void encodeDouble(
double item, std::vector<uint8_t> & buffer) {
39 #if defined(__x86_64__)
41 auto ptr =
reinterpret_cast<uint8_t
const *
>(&item);
42 buffer.insert(buffer.end(), ptr, ptr + 8);
44 union { uint64_t u;
double d };
46 buffer.push_back(
static_cast<uint8_t
>(value));
47 buffer.push_back(
static_cast<uint8_t
>(value >> 8));
48 buffer.push_back(
static_cast<uint8_t
>(value >> 16));
49 buffer.push_back(
static_cast<uint8_t
>(value >> 24));
50 buffer.push_back(
static_cast<uint8_t
>(value >> 32));
51 buffer.push_back(
static_cast<uint8_t
>(value >> 40));
52 buffer.push_back(
static_cast<uint8_t
>(value >> 48));
53 buffer.push_back(
static_cast<uint8_t
>(value >> 56));
60 #if defined(__x86_64__)
62 return *
reinterpret_cast<double const *
>(buffer);
64 union { uint64_t u;
double d };
65 u =
static_cast<uint64_t
>(buffer[0]) +
66 (
static_cast<uint64_t
>(buffer[1]) << 8) +
67 (
static_cast<uint64_t
>(buffer[2]) << 16) +
68 (
static_cast<uint64_t
>(buffer[3]) << 24) +
69 (
static_cast<uint64_t
>(buffer[4]) << 32) +
70 (
static_cast<uint64_t
>(buffer[5]) << 40) +
71 (
static_cast<uint64_t
>(buffer[6]) << 48) +
72 (
static_cast<uint64_t
>(buffer[7]) << 56);
void encodeDouble(double item, std::vector< uint8_t > &buffer)
Definition: codec.h:38
double decodeDouble(uint8_t const *buffer)
Definition: codec.h:59