esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
message_registry.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <esphome/api/proto/message_id.hpp>
8
9#include <cstddef>
10#include <cstdint>
11#include <memory>
12
13namespace esphome::api {
14
22public:
24 static const MessageRegistry& instance();
25
28 [[nodiscard]] static std::unique_ptr<ProtoMessage> create(std::uint32_t id);
29 [[nodiscard]] static std::unique_ptr<ProtoMessage> create(MessageId id);
30
32 [[nodiscard]] static bool contains(std::uint32_t id);
33
35 [[nodiscard]] static std::size_t size() noexcept;
36
38 [[nodiscard]] static std::uint32_t id_of(const ProtoMessage& msg);
39
41 MessageRegistry& operator=(const MessageRegistry&) = delete;
42
43private:
44 MessageRegistry() = default;
45};
46
47} // namespace esphome::api
Maps the protocol's numeric message ids (the proto (id) option) to and from concrete message types.
Definition message_registry.hpp:21
static bool contains(std::uint32_t id)
Whether a message type with id exists.
static std::unique_ptr< ProtoMessage > create(MessageId id)
static std::uint32_t id_of(const ProtoMessage &msg)
The message id of a concrete message instance (0 if it carries none).
static std::size_t size() noexcept
Number of registered message types.
static std::unique_ptr< ProtoMessage > create(std::uint32_t id)
Create a default-constructed message for id, or nullptr if no message type carries that id.
static const MessageRegistry & instance()
The process-wide registry (constructed on first use).
Base class every generated message derives from.
Definition proto_message.hpp:23
Definition bytes.hpp:10
Lightweight base class for every generated ESPHome API message.