1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7
8 #include "google/protobuf/json/internal/message_path.h"
9
10 #include <string>
11
12 #include "absl/strings/str_cat.h"
13
14 // Must be included last.
15 #include "google/protobuf/port_def.inc"
16
17 namespace google {
18 namespace protobuf {
19 namespace json_internal {
Describe(std::string & out) const20 void MessagePath::Describe(std::string& out) const {
21 absl::StrAppend(&out, components_.front().type_name);
22 if (components_.size() == 1) {
23 return;
24 }
25
26 absl::StrAppend(&out, " @ ");
27 for (size_t i = 1; i < components_.size(); ++i) {
28 absl::StrAppend(&out, i == 1 ? "" : ".", components_[i].field_name);
29 if (components_[i].repeated_index >= 0) {
30 absl::StrAppend(&out, "[", components_[i].repeated_index, "]");
31 }
32 }
33 absl::string_view kind_name =
34 FieldDescriptor::TypeName(components_.back().type);
35 absl::StrAppend(&out, ": ", kind_name);
36
37 absl::string_view type_name = components_.back().type_name;
38 if (!type_name.empty()) {
39 absl::StrAppend(&out, " ", type_name);
40 }
41 }
42 } // namespace json_internal
43 } // namespace protobuf
44 } // namespace google
45
46 #include "google/protobuf/port_undef.inc"
47