ESPHome 2025.8.0b1
Loading...
Searching...
No Matches
esphome::api::ProtoVarInt Class Reference

Representation of a VarInt - in ProtoBuf should be 64bit but we only use 32bit. More...

#include <proto.h>

Public Member Functions

 ProtoVarInt ()
 
 ProtoVarInt (uint64_t value)
 
constexpr uint16_t as_uint16 () const
 
constexpr uint32_t as_uint32 () const
 
constexpr uint64_t as_uint64 () const
 
constexpr bool as_bool () const
 
constexpr int32_t as_int32 () const
 
constexpr int64_t as_int64 () const
 
constexpr int32_t as_sint32 () const
 
constexpr int64_t as_sint64 () const
 
void encode_to_buffer_unchecked (uint8_t *buffer, size_t len)
 Encode the varint value to a pre-allocated buffer without bounds checking.
 
void encode (std::vector< uint8_t > &out)
 

Static Public Member Functions

static optional< ProtoVarIntparse (const uint8_t *buffer, uint32_t len, uint32_t *consumed)
 

Protected Attributes

uint64_t value_
 

Detailed Description

Representation of a VarInt - in ProtoBuf should be 64bit but we only use 32bit.

Definition at line 66 of file proto.h.

Constructor & Destructor Documentation

◆ ProtoVarInt() [1/2]

esphome::api::ProtoVarInt::ProtoVarInt ( )
inline

Definition at line 68 of file proto.h.

◆ ProtoVarInt() [2/2]

esphome::api::ProtoVarInt::ProtoVarInt ( uint64_t value)
inlineexplicit

Definition at line 69 of file proto.h.

Member Function Documentation

◆ as_bool()

bool esphome::api::ProtoVarInt::as_bool ( ) const
inlineconstexpr

Definition at line 110 of file proto.h.

◆ as_int32()

int32_t esphome::api::ProtoVarInt::as_int32 ( ) const
inlineconstexpr

Definition at line 111 of file proto.h.

◆ as_int64()

int64_t esphome::api::ProtoVarInt::as_int64 ( ) const
inlineconstexpr

Definition at line 115 of file proto.h.

◆ as_sint32()

int32_t esphome::api::ProtoVarInt::as_sint32 ( ) const
inlineconstexpr

Definition at line 119 of file proto.h.

◆ as_sint64()

int64_t esphome::api::ProtoVarInt::as_sint64 ( ) const
inlineconstexpr

Definition at line 123 of file proto.h.

◆ as_uint16()

uint16_t esphome::api::ProtoVarInt::as_uint16 ( ) const
inlineconstexpr

Definition at line 107 of file proto.h.

◆ as_uint32()

uint32_t esphome::api::ProtoVarInt::as_uint32 ( ) const
inlineconstexpr

Definition at line 108 of file proto.h.

◆ as_uint64()

uint64_t esphome::api::ProtoVarInt::as_uint64 ( ) const
inlineconstexpr

Definition at line 109 of file proto.h.

◆ encode()

void esphome::api::ProtoVarInt::encode ( std::vector< uint8_t > & out)
inline

Definition at line 155 of file proto.h.

◆ encode_to_buffer_unchecked()

void esphome::api::ProtoVarInt::encode_to_buffer_unchecked ( uint8_t * buffer,
size_t len )
inline

Encode the varint value to a pre-allocated buffer without bounds checking.

Parameters
bufferThe pre-allocated buffer to write the encoded varint to
lenThe size of the buffer in bytes
Note
The caller is responsible for ensuring the buffer is large enough to hold the encoded value. Use ProtoSize::varint() to calculate the exact size needed before calling this method.
No bounds checking is performed for performance reasons.

Definition at line 138 of file proto.h.

◆ parse()

static optional< ProtoVarInt > esphome::api::ProtoVarInt::parse ( const uint8_t * buffer,
uint32_t len,
uint32_t * consumed )
inlinestatic

Definition at line 71 of file proto.h.

Field Documentation

◆ value_

uint64_t esphome::api::ProtoVarInt::value_
protected

Definition at line 173 of file proto.h.


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