Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/extensions/filters/common/expr/cel_state.cc
Line
Count
Source (jump to first uncovered line)
1
#include "source/extensions/filters/common/expr/cel_state.h"
2
3
#include "eval/public/structs/cel_proto_wrapper.h"
4
#include "flatbuffers/reflection.h"
5
#include "tools/flatbuffers_backed_impl.h"
6
7
namespace Envoy {
8
namespace Extensions {
9
namespace Filters {
10
namespace Common {
11
namespace Expr {
12
13
using google::api::expr::runtime::CelValue;
14
15
0
CelValue CelState::exprValue(Protobuf::Arena* arena, bool last) const {
16
0
  if (initialized_) {
17
0
    switch (type_) {
18
0
    case CelStateType::String:
19
0
      return CelValue::CreateString(&value_);
20
0
    case CelStateType::Bytes:
21
0
      return CelValue::CreateBytes(&value_);
22
0
    case CelStateType::Protobuf: {
23
0
      if (last) {
24
0
        return CelValue::CreateBytes(&value_);
25
0
      }
26
      // Note that this is very expensive since it incurs a de-serialization
27
0
      const auto any = serializeAsProto();
28
0
      return google::api::expr::runtime::CelProtoWrapper::CreateMessage(any.get(), arena);
29
0
    }
30
0
    case CelStateType::FlatBuffers:
31
0
      if (last) {
32
0
        return CelValue::CreateBytes(&value_);
33
0
      }
34
0
      return CelValue::CreateMap(google::api::expr::runtime::CreateFlatBuffersBackedObject(
35
0
          reinterpret_cast<const uint8_t*>(value_.data()), *reflection::GetSchema(schema_.data()),
36
0
          arena));
37
0
    }
38
0
  }
39
0
  return CelValue::CreateNull();
40
0
}
41
42
0
ProtobufTypes::MessagePtr CelState::serializeAsProto() const {
43
0
  auto any = std::make_unique<ProtobufWkt::Any>();
44
45
0
  if (type_ != CelStateType::Protobuf) {
46
0
    ProtobufWkt::BytesValue value;
47
0
    value.set_value(value_);
48
0
    any->PackFrom(value);
49
0
  } else {
50
0
    any->set_type_url(std::string(schema_));
51
0
    any->set_value(value_);
52
0
  }
53
54
0
  return any;
55
0
}
56
57
} // namespace Expr
58
} // namespace Common
59
} // namespace Filters
60
} // namespace Extensions
61
} // namespace Envoy