Skip to content

Commit 883d727

Browse files
jckingcopybara-github
authored andcommitted
Make the minimal descriptor pool public
PiperOrigin-RevId: 691074913
1 parent a546afa commit 883d727

File tree

5 files changed

+98
-29
lines changed

5 files changed

+98
-29
lines changed

common/BUILD

+21
Original file line numberDiff line numberDiff line change
@@ -867,3 +867,24 @@ cc_test(
867867
"@com_google_protobuf//:protobuf",
868868
],
869869
)
870+
871+
cc_library(
872+
name = "minimal_descriptor_pool",
873+
srcs = ["minimal_descriptor_pool.cc"],
874+
hdrs = ["minimal_descriptor_pool.h"],
875+
deps = [
876+
"//internal:minimal_descriptor_pool",
877+
"@com_google_absl//absl/base:nullability",
878+
"@com_google_protobuf//:protobuf",
879+
],
880+
)
881+
882+
cc_test(
883+
name = "minimal_descriptor_pool_test",
884+
srcs = ["minimal_descriptor_pool_test.cc"],
885+
deps = [
886+
":minimal_descriptor_pool",
887+
"//internal:testing",
888+
"@com_google_protobuf//:protobuf",
889+
],
890+
)

common/minimal_descriptor_pool.cc

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#include "common/minimal_descriptor_pool.h"
16+
17+
#include "absl/base/nullability.h"
18+
#include "internal/minimal_descriptor_pool.h"
19+
#include "google/protobuf/descriptor.h"
20+
21+
namespace cel {
22+
23+
absl::Nonnull<const google::protobuf::DescriptorPool*> GetMinimalDescriptorPool() {
24+
return internal::GetMinimalDescriptorPool();
25+
}
26+
27+
} // namespace cel

common/minimal_descriptor_pool.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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_COMMON_MINIMAL_DESCRIPTOR_POOL_H_
16+
#define THIRD_PARTY_CEL_CPP_COMMON_MINIMAL_DESCRIPTOR_POOL_H_
17+
18+
#include "absl/base/nullability.h"
19+
#include "google/protobuf/descriptor.h"
20+
21+
namespace cel {
22+
23+
// GetMinimalDescriptorPool returns a pointer to a `google::protobuf::DescriptorPool`
24+
// which includes has the minimally necessary descriptors required by the Common
25+
// Expression Language. The returned `google::protobuf::DescriptorPool` is valid for the
26+
// lifetime of the process and should not be deleted.
27+
absl::Nonnull<const google::protobuf::DescriptorPool*> GetMinimalDescriptorPool();
28+
29+
} // namespace cel
30+
31+
#endif // THIRD_PARTY_CEL_CPP_COMMON_MINIMAL_DESCRIPTOR_POOL_H_

internal/minimal_descriptor_pool_test.cc renamed to common/minimal_descriptor_pool_test.cc

+19-19
Original file line numberDiff line numberDiff line change
@@ -12,138 +12,138 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "internal/minimal_descriptor_pool.h"
15+
#include "common/minimal_descriptor_pool.h"
1616

1717
#include "internal/testing.h"
1818
#include "google/protobuf/descriptor.h"
1919

20-
namespace cel::internal {
20+
namespace cel {
2121
namespace {
2222

2323
using ::testing::NotNull;
2424

25-
TEST(MinimalDescriptorPool, NullValue) {
25+
TEST(GetMinimalDescriptorPool, NullValue) {
2626
ASSERT_THAT(GetMinimalDescriptorPool()->FindEnumTypeByName(
2727
"google.protobuf.NullValue"),
2828
NotNull());
2929
}
3030

31-
TEST(MinimalDescriptorPool, BoolValue) {
31+
TEST(GetMinimalDescriptorPool, BoolValue) {
3232
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
3333
"google.protobuf.BoolValue");
3434
ASSERT_THAT(desc, NotNull());
3535
EXPECT_EQ(desc->well_known_type(),
3636
google::protobuf::Descriptor::WELLKNOWNTYPE_BOOLVALUE);
3737
}
3838

39-
TEST(MinimalDescriptorPool, Int32Value) {
39+
TEST(GetMinimalDescriptorPool, Int32Value) {
4040
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
4141
"google.protobuf.Int32Value");
4242
ASSERT_THAT(desc, NotNull());
4343
EXPECT_EQ(desc->well_known_type(),
4444
google::protobuf::Descriptor::WELLKNOWNTYPE_INT32VALUE);
4545
}
4646

47-
TEST(MinimalDescriptorPool, Int64Value) {
47+
TEST(GetMinimalDescriptorPool, Int64Value) {
4848
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
4949
"google.protobuf.Int64Value");
5050
ASSERT_THAT(desc, NotNull());
5151
EXPECT_EQ(desc->well_known_type(),
5252
google::protobuf::Descriptor::WELLKNOWNTYPE_INT64VALUE);
5353
}
5454

55-
TEST(MinimalDescriptorPool, UInt32Value) {
55+
TEST(GetMinimalDescriptorPool, UInt32Value) {
5656
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
5757
"google.protobuf.UInt32Value");
5858
ASSERT_THAT(desc, NotNull());
5959
EXPECT_EQ(desc->well_known_type(),
6060
google::protobuf::Descriptor::WELLKNOWNTYPE_UINT32VALUE);
6161
}
6262

63-
TEST(MinimalDescriptorPool, UInt64Value) {
63+
TEST(GetMinimalDescriptorPool, UInt64Value) {
6464
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
6565
"google.protobuf.UInt64Value");
6666
ASSERT_THAT(desc, NotNull());
6767
EXPECT_EQ(desc->well_known_type(),
6868
google::protobuf::Descriptor::WELLKNOWNTYPE_UINT64VALUE);
6969
}
7070

71-
TEST(MinimalDescriptorPool, FloatValue) {
71+
TEST(GetMinimalDescriptorPool, FloatValue) {
7272
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
7373
"google.protobuf.FloatValue");
7474
ASSERT_THAT(desc, NotNull());
7575
EXPECT_EQ(desc->well_known_type(),
7676
google::protobuf::Descriptor::WELLKNOWNTYPE_FLOATVALUE);
7777
}
7878

79-
TEST(MinimalDescriptorPool, DoubleValue) {
79+
TEST(GetMinimalDescriptorPool, DoubleValue) {
8080
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
8181
"google.protobuf.DoubleValue");
8282
ASSERT_THAT(desc, NotNull());
8383
EXPECT_EQ(desc->well_known_type(),
8484
google::protobuf::Descriptor::WELLKNOWNTYPE_DOUBLEVALUE);
8585
}
8686

87-
TEST(MinimalDescriptorPool, BytesValue) {
87+
TEST(GetMinimalDescriptorPool, BytesValue) {
8888
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
8989
"google.protobuf.BytesValue");
9090
ASSERT_THAT(desc, NotNull());
9191
EXPECT_EQ(desc->well_known_type(),
9292
google::protobuf::Descriptor::WELLKNOWNTYPE_BYTESVALUE);
9393
}
9494

95-
TEST(MinimalDescriptorPool, StringValue) {
95+
TEST(GetMinimalDescriptorPool, StringValue) {
9696
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
9797
"google.protobuf.StringValue");
9898
ASSERT_THAT(desc, NotNull());
9999
EXPECT_EQ(desc->well_known_type(),
100100
google::protobuf::Descriptor::WELLKNOWNTYPE_STRINGVALUE);
101101
}
102102

103-
TEST(MinimalDescriptorPool, Any) {
103+
TEST(GetMinimalDescriptorPool, Any) {
104104
const auto* desc =
105105
GetMinimalDescriptorPool()->FindMessageTypeByName("google.protobuf.Any");
106106
ASSERT_THAT(desc, NotNull());
107107
EXPECT_EQ(desc->well_known_type(), google::protobuf::Descriptor::WELLKNOWNTYPE_ANY);
108108
}
109109

110-
TEST(MinimalDescriptorPool, Duration) {
110+
TEST(GetMinimalDescriptorPool, Duration) {
111111
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
112112
"google.protobuf.Duration");
113113
ASSERT_THAT(desc, NotNull());
114114
EXPECT_EQ(desc->well_known_type(),
115115
google::protobuf::Descriptor::WELLKNOWNTYPE_DURATION);
116116
}
117117

118-
TEST(MinimalDescriptorPool, Timestamp) {
118+
TEST(GetMinimalDescriptorPool, Timestamp) {
119119
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
120120
"google.protobuf.Timestamp");
121121
ASSERT_THAT(desc, NotNull());
122122
EXPECT_EQ(desc->well_known_type(),
123123
google::protobuf::Descriptor::WELLKNOWNTYPE_TIMESTAMP);
124124
}
125125

126-
TEST(MinimalDescriptorPool, Value) {
126+
TEST(GetMinimalDescriptorPool, Value) {
127127
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
128128
"google.protobuf.Value");
129129
ASSERT_THAT(desc, NotNull());
130130
EXPECT_EQ(desc->well_known_type(), google::protobuf::Descriptor::WELLKNOWNTYPE_VALUE);
131131
}
132132

133-
TEST(MinimalDescriptorPool, ListValue) {
133+
TEST(GetMinimalDescriptorPool, ListValue) {
134134
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
135135
"google.protobuf.ListValue");
136136
ASSERT_THAT(desc, NotNull());
137137
EXPECT_EQ(desc->well_known_type(),
138138
google::protobuf::Descriptor::WELLKNOWNTYPE_LISTVALUE);
139139
}
140140

141-
TEST(MinimalDescriptorPool, Struct) {
141+
TEST(GetMinimalDescriptorPool, Struct) {
142142
const auto* desc = GetMinimalDescriptorPool()->FindMessageTypeByName(
143143
"google.protobuf.Struct");
144144
ASSERT_THAT(desc, NotNull());
145145
EXPECT_EQ(desc->well_known_type(), google::protobuf::Descriptor::WELLKNOWNTYPE_STRUCT);
146146
}
147147

148148
} // namespace
149-
} // namespace cel::internal
149+
} // namespace cel

internal/BUILD

-10
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,6 @@ cc_library(
535535
],
536536
)
537537

538-
cc_test(
539-
name = "minimal_descriptor_pool_test",
540-
srcs = ["minimal_descriptor_pool_test.cc"],
541-
deps = [
542-
":minimal_descriptor_pool",
543-
":testing",
544-
"@com_google_protobuf//:protobuf",
545-
],
546-
)
547-
548538
cel_proto_transitive_descriptor_set(
549539
name = "testing_descriptor_set",
550540
testonly = True,

0 commit comments

Comments
 (0)