1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-23 20:23:50 +01:00

no vector

This commit is contained in:
J. Nick Koston
2025-10-18 09:59:24 -10:00
parent 6a96e0ee90
commit c76e386a79
6 changed files with 65 additions and 10 deletions

View File

@@ -506,7 +506,7 @@ message ListEntitiesLightResponse {
string name = 3;
reserved 4; // Deprecated: was string unique_id
repeated ColorMode supported_color_modes = 12 [(fixed_vector) = true];
repeated ColorMode supported_color_modes = 12 [(enum_as_bitmask) = true];
// next four supports_* are for legacy clients, newer clients should use color modes
// Deprecated in API version 1.6
bool legacy_supports_brightness = 5 [deprecated=true];

View File

@@ -70,4 +70,13 @@ extend google.protobuf.FieldOptions {
// init(size) before adding elements. This eliminates std::vector template overhead
// and is ideal when the exact size is known before populating the array.
optional bool fixed_vector = 50013 [default=false];
// enum_as_bitmask: Encode repeated enum fields as a uint32_t bitmask
// When set on a repeated enum field, the field will be stored as a single uint32_t
// where each bit represents whether that enum value is present. This is ideal for
// enums with ≤32 values and eliminates all vector template instantiation overhead.
// The enum values should be sequential starting from 0.
// Encoding: bit N set means enum value N is present in the set.
// Example: {ColorMode::RGB, ColorMode::WHITE} → bitmask with bits 5 and 6 set
optional bool enum_as_bitmask = 50014 [default=false];
}

View File

@@ -471,8 +471,10 @@ void ListEntitiesLightResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_string(1, this->object_id_ref_);
buffer.encode_fixed32(2, this->key);
buffer.encode_string(3, this->name_ref_);
for (auto &it : this->supported_color_modes) {
buffer.encode_uint32(12, static_cast<uint32_t>(it), true);
for (uint8_t bit = 0; bit < 32; bit++) {
if (this->supported_color_modes & (1U << bit)) {
buffer.encode_uint32(12, bit, true);
}
}
buffer.encode_float(9, this->min_mireds);
buffer.encode_float(10, this->max_mireds);
@@ -492,9 +494,11 @@ void ListEntitiesLightResponse::calculate_size(ProtoSize &size) const {
size.add_length(1, this->object_id_ref_.size());
size.add_fixed32(1, this->key);
size.add_length(1, this->name_ref_.size());
if (!this->supported_color_modes.empty()) {
for (const auto &it : this->supported_color_modes) {
size.add_uint32_force(1, static_cast<uint32_t>(it));
if (this->supported_color_modes != 0) {
for (uint8_t bit = 0; bit < 32; bit++) {
if (this->supported_color_modes & (1U << bit)) {
size.add_uint32_force(1, static_cast<uint32_t>(bit));
}
}
}
size.add_float(1, this->min_mireds);

View File

@@ -790,7 +790,7 @@ class ListEntitiesLightResponse final : public InfoResponseProtoMessage {
#ifdef HAS_PROTO_MESSAGE_DUMP
const char *message_name() const override { return "list_entities_light_response"; }
#endif
FixedVector<enums::ColorMode> supported_color_modes{};
uint32_t supported_color_modes{};
float min_mireds{0.0f};
float max_mireds{0.0f};
std::vector<std::string> effects{};

View File

@@ -913,9 +913,9 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const {
dump_field(out, "object_id", this->object_id_ref_);
dump_field(out, "key", this->key);
dump_field(out, "name", this->name_ref_);
for (const auto &it : this->supported_color_modes) {
dump_field(out, "supported_color_modes", static_cast<enums::ColorMode>(it), 4);
}
out.append(" supported_color_modes: 0x");
out.append(uint32_to_string(this->supported_color_modes));
out.append("\n");
dump_field(out, "min_mireds", this->min_mireds);
dump_field(out, "max_mireds", this->max_mireds);
for (const auto &it : this->effects) {