mirror of
https://github.com/esphome/esphome.git
synced 2025-07-28 22:26:36 +00:00
Use encode_bytes() for protobuf bytes fields (#9289)
This commit is contained in:
parent
fae96e279c
commit
eba2c82fec
@ -3494,7 +3494,7 @@ bool SubscribeLogsResponse::decode_length(uint32_t field_id, ProtoLengthDelimite
|
|||||||
}
|
}
|
||||||
void SubscribeLogsResponse::encode(ProtoWriteBuffer buffer) const {
|
void SubscribeLogsResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_enum<enums::LogLevel>(1, this->level);
|
buffer.encode_enum<enums::LogLevel>(1, this->level);
|
||||||
buffer.encode_string(3, this->message);
|
buffer.encode_bytes(3, reinterpret_cast<const uint8_t *>(this->message.data()), this->message.size());
|
||||||
buffer.encode_bool(4, this->send_failed);
|
buffer.encode_bool(4, this->send_failed);
|
||||||
}
|
}
|
||||||
void SubscribeLogsResponse::calculate_size(uint32_t &total_size) const {
|
void SubscribeLogsResponse::calculate_size(uint32_t &total_size) const {
|
||||||
@ -3530,7 +3530,9 @@ bool NoiseEncryptionSetKeyRequest::decode_length(uint32_t field_id, ProtoLengthD
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void NoiseEncryptionSetKeyRequest::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->key); }
|
void NoiseEncryptionSetKeyRequest::encode(ProtoWriteBuffer buffer) const {
|
||||||
|
buffer.encode_bytes(1, reinterpret_cast<const uint8_t *>(this->key.data()), this->key.size());
|
||||||
|
}
|
||||||
void NoiseEncryptionSetKeyRequest::calculate_size(uint32_t &total_size) const {
|
void NoiseEncryptionSetKeyRequest::calculate_size(uint32_t &total_size) const {
|
||||||
ProtoSize::add_string_field(total_size, 1, this->key, false);
|
ProtoSize::add_string_field(total_size, 1, this->key, false);
|
||||||
}
|
}
|
||||||
@ -4267,7 +4269,7 @@ bool CameraImageResponse::decode_32bit(uint32_t field_id, Proto32Bit value) {
|
|||||||
}
|
}
|
||||||
void CameraImageResponse::encode(ProtoWriteBuffer buffer) const {
|
void CameraImageResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_fixed32(1, this->key);
|
buffer.encode_fixed32(1, this->key);
|
||||||
buffer.encode_string(2, this->data);
|
buffer.encode_bytes(2, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||||
buffer.encode_bool(3, this->done);
|
buffer.encode_bool(3, this->done);
|
||||||
}
|
}
|
||||||
void CameraImageResponse::calculate_size(uint32_t &total_size) const {
|
void CameraImageResponse::calculate_size(uint32_t &total_size) const {
|
||||||
@ -6785,7 +6787,7 @@ void BluetoothServiceData::encode(ProtoWriteBuffer buffer) const {
|
|||||||
for (auto &it : this->legacy_data) {
|
for (auto &it : this->legacy_data) {
|
||||||
buffer.encode_uint32(2, it, true);
|
buffer.encode_uint32(2, it, true);
|
||||||
}
|
}
|
||||||
buffer.encode_string(3, this->data);
|
buffer.encode_bytes(3, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||||
}
|
}
|
||||||
void BluetoothServiceData::calculate_size(uint32_t &total_size) const {
|
void BluetoothServiceData::calculate_size(uint32_t &total_size) const {
|
||||||
ProtoSize::add_string_field(total_size, 1, this->uuid, false);
|
ProtoSize::add_string_field(total_size, 1, this->uuid, false);
|
||||||
@ -6859,7 +6861,7 @@ bool BluetoothLEAdvertisementResponse::decode_length(uint32_t field_id, ProtoLen
|
|||||||
}
|
}
|
||||||
void BluetoothLEAdvertisementResponse::encode(ProtoWriteBuffer buffer) const {
|
void BluetoothLEAdvertisementResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_uint64(1, this->address);
|
buffer.encode_uint64(1, this->address);
|
||||||
buffer.encode_string(2, this->name);
|
buffer.encode_bytes(2, reinterpret_cast<const uint8_t *>(this->name.data()), this->name.size());
|
||||||
buffer.encode_sint32(3, this->rssi);
|
buffer.encode_sint32(3, this->rssi);
|
||||||
for (auto &it : this->service_uuids) {
|
for (auto &it : this->service_uuids) {
|
||||||
buffer.encode_string(4, it, true);
|
buffer.encode_string(4, it, true);
|
||||||
@ -6960,7 +6962,7 @@ void BluetoothLERawAdvertisement::encode(ProtoWriteBuffer buffer) const {
|
|||||||
buffer.encode_uint64(1, this->address);
|
buffer.encode_uint64(1, this->address);
|
||||||
buffer.encode_sint32(2, this->rssi);
|
buffer.encode_sint32(2, this->rssi);
|
||||||
buffer.encode_uint32(3, this->address_type);
|
buffer.encode_uint32(3, this->address_type);
|
||||||
buffer.encode_string(4, this->data);
|
buffer.encode_bytes(4, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||||
}
|
}
|
||||||
void BluetoothLERawAdvertisement::calculate_size(uint32_t &total_size) const {
|
void BluetoothLERawAdvertisement::calculate_size(uint32_t &total_size) const {
|
||||||
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
||||||
@ -7493,7 +7495,7 @@ bool BluetoothGATTReadResponse::decode_length(uint32_t field_id, ProtoLengthDeli
|
|||||||
void BluetoothGATTReadResponse::encode(ProtoWriteBuffer buffer) const {
|
void BluetoothGATTReadResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_uint64(1, this->address);
|
buffer.encode_uint64(1, this->address);
|
||||||
buffer.encode_uint32(2, this->handle);
|
buffer.encode_uint32(2, this->handle);
|
||||||
buffer.encode_string(3, this->data);
|
buffer.encode_bytes(3, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||||
}
|
}
|
||||||
void BluetoothGATTReadResponse::calculate_size(uint32_t &total_size) const {
|
void BluetoothGATTReadResponse::calculate_size(uint32_t &total_size) const {
|
||||||
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
||||||
@ -7552,7 +7554,7 @@ void BluetoothGATTWriteRequest::encode(ProtoWriteBuffer buffer) const {
|
|||||||
buffer.encode_uint64(1, this->address);
|
buffer.encode_uint64(1, this->address);
|
||||||
buffer.encode_uint32(2, this->handle);
|
buffer.encode_uint32(2, this->handle);
|
||||||
buffer.encode_bool(3, this->response);
|
buffer.encode_bool(3, this->response);
|
||||||
buffer.encode_string(4, this->data);
|
buffer.encode_bytes(4, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||||
}
|
}
|
||||||
void BluetoothGATTWriteRequest::calculate_size(uint32_t &total_size) const {
|
void BluetoothGATTWriteRequest::calculate_size(uint32_t &total_size) const {
|
||||||
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
||||||
@ -7649,7 +7651,7 @@ bool BluetoothGATTWriteDescriptorRequest::decode_length(uint32_t field_id, Proto
|
|||||||
void BluetoothGATTWriteDescriptorRequest::encode(ProtoWriteBuffer buffer) const {
|
void BluetoothGATTWriteDescriptorRequest::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_uint64(1, this->address);
|
buffer.encode_uint64(1, this->address);
|
||||||
buffer.encode_uint32(2, this->handle);
|
buffer.encode_uint32(2, this->handle);
|
||||||
buffer.encode_string(3, this->data);
|
buffer.encode_bytes(3, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||||
}
|
}
|
||||||
void BluetoothGATTWriteDescriptorRequest::calculate_size(uint32_t &total_size) const {
|
void BluetoothGATTWriteDescriptorRequest::calculate_size(uint32_t &total_size) const {
|
||||||
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
||||||
@ -7751,7 +7753,7 @@ bool BluetoothGATTNotifyDataResponse::decode_length(uint32_t field_id, ProtoLeng
|
|||||||
void BluetoothGATTNotifyDataResponse::encode(ProtoWriteBuffer buffer) const {
|
void BluetoothGATTNotifyDataResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_uint64(1, this->address);
|
buffer.encode_uint64(1, this->address);
|
||||||
buffer.encode_uint32(2, this->handle);
|
buffer.encode_uint32(2, this->handle);
|
||||||
buffer.encode_string(3, this->data);
|
buffer.encode_bytes(3, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||||
}
|
}
|
||||||
void BluetoothGATTNotifyDataResponse::calculate_size(uint32_t &total_size) const {
|
void BluetoothGATTNotifyDataResponse::calculate_size(uint32_t &total_size) const {
|
||||||
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
ProtoSize::add_uint64_field(total_size, 1, this->address, false);
|
||||||
@ -8481,7 +8483,7 @@ bool VoiceAssistantAudio::decode_length(uint32_t field_id, ProtoLengthDelimited
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void VoiceAssistantAudio::encode(ProtoWriteBuffer buffer) const {
|
void VoiceAssistantAudio::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_string(1, this->data);
|
buffer.encode_bytes(1, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||||
buffer.encode_bool(2, this->end);
|
buffer.encode_bool(2, this->end);
|
||||||
}
|
}
|
||||||
void VoiceAssistantAudio::calculate_size(uint32_t &total_size) const {
|
void VoiceAssistantAudio::calculate_size(uint32_t &total_size) const {
|
||||||
|
@ -526,9 +526,13 @@ class BytesType(TypeInfo):
|
|||||||
reference_type = "std::string &"
|
reference_type = "std::string &"
|
||||||
const_reference_type = "const std::string &"
|
const_reference_type = "const std::string &"
|
||||||
decode_length = "value.as_string()"
|
decode_length = "value.as_string()"
|
||||||
encode_func = "encode_string"
|
encode_func = "encode_bytes"
|
||||||
wire_type = WireType.LENGTH_DELIMITED # Uses wire type 2
|
wire_type = WireType.LENGTH_DELIMITED # Uses wire type 2
|
||||||
|
|
||||||
|
@property
|
||||||
|
def encode_content(self) -> str:
|
||||||
|
return f"buffer.encode_bytes({self.number}, reinterpret_cast<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size());"
|
||||||
|
|
||||||
def dump(self, name: str) -> str:
|
def dump(self, name: str) -> str:
|
||||||
o = f"out.append(format_hex_pretty({name}));"
|
o = f"out.append(format_hex_pretty({name}));"
|
||||||
return o
|
return o
|
||||||
|
Loading…
x
Reference in New Issue
Block a user