Skip to content

Commit 3dad8a5

Browse files
authored
impl(spanner): constrain spanner::ProtoMessage<M>::operator<<() (#13758)
Use `internal::DebugString()` to implement the output operators for `spanner::ProtoMessage<M>` and a PROTO `spanner::Value`. This allows us to avoid the inter-release vagaries of `Message::ShortDebugString()` (by using a `google::protobuf::TextFormat::Printer` directly), and that allows us to make more-portable test expectations.
1 parent f66a62f commit 3dad8a5

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

google/cloud/spanner/proto_message.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_PROTO_MESSAGE_H
1616
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_PROTO_MESSAGE_H
1717

18+
#include "google/cloud/internal/debug_string_protobuf.h"
1819
#include "google/cloud/version.h"
1920
#include <google/protobuf/descriptor.h>
2021
#include <google/protobuf/message.h>
@@ -90,8 +91,7 @@ class ProtoMessage {
9091

9192
/// Outputs string representation of the `ProtoMessage` to the stream.
9293
friend std::ostream& operator<<(std::ostream& os, ProtoMessage const& m) {
93-
auto s = message_type(m).ShortDebugString();
94-
return os << TypeName() << " { " << s << (s.empty() ? "" : " ") << "}";
94+
return os << internal::DebugString(message_type(m), TracingOptions{});
9595
}
9696

9797
private:

google/cloud/spanner/value.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "google/cloud/spanner/value.h"
1616
#include "google/cloud/internal/base64_transforms.h"
17+
#include "google/cloud/internal/debug_string_protobuf.h"
1718
#include "google/cloud/internal/strerror.h"
1819
#include "absl/time/civil_time.h"
1920
#include <google/protobuf/descriptor.h>
@@ -180,9 +181,7 @@ std::ostream& StreamHelper(std::ostream& os, // NOLINT(misc-no-recursion)
180181
if (auto const* pt = f->GetPrototype(d)) {
181182
std::unique_ptr<google::protobuf::Message> m(pt->New());
182183
m->ParseFromString(std::string(bytes->begin(), bytes->end()));
183-
auto s = m->ShortDebugString();
184-
return os << t.proto_type_fqn() << " { " << s
185-
<< (s.empty() ? "" : " ") << "}";
184+
return os << internal::DebugString(*m, TracingOptions{});
186185
}
187186
}
188187
}

0 commit comments

Comments
 (0)