1
#pragma once
2

            
3
#include <string>
4
#include <vector>
5

            
6
#include "absl/container/flat_hash_map.h"
7
#include "absl/container/flat_hash_set.h"
8
#include "absl/strings/string_view.h"
9

            
10
namespace Envoy {
11
namespace Json {
12

            
13
/**
14
 * Rule defining which attribute to extract based on its JSON path.
15
 */
16
struct AttributeExtractionRule {
17
  std::string path; // JSON path (e.g., "params.name")
18

            
19
252
  explicit AttributeExtractionRule(const std::string& p) : path(p) {}
20
};
21

            
22
/**
23
 * Configuration for the JSON-RPC parser, defining which fields should be
24
 * extracted per method or globally.
25
 */
26
class JsonRpcParserConfig {
27
public:
28
118
  virtual ~JsonRpcParserConfig() = default;
29

            
30
  /**
31
   * Returns the list of fields to extract for a specific JSON-RPC method.
32
   * @param method the method name.
33
   * @return vector of extraction rules.
34
   */
35
  const std::vector<AttributeExtractionRule> getFieldsForMethod(const std::string& method) const;
36

            
37
  /**
38
   * Adds a configuration for a specific method.
39
   * @param method the method name.
40
   * @param fields the rules for field extraction.
41
   */
42
  void addMethodConfig(absl::string_view method, std::vector<AttributeExtractionRule> fields);
43

            
44
  /**
45
   * @return global fields that should always be extracted regardless of the method.
46
   */
47
153
  const absl::flat_hash_set<std::string>& getAlwaysExtract() const { return always_extract_; }
48

            
49
protected:
50
  virtual void initializeDefaults() = 0;
51

            
52
  // Per-method field policies
53
  absl::flat_hash_map<std::string, std::vector<AttributeExtractionRule>> method_fields_;
54

            
55
  // Global fields to always extract
56
  absl::flat_hash_set<std::string> always_extract_;
57
};
58

            
59
} // namespace Json
60
} // namespace Envoy