4 #ifndef _PPRINT_UTILS_H 5 #define _PPRINT_UTILS_H 7 #include <google/protobuf/text_format.h> 14 #include "base/integral_types.h" 15 #include "strings/stringpiece.h" 20 namespace gpb = ::google::protobuf;
25 typedef std::function<void(
const gpb::Message& msg,
const gpb::FieldDescriptor*,
int,
int)>
29 FdPath(
const gpb::Descriptor* root, StringPiece path);
34 void ExtractValue(
const gpb::Message& msg, ValueCb cb)
const {
35 ExtractValueRecur(msg, 0, cb);
38 bool IsRepeated()
const;
40 const std::vector<const gpb::FieldDescriptor*> path()
const {
43 void push_back(
const gpb::FieldDescriptor* fd) {
47 return !path_.empty();
51 void ExtractValueRecur(
const gpb::Message& msg, uint32 index, ValueCb cb)
const;
53 std::vector<const gpb::FieldDescriptor*> path_;
54 mutable std::vector<uint32> cur_repeated_stack_;
58 gpb::Message* AllocateMsgFromDescr(
const gpb::Descriptor* descr);
62 gpb::Message* AllocateMsgByMeta(
const std::string& type,
const std::string& fd_set);
65 std::vector<PathNode> children;
66 const gpb::FieldDescriptor* fd;
68 explicit PathNode(
const gpb::FieldDescriptor* fdescr =
nullptr) : fd(fdescr) {
71 PathNode* AddChild(
const gpb::FieldDescriptor* fd);
75 gpb::TextFormat::Printer printer_;
76 std::string type_name_;
77 std::vector<FdPath> fds_;
84 void PrintValueRecur(
size_t path_index,
const std::string& prefix,
bool has_value,
85 const gpb::Message& msg)
const;
88 using FieldPrinterPredicate =
89 std::function<gpb::TextFormat::FieldValuePrinter*(
const gpb::FieldDescriptor& fd)>;
91 explicit Printer(
const gpb::Descriptor* descriptor, FieldPrinterPredicate pred =
nullptr);
92 void Output(
const gpb::Message& msg)
const;
96 typedef std::function<std::string(const ::google::protobuf::FieldDescriptor& fd)> OverrideCb;
98 OverrideCb field_name_cb;
99 OverrideCb type_name_cb;
102 void PrintBqSchema(
const gpb::Descriptor* descr,
109 Trie* Get(ptrdiff_t i) {
110 return children_[i].get();
112 const Trie* Get(ptrdiff_t i)
const {
113 return children_[i].get();
115 void Put(ptrdiff_t i, std::unique_ptr<Trie> p) {
116 children_[i] = move(p);
118 void Resize(
size_t sz) {
119 children_.resize(sz);
121 size_t Size()
const {
122 return children_.size();
129 std::vector<std::unique_ptr<Trie> > children_;
133 void AddSizes(
const gpb::Message& msg);
134 std::map<std::string, size_t> GetSizes()
const;
135 void Print(std::ostream* out)
const;
141 inline std::ostream& operator<<(std::ostream& out,
const SizeSummarizer& ss) {
148 #endif // _PPRINT_UTILS_H