esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
esphome::api::PlaintextFrameHelper Class Referencefinal

Codec for the plaintext native-API framing: More...

#include <plaintext_frame_helper.hpp>

Inheritance diagram for esphome::api::PlaintextFrameHelper:
Inheritance graph
[legend]
Collaboration diagram for esphome::api::PlaintextFrameHelper:
Collaboration graph
[legend]

Public Member Functions

void encode (std::uint32_t msg_type, ByteView payload, ByteBuffer &out) override
 Serialize a message (numeric type id + protobuf payload) to wire bytes, appending them to out.
 
void feed (ByteView data) override
 Append freshly received bytes to the internal reassembly buffer.
 
FrameStatus next (std::uint32_t &out_type, ByteView &out_payload) override
 Try to extract the next complete frame.
 
- Public Member Functions inherited from esphome::api::FrameHelper
 FrameHelper ()=default
 
virtual ~FrameHelper ()=default
 
 FrameHelper (const FrameHelper &)=delete
 
FrameHelperoperator= (const FrameHelper &)=delete
 
 FrameHelper (FrameHelper &&)=delete
 
FrameHelperoperator= (FrameHelper &&)=delete
 
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.
 

Static Public Attributes

static constexpr std::uint8_t indicator = 0x00
 Indicator byte that prefixes every plaintext frame.
 

Additional Inherited Members

- Public Types inherited from esphome::api::FrameHelper
using HandshakeReady = std::function< void()>
 
using HandshakeError = std::function< void(const std::string &what)>
 

Detailed Description

Codec for the plaintext native-API framing:

[0x00][varint payload_length][varint msg_type][protobuf payload]

The leading 0x00 indicator distinguishes plaintext from Noise (0x01).

Member Function Documentation

◆ encode()

void esphome::api::PlaintextFrameHelper::encode ( std::uint32_t  msg_type,
ByteView  payload,
ByteBuffer out 
)
overridevirtual

Serialize a message (numeric type id + protobuf payload) to wire bytes, appending them to out.

Implements esphome::api::FrameHelper.

◆ feed()

void esphome::api::PlaintextFrameHelper::feed ( ByteView  data)
overridevirtual

Append freshly received bytes to the internal reassembly buffer.

Implements esphome::api::FrameHelper.

◆ next()

FrameStatus esphome::api::PlaintextFrameHelper::next ( std::uint32_t &  out_type,
ByteView out_payload 
)
overridevirtual

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.

Implements esphome::api::FrameHelper.

Member Data Documentation

◆ indicator

constexpr std::uint8_t esphome::api::PlaintextFrameHelper::indicator = 0x00
staticconstexpr

Indicator byte that prefixes every plaintext frame.


The documentation for this class was generated from the following file: