mirror of
https://github.com/esphome/esphome.git
synced 2026-01-09 19:50:49 -07:00
[api] Remove unused force parameter from encode_message (#12551)
This commit is contained in:
@@ -124,12 +124,12 @@ void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_DEVICES
|
#ifdef USE_DEVICES
|
||||||
for (const auto &it : this->devices) {
|
for (const auto &it : this->devices) {
|
||||||
buffer.encode_message(20, it, true);
|
buffer.encode_message(20, it);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_AREAS
|
#ifdef USE_AREAS
|
||||||
for (const auto &it : this->areas) {
|
for (const auto &it : this->areas) {
|
||||||
buffer.encode_message(21, it, true);
|
buffer.encode_message(21, it);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_AREAS
|
#ifdef USE_AREAS
|
||||||
@@ -878,13 +878,13 @@ void HomeassistantServiceMap::calculate_size(ProtoSize &size) const {
|
|||||||
void HomeassistantActionRequest::encode(ProtoWriteBuffer buffer) const {
|
void HomeassistantActionRequest::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_string(1, this->service_ref_);
|
buffer.encode_string(1, this->service_ref_);
|
||||||
for (auto &it : this->data) {
|
for (auto &it : this->data) {
|
||||||
buffer.encode_message(2, it, true);
|
buffer.encode_message(2, it);
|
||||||
}
|
}
|
||||||
for (auto &it : this->data_template) {
|
for (auto &it : this->data_template) {
|
||||||
buffer.encode_message(3, it, true);
|
buffer.encode_message(3, it);
|
||||||
}
|
}
|
||||||
for (auto &it : this->variables) {
|
for (auto &it : this->variables) {
|
||||||
buffer.encode_message(4, it, true);
|
buffer.encode_message(4, it);
|
||||||
}
|
}
|
||||||
buffer.encode_bool(5, this->is_event);
|
buffer.encode_bool(5, this->is_event);
|
||||||
#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
|
#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
|
||||||
@@ -1011,7 +1011,7 @@ void ListEntitiesServicesResponse::encode(ProtoWriteBuffer buffer) const {
|
|||||||
buffer.encode_string(1, this->name_ref_);
|
buffer.encode_string(1, this->name_ref_);
|
||||||
buffer.encode_fixed32(2, this->key);
|
buffer.encode_fixed32(2, this->key);
|
||||||
for (auto &it : this->args) {
|
for (auto &it : this->args) {
|
||||||
buffer.encode_message(3, it, true);
|
buffer.encode_message(3, it);
|
||||||
}
|
}
|
||||||
buffer.encode_uint32(4, static_cast<uint32_t>(this->supports_response));
|
buffer.encode_uint32(4, static_cast<uint32_t>(this->supports_response));
|
||||||
}
|
}
|
||||||
@@ -1867,7 +1867,7 @@ void ListEntitiesMediaPlayerResponse::encode(ProtoWriteBuffer buffer) const {
|
|||||||
buffer.encode_uint32(7, static_cast<uint32_t>(this->entity_category));
|
buffer.encode_uint32(7, static_cast<uint32_t>(this->entity_category));
|
||||||
buffer.encode_bool(8, this->supports_pause);
|
buffer.encode_bool(8, this->supports_pause);
|
||||||
for (auto &it : this->supported_formats) {
|
for (auto &it : this->supported_formats) {
|
||||||
buffer.encode_message(9, it, true);
|
buffer.encode_message(9, it);
|
||||||
}
|
}
|
||||||
#ifdef USE_DEVICES
|
#ifdef USE_DEVICES
|
||||||
buffer.encode_uint32(10, this->device_id);
|
buffer.encode_uint32(10, this->device_id);
|
||||||
@@ -1987,7 +1987,7 @@ void BluetoothLERawAdvertisement::calculate_size(ProtoSize &size) const {
|
|||||||
}
|
}
|
||||||
void BluetoothLERawAdvertisementsResponse::encode(ProtoWriteBuffer buffer) const {
|
void BluetoothLERawAdvertisementsResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
for (uint16_t i = 0; i < this->advertisements_len; i++) {
|
for (uint16_t i = 0; i < this->advertisements_len; i++) {
|
||||||
buffer.encode_message(1, this->advertisements[i], true);
|
buffer.encode_message(1, this->advertisements[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void BluetoothLERawAdvertisementsResponse::calculate_size(ProtoSize &size) const {
|
void BluetoothLERawAdvertisementsResponse::calculate_size(ProtoSize &size) const {
|
||||||
@@ -2060,7 +2060,7 @@ void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const {
|
|||||||
buffer.encode_uint32(2, this->handle);
|
buffer.encode_uint32(2, this->handle);
|
||||||
buffer.encode_uint32(3, this->properties);
|
buffer.encode_uint32(3, this->properties);
|
||||||
for (auto &it : this->descriptors) {
|
for (auto &it : this->descriptors) {
|
||||||
buffer.encode_message(4, it, true);
|
buffer.encode_message(4, it);
|
||||||
}
|
}
|
||||||
buffer.encode_uint32(5, this->short_uuid);
|
buffer.encode_uint32(5, this->short_uuid);
|
||||||
}
|
}
|
||||||
@@ -2081,7 +2081,7 @@ void BluetoothGATTService::encode(ProtoWriteBuffer buffer) const {
|
|||||||
}
|
}
|
||||||
buffer.encode_uint32(2, this->handle);
|
buffer.encode_uint32(2, this->handle);
|
||||||
for (auto &it : this->characteristics) {
|
for (auto &it : this->characteristics) {
|
||||||
buffer.encode_message(3, it, true);
|
buffer.encode_message(3, it);
|
||||||
}
|
}
|
||||||
buffer.encode_uint32(4, this->short_uuid);
|
buffer.encode_uint32(4, this->short_uuid);
|
||||||
}
|
}
|
||||||
@@ -2097,7 +2097,7 @@ void BluetoothGATTService::calculate_size(ProtoSize &size) const {
|
|||||||
void BluetoothGATTGetServicesResponse::encode(ProtoWriteBuffer buffer) const {
|
void BluetoothGATTGetServicesResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_uint64(1, this->address);
|
buffer.encode_uint64(1, this->address);
|
||||||
for (auto &it : this->services) {
|
for (auto &it : this->services) {
|
||||||
buffer.encode_message(2, it, true);
|
buffer.encode_message(2, it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void BluetoothGATTGetServicesResponse::calculate_size(ProtoSize &size) const {
|
void BluetoothGATTGetServicesResponse::calculate_size(ProtoSize &size) const {
|
||||||
@@ -2557,7 +2557,7 @@ bool VoiceAssistantConfigurationRequest::decode_length(uint32_t field_id, ProtoL
|
|||||||
}
|
}
|
||||||
void VoiceAssistantConfigurationResponse::encode(ProtoWriteBuffer buffer) const {
|
void VoiceAssistantConfigurationResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
for (auto &it : this->available_wake_words) {
|
for (auto &it : this->available_wake_words) {
|
||||||
buffer.encode_message(1, it, true);
|
buffer.encode_message(1, it);
|
||||||
}
|
}
|
||||||
for (const auto &it : *this->active_wake_words) {
|
for (const auto &it : *this->active_wake_words) {
|
||||||
buffer.encode_string(2, it, true);
|
buffer.encode_string(2, it, true);
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ class ProtoWriteBuffer {
|
|||||||
void encode_sint64(uint32_t field_id, int64_t value, bool force = false) {
|
void encode_sint64(uint32_t field_id, int64_t value, bool force = false) {
|
||||||
this->encode_uint64(field_id, encode_zigzag64(value), force);
|
this->encode_uint64(field_id, encode_zigzag64(value), force);
|
||||||
}
|
}
|
||||||
void encode_message(uint32_t field_id, const ProtoMessage &value, bool force = false);
|
void encode_message(uint32_t field_id, const ProtoMessage &value);
|
||||||
std::vector<uint8_t> *get_buffer() const { return buffer_; }
|
std::vector<uint8_t> *get_buffer() const { return buffer_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -795,7 +795,7 @@ class ProtoSize {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Implementation of encode_message - must be after ProtoMessage is defined
|
// Implementation of encode_message - must be after ProtoMessage is defined
|
||||||
inline void ProtoWriteBuffer::encode_message(uint32_t field_id, const ProtoMessage &value, bool force) {
|
inline void ProtoWriteBuffer::encode_message(uint32_t field_id, const ProtoMessage &value) {
|
||||||
this->encode_field_raw(field_id, 2); // type 2: Length-delimited message
|
this->encode_field_raw(field_id, 2); // type 2: Length-delimited message
|
||||||
|
|
||||||
// Calculate the message size first
|
// Calculate the message size first
|
||||||
|
|||||||
@@ -1215,6 +1215,9 @@ class FixedArrayRepeatedType(TypeInfo):
|
|||||||
"""Helper to generate encode statement for a single element."""
|
"""Helper to generate encode statement for a single element."""
|
||||||
if isinstance(self._ti, EnumType):
|
if isinstance(self._ti, EnumType):
|
||||||
return f"buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>({element}), true);"
|
return f"buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>({element}), true);"
|
||||||
|
# MessageType.encode_message doesn't have a force parameter
|
||||||
|
if isinstance(self._ti, MessageType):
|
||||||
|
return f"buffer.{self._ti.encode_func}({self.number}, {element});"
|
||||||
return f"buffer.{self._ti.encode_func}({self.number}, {element}, true);"
|
return f"buffer.{self._ti.encode_func}({self.number}, {element}, true);"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -1536,6 +1539,15 @@ class RepeatedTypeInfo(TypeInfo):
|
|||||||
# std::vector is specialized for bool, reference does not work
|
# std::vector is specialized for bool, reference does not work
|
||||||
return isinstance(self._ti, BoolType)
|
return isinstance(self._ti, BoolType)
|
||||||
|
|
||||||
|
def _encode_element_call(self, element: str) -> str:
|
||||||
|
"""Helper to generate encode call for a single element."""
|
||||||
|
if isinstance(self._ti, EnumType):
|
||||||
|
return f"buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>({element}), true);"
|
||||||
|
# MessageType.encode_message doesn't have a force parameter
|
||||||
|
if isinstance(self._ti, MessageType):
|
||||||
|
return f"buffer.{self._ti.encode_func}({self.number}, {element});"
|
||||||
|
return f"buffer.{self._ti.encode_func}({self.number}, {element}, true);"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def encode_content(self) -> str:
|
def encode_content(self) -> str:
|
||||||
if self._use_pointer:
|
if self._use_pointer:
|
||||||
@@ -1546,17 +1558,11 @@ class RepeatedTypeInfo(TypeInfo):
|
|||||||
o += f" buffer.{self._ti.encode_func}({self.number}, it, strlen(it), true);\n"
|
o += f" buffer.{self._ti.encode_func}({self.number}, it, strlen(it), true);\n"
|
||||||
else:
|
else:
|
||||||
o = f"for (const auto &it : *this->{self.field_name}) {{\n"
|
o = f"for (const auto &it : *this->{self.field_name}) {{\n"
|
||||||
if isinstance(self._ti, EnumType):
|
o += f" {self._encode_element_call('it')}\n"
|
||||||
o += f" buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>(it), true);\n"
|
|
||||||
else:
|
|
||||||
o += f" buffer.{self._ti.encode_func}({self.number}, it, true);\n"
|
|
||||||
o += "}"
|
o += "}"
|
||||||
return o
|
return o
|
||||||
o = f"for (auto {'' if self._ti_is_bool else '&'}it : this->{self.field_name}) {{\n"
|
o = f"for (auto {'' if self._ti_is_bool else '&'}it : this->{self.field_name}) {{\n"
|
||||||
if isinstance(self._ti, EnumType):
|
o += f" {self._encode_element_call('it')}\n"
|
||||||
o += f" buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>(it), true);\n"
|
|
||||||
else:
|
|
||||||
o += f" buffer.{self._ti.encode_func}({self.number}, it, true);\n"
|
|
||||||
o += "}"
|
o += "}"
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user