From 5bac2a9fc964d4022f2009af5bd2806f9e7c2762 Mon Sep 17 00:00:00 2001 From: Anqi Dong Date: Wed, 9 Nov 2022 06:22:02 +0000 Subject: pw_protobuf: Generate operator!= for Message structs It's rather awkward to have operator== but not operator!=, as we can't expect users to write `!(foo1 == foo2)` themselves. Change-Id: I587fbd01f7bd479a55bb25bab9ebeb3dfc89c8d2 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/117131 Reviewed-by: Matthias Guenther Reviewed-by: Wyatt Hepler Commit-Queue: Anqi Dong --- pw_protobuf/py/pw_protobuf/codegen_pwpb.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pw_protobuf') diff --git a/pw_protobuf/py/pw_protobuf/codegen_pwpb.py b/pw_protobuf/py/pw_protobuf/codegen_pwpb.py index 3cfebb03b..78d729582 100644 --- a/pw_protobuf/py/pw_protobuf/codegen_pwpb.py +++ b/pw_protobuf/py/pw_protobuf/codegen_pwpb.py @@ -2108,6 +2108,8 @@ def generate_struct_for_message(message: ProtoMessage, root: ProtoNode, output.write_line('static_cast(other);') output.write_line('return true;') output.write_line('}') + output.write_line('bool operator!=(const Message& other) const ' + '{ return !(*this == other); }') output.write_line('};') -- cgit v1.2.3