Skip to content

Commit 7b4afd0

Browse files
authored
Add enum_as_bitmask protobuf option for ColorMode encoding (#1401)
1 parent 891892c commit 7b4afd0

File tree

4 files changed

+328
-319
lines changed

4 files changed

+328
-319
lines changed

aioesphomeapi/api.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ message ListEntitiesLightResponse {
506506
string name = 3;
507507
reserved 4; // Deprecated: was string unique_id
508508

509-
repeated ColorMode supported_color_modes = 12 [(container_pointer) = "std::set<light::ColorMode>"];
509+
repeated ColorMode supported_color_modes = 12 [(enum_as_bitmask) = true];
510510
// next four supports_* are for legacy clients, newer clients should use color modes
511511
// Deprecated in API version 1.6
512512
bool legacy_supports_brightness = 5 [deprecated=true];

aioesphomeapi/api_options.proto

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

aioesphomeapi/api_options_pb2.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aioesphomeapi/api_pb2.py

Lines changed: 317 additions & 317 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)