Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/internal/json.h
Line
Count
Source
1
// Copyright 2024 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef THIRD_PARTY_CEL_CPP_INTERNAL_JSON_H_
16
#define THIRD_PARTY_CEL_CPP_INTERNAL_JSON_H_
17
18
#include <string>
19
20
#include "google/protobuf/struct.pb.h"
21
#include "absl/base/nullability.h"
22
#include "absl/status/status.h"
23
#include "google/protobuf/descriptor.h"
24
#include "google/protobuf/message.h"
25
26
namespace cel::internal {
27
28
// Converts the given message to its `google.protobuf.Value` equivalent
29
// representation. This is similar to `proto2::json::MessageToJsonString()`,
30
// except that this results in structured serialization.
31
absl::Status MessageToJson(
32
    const google::protobuf::Message& message,
33
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
34
    google::protobuf::MessageFactory* absl_nonnull message_factory,
35
    google::protobuf::Value* absl_nonnull result);
36
absl::Status MessageToJson(
37
    const google::protobuf::Message& message,
38
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
39
    google::protobuf::MessageFactory* absl_nonnull message_factory,
40
    google::protobuf::Struct* absl_nonnull result);
41
absl::Status MessageToJson(
42
    const google::protobuf::Message& message,
43
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
44
    google::protobuf::MessageFactory* absl_nonnull message_factory,
45
    google::protobuf::Message* absl_nonnull result);
46
47
// Converts the given message field to its `google.protobuf.Value` equivalent
48
// representation. This is similar to `proto2::json::MessageToJsonString()`,
49
// except that this results in structured serialization.
50
absl::Status MessageFieldToJson(
51
    const google::protobuf::Message& message,
52
    const google::protobuf::FieldDescriptor* absl_nonnull field,
53
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
54
    google::protobuf::MessageFactory* absl_nonnull message_factory,
55
    google::protobuf::Value* absl_nonnull result);
56
absl::Status MessageFieldToJson(
57
    const google::protobuf::Message& message,
58
    const google::protobuf::FieldDescriptor* absl_nonnull field,
59
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
60
    google::protobuf::MessageFactory* absl_nonnull message_factory,
61
    google::protobuf::ListValue* absl_nonnull result);
62
absl::Status MessageFieldToJson(
63
    const google::protobuf::Message& message,
64
    const google::protobuf::FieldDescriptor* absl_nonnull field,
65
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
66
    google::protobuf::MessageFactory* absl_nonnull message_factory,
67
    google::protobuf::Struct* absl_nonnull result);
68
absl::Status MessageFieldToJson(
69
    const google::protobuf::Message& message,
70
    const google::protobuf::FieldDescriptor* absl_nonnull field,
71
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
72
    google::protobuf::MessageFactory* absl_nonnull message_factory,
73
    google::protobuf::Message* absl_nonnull result);
74
75
// Checks that the instance of `google.protobuf.Value` has a descriptor which is
76
// well formed.
77
0
inline absl::Status CheckJson(const google::protobuf::Value&) {
78
0
  return absl::OkStatus();
79
0
}
80
absl::Status CheckJson(const google::protobuf::MessageLite& message);
81
82
// Checks that the instance of `google.protobuf.ListValue` has a descriptor
83
// which is well formed.
84
0
inline absl::Status CheckJsonList(const google::protobuf::ListValue&) {
85
0
  return absl::OkStatus();
86
0
}
87
absl::Status CheckJsonList(const google::protobuf::MessageLite& message);
88
89
// Checks that the instance of `google.protobuf.Struct` has a descriptor which
90
// is well formed.
91
0
inline absl::Status CheckJsonMap(const google::protobuf::Struct&) {
92
0
  return absl::OkStatus();
93
0
}
94
absl::Status CheckJsonMap(const google::protobuf::MessageLite& message);
95
96
// Produces a debug string for the given instance of `google.protobuf.Value`.
97
std::string JsonDebugString(const google::protobuf::Value& message);
98
std::string JsonDebugString(const google::protobuf::Message& message);
99
100
// Produces a debug string for the given instance of
101
// `google.protobuf.ListValue`.
102
std::string JsonListDebugString(const google::protobuf::ListValue& message);
103
std::string JsonListDebugString(const google::protobuf::Message& message);
104
105
// Produces a debug string for the given instance of `google.protobuf.Struct`.
106
std::string JsonMapDebugString(const google::protobuf::Struct& message);
107
std::string JsonMapDebugString(const google::protobuf::Message& message);
108
109
// Compares the given instances of `google.protobuf.Value` for equality.
110
bool JsonEquals(const google::protobuf::Value& lhs,
111
                const google::protobuf::Value& rhs);
112
bool JsonEquals(const google::protobuf::Value& lhs, const google::protobuf::Message& rhs);
113
bool JsonEquals(const google::protobuf::Message& lhs, const google::protobuf::Value& rhs);
114
bool JsonEquals(const google::protobuf::Message& lhs, const google::protobuf::Message& rhs);
115
bool JsonEquals(const google::protobuf::MessageLite& lhs, const google::protobuf::MessageLite& rhs);
116
117
// Compares the given instances of `google.protobuf.ListValue` for equality.
118
bool JsonListEquals(const google::protobuf::ListValue& lhs,
119
                    const google::protobuf::ListValue& rhs);
120
bool JsonListEquals(const google::protobuf::ListValue& lhs,
121
                    const google::protobuf::Message& rhs);
122
bool JsonListEquals(const google::protobuf::Message& lhs,
123
                    const google::protobuf::ListValue& rhs);
124
bool JsonListEquals(const google::protobuf::Message& lhs, const google::protobuf::Message& rhs);
125
bool JsonListEquals(const google::protobuf::MessageLite& lhs,
126
                    const google::protobuf::MessageLite& rhs);
127
128
// Compares the given instances of `google.protobuf.Struct` for equality.
129
bool JsonMapEquals(const google::protobuf::Struct& lhs,
130
                   const google::protobuf::Struct& rhs);
131
bool JsonMapEquals(const google::protobuf::Struct& lhs,
132
                   const google::protobuf::Message& rhs);
133
bool JsonMapEquals(const google::protobuf::Message& lhs,
134
                   const google::protobuf::Struct& rhs);
135
bool JsonMapEquals(const google::protobuf::Message& lhs, const google::protobuf::Message& rhs);
136
bool JsonMapEquals(const google::protobuf::MessageLite& lhs,
137
                   const google::protobuf::MessageLite& rhs);
138
139
}  // namespace cel::internal
140
141
#endif  // THIRD_PARTY_CEL_CPP_INTERNAL_JSON_H_