pw_protobuf: Add explicit casts for -Wconversion

Bug: b/259746255
Change-Id: I1a1fd372036f7edc6ac34045f93276801d0b1a90
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/127330
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
diff --git a/pw_protobuf/BUILD.bazel b/pw_protobuf/BUILD.bazel
index 630c528..33c6892 100644
--- a/pw_protobuf/BUILD.bazel
+++ b/pw_protobuf/BUILD.bazel
@@ -64,6 +64,7 @@
         "//pw_bytes:bit",
         "//pw_containers:vector",
         "//pw_function",
+        "//pw_preprocessor",
         "//pw_result",
         "//pw_span",
         "//pw_status",
diff --git a/pw_protobuf/BUILD.gn b/pw_protobuf/BUILD.gn
index 4463f13..8c21beb 100644
--- a/pw_protobuf/BUILD.gn
+++ b/pw_protobuf/BUILD.gn
@@ -54,6 +54,7 @@
     dir_pw_bytes,
     dir_pw_function,
     dir_pw_log,
+    dir_pw_preprocessor,
     dir_pw_result,
     dir_pw_span,
     dir_pw_status,
diff --git a/pw_protobuf/CMakeLists.txt b/pw_protobuf/CMakeLists.txt
index bb90850..4d1ecec 100644
--- a/pw_protobuf/CMakeLists.txt
+++ b/pw_protobuf/CMakeLists.txt
@@ -46,6 +46,7 @@
     pw_bytes.bit
     pw_containers.vector
     pw_function
+    pw_preprocessor
     pw_protobuf.config
     pw_result
     pw_span
diff --git a/pw_protobuf/public/pw_protobuf/internal/codegen.h b/pw_protobuf/public/pw_protobuf/internal/codegen.h
index eed264f..644a2ca 100644
--- a/pw_protobuf/public/pw_protobuf/internal/codegen.h
+++ b/pw_protobuf/public/pw_protobuf/internal/codegen.h
@@ -16,10 +16,16 @@
 #include <cstdint>
 
 #include "pw_function/function.h"
+#include "pw_preprocessor/compiler.h"
 #include "pw_protobuf/wire_format.h"
 #include "pw_span/span.h"
 #include "pw_status/status.h"
 
+// TODO(b/259746255): Remove this manual application of -Wconversion when all of
+//     Pigweed builds with it.
+PW_MODIFY_DIAGNOSTICS_PUSH();
+PW_MODIFY_DIAGNOSTIC(error, "-Wconversion");
+
 namespace pw::protobuf {
 namespace internal {
 
@@ -70,13 +76,15 @@
                          size_t field_size,
                          const span<const MessageField>* nested_message_fields)
       : field_number_(field_number),
-        field_info_(
-            static_cast<unsigned int>(wire_type) << kWireTypeShift |
-            elem_size << kElemSizeShift |
-            static_cast<unsigned int>(varint_type) << kVarintTypeShift |
-            is_string << kIsStringShift | is_fixed_size << kIsFixedSizeShift |
-            is_repeated << kIsRepeatedShift | is_optional << kIsOptionalShift |
-            use_callback << kUseCallbackShift | field_size << kFieldSizeShift),
+        field_info_(static_cast<uint32_t>(wire_type) << kWireTypeShift |
+                    static_cast<uint32_t>(elem_size) << kElemSizeShift |
+                    static_cast<uint32_t>(varint_type) << kVarintTypeShift |
+                    static_cast<uint32_t>(is_string) << kIsStringShift |
+                    static_cast<uint32_t>(is_fixed_size) << kIsFixedSizeShift |
+                    static_cast<uint32_t>(is_repeated) << kIsRepeatedShift |
+                    static_cast<uint32_t>(is_optional) << kIsOptionalShift |
+                    static_cast<uint32_t>(use_callback) << kUseCallbackShift |
+                    static_cast<uint32_t>(field_size) << kFieldSizeShift),
         field_offset_(field_offset),
         nested_message_fields_(nested_message_fields) {}
 
@@ -223,3 +231,5 @@
 };
 
 }  // namespace pw::protobuf
+
+PW_MODIFY_DIAGNOSTICS_POP();