mirror of
https://github.com/esphome/esphome.git
synced 2026-05-30 07:16:11 +08:00
[api] Make ProtoDecodableMessage::decode() non-virtual (#15076)
This commit is contained in:
@@ -1253,7 +1253,7 @@ class ExecuteServiceArgument final : public ProtoDecodableMessage {
|
|||||||
FixedVector<int32_t> int_array{};
|
FixedVector<int32_t> int_array{};
|
||||||
FixedVector<float> float_array{};
|
FixedVector<float> float_array{};
|
||||||
FixedVector<std::string> string_array{};
|
FixedVector<std::string> string_array{};
|
||||||
void decode(const uint8_t *buffer, size_t length) override;
|
void decode(const uint8_t *buffer, size_t length);
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
const char *dump_to(DumpBuffer &out) const override;
|
const char *dump_to(DumpBuffer &out) const override;
|
||||||
#endif
|
#endif
|
||||||
@@ -1278,7 +1278,7 @@ class ExecuteServiceRequest final : public ProtoDecodableMessage {
|
|||||||
#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
|
#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
|
||||||
bool return_response{false};
|
bool return_response{false};
|
||||||
#endif
|
#endif
|
||||||
void decode(const uint8_t *buffer, size_t length) override;
|
void decode(const uint8_t *buffer, size_t length);
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
const char *dump_to(DumpBuffer &out) const override;
|
const char *dump_to(DumpBuffer &out) const override;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -152,8 +152,7 @@ class ProtoVarInt {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// Forward declarations for decode_to_message and related encoding helpers
|
// Forward declarations for encoding helpers
|
||||||
class ProtoDecodableMessage;
|
|
||||||
class ProtoMessage;
|
class ProtoMessage;
|
||||||
class ProtoSize;
|
class ProtoSize;
|
||||||
|
|
||||||
@@ -166,16 +165,9 @@ class ProtoLengthDelimited {
|
|||||||
const uint8_t *data() const { return this->value_; }
|
const uint8_t *data() const { return this->value_; }
|
||||||
size_t size() const { return this->length_; }
|
size_t size() const { return this->length_; }
|
||||||
|
|
||||||
/**
|
/// Decode the length-delimited data into a message instance.
|
||||||
* Decode the length-delimited data into an existing ProtoDecodableMessage instance.
|
/// Template preserves concrete type so decode() resolves statically.
|
||||||
*
|
template<typename T> void decode_to_message(T &msg) const;
|
||||||
* This method allows decoding without templates, enabling use in contexts
|
|
||||||
* where the message type is not known at compile time. The ProtoDecodableMessage's
|
|
||||||
* decode() method will be called with the raw data and length.
|
|
||||||
*
|
|
||||||
* @param msg The ProtoDecodableMessage instance to decode into
|
|
||||||
*/
|
|
||||||
void decode_to_message(ProtoDecodableMessage &msg) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const uint8_t *const value_;
|
const uint8_t *const value_;
|
||||||
@@ -468,7 +460,7 @@ class ProtoMessage {
|
|||||||
// Base class for messages that support decoding
|
// Base class for messages that support decoding
|
||||||
class ProtoDecodableMessage : public ProtoMessage {
|
class ProtoDecodableMessage : public ProtoMessage {
|
||||||
public:
|
public:
|
||||||
virtual void decode(const uint8_t *buffer, size_t length);
|
void decode(const uint8_t *buffer, size_t length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count occurrences of a repeated field in a protobuf buffer.
|
* Count occurrences of a repeated field in a protobuf buffer.
|
||||||
@@ -704,8 +696,8 @@ template<typename T> inline void ProtoWriteBuffer::encode_optional_sub_message(u
|
|||||||
this->encode_optional_sub_message(field_id, value.calculate_size(), &value, &proto_encode_msg<T>);
|
this->encode_optional_sub_message(field_id, value.calculate_size(), &value, &proto_encode_msg<T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of decode_to_message - must be after ProtoDecodableMessage is defined
|
// Template decode_to_message - preserves concrete type so decode() resolves statically
|
||||||
inline void ProtoLengthDelimited::decode_to_message(ProtoDecodableMessage &msg) const {
|
template<typename T> void ProtoLengthDelimited::decode_to_message(T &msg) const {
|
||||||
msg.decode(this->value_, this->length_);
|
msg.decode(this->value_, this->length_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2275,7 +2275,7 @@ def build_message_type(
|
|||||||
o += "}\n"
|
o += "}\n"
|
||||||
cpp += o
|
cpp += o
|
||||||
# Generate the decode() declaration in header (public method)
|
# Generate the decode() declaration in header (public method)
|
||||||
prot = "void decode(const uint8_t *buffer, size_t length) override;"
|
prot = "void decode(const uint8_t *buffer, size_t length);"
|
||||||
public_content.append(prot)
|
public_content.append(prot)
|
||||||
|
|
||||||
# Only generate encode method if this message needs encoding and has fields
|
# Only generate encode method if this message needs encoding and has fields
|
||||||
|
|||||||
Reference in New Issue
Block a user