serialization.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 
5 #include <nlohmann/json.hpp>
6 
7 #include "common.hpp"
8 #include "parameter.hpp"
9 
10 namespace foxglove {
11 
12 inline void WriteUint64LE(uint8_t* buf, uint64_t val) {
13 #ifdef ARCH_IS_BIG_ENDIAN
14  buf[0] = val & 0xff;
15  buf[1] = (val >> 8) & 0xff;
16  buf[2] = (val >> 16) & 0xff;
17  buf[3] = (val >> 24) & 0xff;
18  buf[4] = (val >> 32) & 0xff;
19  buf[5] = (val >> 40) & 0xff;
20  buf[6] = (val >> 48) & 0xff;
21  buf[7] = (val >> 56) & 0xff;
22 #else
23  reinterpret_cast<uint64_t*>(buf)[0] = val;
24 #endif
25 }
26 
27 inline void WriteUint32LE(uint8_t* buf, uint32_t val) {
28 #ifdef ARCH_IS_BIG_ENDIAN
29  buf[0] = val & 0xff;
30  buf[1] = (val >> 8) & 0xff;
31  buf[2] = (val >> 16) & 0xff;
32  buf[3] = (val >> 24) & 0xff;
33 #else
34  reinterpret_cast<uint32_t*>(buf)[0] = val;
35 #endif
36 }
37 
38 inline uint32_t ReadUint32LE(const uint8_t* buf) {
39 #ifdef ARCH_IS_BIG_ENDIAN
40  uint32_t val = (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3];
41  return val;
42 #else
43  return reinterpret_cast<const uint32_t*>(buf)[0];
44 #endif
45 }
46 
47 void to_json(nlohmann::json& j, const Channel& c);
48 void from_json(const nlohmann::json& j, Channel& c);
49 void to_json(nlohmann::json& j, const ParameterValue& p);
50 void from_json(const nlohmann::json& j, ParameterValue& p);
51 void to_json(nlohmann::json& j, const Parameter& p);
52 void from_json(const nlohmann::json& j, Parameter& p);
53 void to_json(nlohmann::json& j, const Service& p);
54 void from_json(const nlohmann::json& j, Service& p);
55 
56 } // namespace foxglove
void to_json(nlohmann::json &j, const Channel &c)
nlohmann::json json
void from_json(const nlohmann::json &j, Channel &c)
uint32_t ReadUint32LE(const uint8_t *buf)
void WriteUint64LE(uint8_t *buf, uint64_t val)
void WriteUint32LE(uint8_t *buf, uint32_t val)


foxglove_bridge
Author(s): Foxglove
autogenerated on Mon Jul 3 2023 02:12:22