LSH-Core
A robust C++ framework for Arduino-based home automation nodes
Loading...
Searching...
No Matches
payload_utils.hpp
Go to the documentation of this file.
1
21#ifndef LSHCORE_COMMUNICATION_PAYLOAD_UTILS_HPP
22#define LSHCORE_COMMUNICATION_PAYLOAD_UTILS_HPP
23
24#include <etl/span.h>
25
27
28namespace utils::payloads
29{
33 template <bool IsMsgPack>
34 [[nodiscard]] constexpr auto get(constants::payloads::StaticType type) -> etl::span<const uint8_t>
35 {
36 using namespace constants::payloads;
37
38 if constexpr (IsMsgPack)
39 {
40 switch (type)
41 {
42 case StaticType::BOOT:
43 return MSGPACK_BOOT_BYTES;
44 case StaticType::PING_:
45 return MSGPACK_PING_BYTES;
46
47 default:
48 return {};
49 }
50 }
51 else // JSON
52 {
53 switch (type)
54 {
55 case StaticType::BOOT:
56 return JSON_BOOT_BYTES;
57 case StaticType::PING_:
58 return JSON_PING_BYTES;
59 default:
60 return {};
61 }
62 }
63 }
64} // namespace utils::payloads
65
66#endif // LSHCORE_COMMUNICATION_PAYLOAD_UTILS_HPP
constexpr auto get(constants::payloads::StaticType type) -> etl::span< const uint8_t >
Gets a span pointing to the correct pre-defined static payload.
Definition payload_utils.hpp:34
Defines pre-serialized static message payloads stored in Flash.
StaticType
Defines the types of pre-serialized static payloads.
Definition static_payloads.hpp:33