1
#pragma once
2

            
3
#include "envoy/common/pure.h"
4

            
5
#include "source/common/protobuf/protobuf.h"
6

            
7
#include "absl/types/span.h"
8

            
9
namespace Envoy {
10
namespace ProtobufMessage {
11

            
12
class ConstProtoVisitor {
13
public:
14
  virtual ~ConstProtoVisitor() = default;
15

            
16
  // Invoked when a field is visited, with the message, and field descriptor.
17
  virtual void onField(const Protobuf::Message&, const Protobuf::FieldDescriptor&) PURE;
18

            
19
  // Invoked when a message is visited, with the message and visited parents.
20
  // @param was_any_or_top_level supplies whether the message was either the top level message or an
21
  //                             Any before being unpacked for further recursion. The latter can
22
  //                             only be achieved by using recurse_into_any.
23
  // @return a status indicating if the message was validated successfully.
24
  virtual absl::Status onMessage(const Protobuf::Message&,
25
                                 absl::Span<const Protobuf::Message* const>,
26
                                 bool was_any_or_top_level) PURE;
27
};
28

            
29
absl::Status traverseMessage(ConstProtoVisitor& visitor, const Protobuf::Message& message,
30
                             bool recurse_into_any);
31

            
32
} // namespace ProtobufMessage
33
} // namespace Envoy