/proc/self/cwd/common/values/null_value.cc
Line | Count | Source |
1 | | // Copyright 2023 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 "google/protobuf/struct.pb.h" |
16 | | #include "absl/base/nullability.h" |
17 | | #include "absl/log/absl_check.h" |
18 | | #include "absl/status/status.h" |
19 | | #include "common/value.h" |
20 | | #include "internal/status_macros.h" |
21 | | #include "internal/well_known_types.h" |
22 | | #include "google/protobuf/arena.h" |
23 | | #include "google/protobuf/descriptor.h" |
24 | | #include "google/protobuf/io/zero_copy_stream.h" |
25 | | #include "google/protobuf/message.h" |
26 | | |
27 | | namespace cel { |
28 | | |
29 | | using ::cel::well_known_types::ValueReflection; |
30 | | |
31 | | absl::Status NullValue::SerializeTo( |
32 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
33 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
34 | 0 | google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const { |
35 | 0 | ABSL_DCHECK(descriptor_pool != nullptr); |
36 | 0 | ABSL_DCHECK(message_factory != nullptr); |
37 | 0 | ABSL_DCHECK(output != nullptr); |
38 | |
|
39 | 0 | google::protobuf::Value message; |
40 | 0 | message.set_null_value(google::protobuf::NULL_VALUE); |
41 | 0 | if (!message.SerializePartialToZeroCopyStream(output)) { |
42 | 0 | return absl::UnknownError( |
43 | 0 | "failed to serialize message: google.protobuf.Value"); |
44 | 0 | } |
45 | 0 | return absl::OkStatus(); |
46 | 0 | } |
47 | | |
48 | | absl::Status NullValue::ConvertToJson( |
49 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
50 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
51 | 0 | google::protobuf::Message* absl_nonnull json) const { |
52 | 0 | ABSL_DCHECK(descriptor_pool != nullptr); |
53 | 0 | ABSL_DCHECK(message_factory != nullptr); |
54 | 0 | ABSL_DCHECK(json != nullptr); |
55 | 0 | ABSL_DCHECK_EQ(json->GetDescriptor()->well_known_type(), |
56 | 0 | google::protobuf::Descriptor::WELLKNOWNTYPE_VALUE); |
57 | |
|
58 | 0 | ValueReflection value_reflection; |
59 | 0 | CEL_RETURN_IF_ERROR(value_reflection.Initialize(json->GetDescriptor())); |
60 | 0 | value_reflection.SetNullValue(json); |
61 | 0 | return absl::OkStatus(); |
62 | 0 | } |
63 | | |
64 | | absl::Status NullValue::Equal( |
65 | | const Value& other, |
66 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
67 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
68 | 7 | google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const { |
69 | 7 | ABSL_DCHECK(descriptor_pool != nullptr); |
70 | 7 | ABSL_DCHECK(message_factory != nullptr); |
71 | 7 | ABSL_DCHECK(arena != nullptr); |
72 | 7 | ABSL_DCHECK(result != nullptr); |
73 | | |
74 | 7 | *result = BoolValue(other.IsNull()); |
75 | 7 | return absl::OkStatus(); |
76 | 7 | } |
77 | | |
78 | | } // namespace cel |