|
esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
|
Stateful codec sitting between the transport and the connection. More...
#include <frame_helper.hpp>

Public Types | |
| using | HandshakeReady = std::function< void()> |
| using | HandshakeError = std::function< void(const std::string &what)> |
Public Member Functions | |
| FrameHelper ()=default | |
| virtual | ~FrameHelper ()=default |
| FrameHelper (const FrameHelper &)=delete | |
| FrameHelper & | operator= (const FrameHelper &)=delete |
| FrameHelper (FrameHelper &&)=delete | |
| FrameHelper & | operator= (FrameHelper &&)=delete |
| virtual void | encode (std::uint32_t msg_type, ByteView payload, ByteBuffer &out)=0 |
Serialize a message (numeric type id + protobuf payload) to wire bytes, appending them to out. | |
| virtual void | feed (ByteView data)=0 |
| Append freshly received bytes to the internal reassembly buffer. | |
| virtual FrameStatus | next (std::uint32_t &out_type, ByteView &out_payload)=0 |
| Try to extract the next complete frame. | |
| virtual bool | needs_handshake () const |
| True if the transport requires a handshake before application messages (and before the connection should send HelloRequest). | |
| virtual ByteBuffer | connect_bytes () |
| Bytes to transmit immediately after the TCP connection is established (the client's first handshake flight). | |
| virtual void | set_handshake_handlers (HandshakeReady, HandshakeError) |
| Register callbacks fired when the handshake completes or fails. | |
Stateful codec sitting between the transport and the connection.
A FrameHelper owns an internal reassembly buffer. The connection feeds it raw bytes as they arrive (feed) and repeatedly calls next to drain whole frames. Outgoing messages are serialized with encode.
Implementations: PlaintextFrameHelper (no encryption) and, when built with Noise support, NoiseFrameHelper.
| using esphome::api::FrameHelper::HandshakeError = std::function<void(const std::string& what)> |
| using esphome::api::FrameHelper::HandshakeReady = std::function<void()> |
|
default |
|
virtualdefault |
|
delete |
|
delete |
|
inlinevirtual |
Bytes to transmit immediately after the TCP connection is established (the client's first handshake flight).
Empty for plaintext.
Reimplemented in esphome::api::NoiseFrameHelper.
|
pure virtual |
Serialize a message (numeric type id + protobuf payload) to wire bytes, appending them to out.
Implemented in esphome::api::NoiseFrameHelper, and esphome::api::PlaintextFrameHelper.
|
pure virtual |
Append freshly received bytes to the internal reassembly buffer.
Implemented in esphome::api::NoiseFrameHelper, and esphome::api::PlaintextFrameHelper.
|
inlinevirtual |
True if the transport requires a handshake before application messages (and before the connection should send HelloRequest).
Reimplemented in esphome::api::NoiseFrameHelper.
|
pure virtual |
Try to extract the next complete frame.
On FrameStatus::Ok, out_type is the message type id and out_payload is a view of the protobuf payload that stays valid only until the next call to feed or next. On NeedMore nothing was consumed.
Throws ProtocolError on a malformed or oversized frame.
Implemented in esphome::api::NoiseFrameHelper, and esphome::api::PlaintextFrameHelper.
|
delete |
|
delete |
|
inlinevirtual |
Register callbacks fired when the handshake completes or fails.
next consumes handshake frames internally and invokes these.
Reimplemented in esphome::api::NoiseFrameHelper.