diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index 3097a14f51..7e42c67ddf 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -47,6 +47,7 @@ #include "google/protobuf/port.h" #include "absl/base/casts.h" #include "absl/log/absl_check.h" +#include "absl/strings/string_view.h" #include "google/protobuf/arenastring.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/message_lite.h" @@ -738,6 +739,8 @@ class PROTOBUF_EXPORT WireFormatLite { static inline size_t StringSize(const absl::Cord& value); static inline size_t BytesSize(const std::string& value); static inline size_t BytesSize(const absl::Cord& value); + static inline size_t StringSize(absl::string_view value); + static inline size_t BytesSize(absl::string_view value); template static inline size_t GroupSize(const MessageType& value); @@ -1835,6 +1838,15 @@ inline size_t WireFormatLite::StringSize(const absl::Cord& value) { return LengthDelimitedSize(value.size()); } +inline size_t WireFormatLite::StringSize(const absl::string_view value) { + // WARNING: In wire_format.cc, both strings and bytes are handled by + // StringSize() to avoid code duplication. If the implementations become + // different, you will need to update that usage. + return LengthDelimitedSize(value.size()); +} +inline size_t WireFormatLite::BytesSize(const absl::string_view value) { + return LengthDelimitedSize(value.size()); +} template inline size_t WireFormatLite::GroupSize(const MessageType& value) {