/proc/self/cwd/common/values/bytes_value.h
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 | | // IWYU pragma: private, include "common/value.h" |
16 | | // IWYU pragma: friend "common/value.h" |
17 | | |
18 | | #ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_BYTES_VALUE_H_ |
19 | | #define THIRD_PARTY_CEL_CPP_COMMON_VALUES_BYTES_VALUE_H_ |
20 | | |
21 | | #include <cstddef> |
22 | | #include <ostream> |
23 | | #include <string> |
24 | | #include <type_traits> |
25 | | #include <utility> |
26 | | |
27 | | #include "absl/base/attributes.h" |
28 | | #include "absl/base/nullability.h" |
29 | | #include "absl/status/status.h" |
30 | | #include "absl/strings/cord.h" |
31 | | #include "absl/strings/string_view.h" |
32 | | #include "absl/types/optional.h" |
33 | | #include "common/internal/byte_string.h" |
34 | | #include "common/type.h" |
35 | | #include "common/value_kind.h" |
36 | | #include "common/values/values.h" |
37 | | #include "google/protobuf/arena.h" |
38 | | #include "google/protobuf/descriptor.h" |
39 | | #include "google/protobuf/io/zero_copy_stream.h" |
40 | | #include "google/protobuf/message.h" |
41 | | |
42 | | namespace cel { |
43 | | |
44 | | class Value; |
45 | | class BytesValue; |
46 | | class BytesValueInputStream; |
47 | | class BytesValueOutputStream; |
48 | | |
49 | | namespace common_internal { |
50 | | absl::string_view LegacyBytesValue(const BytesValue& value, bool stable, |
51 | | google::protobuf::Arena* absl_nonnull arena); |
52 | | } // namespace common_internal |
53 | | |
54 | | // `BytesValue` represents values of the primitive `bytes` type. |
55 | | class BytesValue final : private common_internal::ValueMixin<BytesValue> { |
56 | | public: |
57 | | static constexpr ValueKind kKind = ValueKind::kBytes; |
58 | | |
59 | | static BytesValue From(const char* absl_nullable value, |
60 | | google::protobuf::Arena* absl_nonnull arena |
61 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
62 | 0 | return BytesValue(common_internal::ByteString::From(value, arena)); |
63 | 0 | } |
64 | | static BytesValue From(absl::string_view value, |
65 | | google::protobuf::Arena* absl_nonnull arena |
66 | 1.59k | ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
67 | 1.59k | return BytesValue(common_internal::ByteString::From(value, arena)); |
68 | 1.59k | } |
69 | | static BytesValue From(const absl::Cord& value, |
70 | | google::protobuf::Arena* absl_nonnull arena |
71 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
72 | 0 | return BytesValue(common_internal::ByteString::From(value, arena)); |
73 | 0 | } |
74 | | static BytesValue From(std::string&& value, |
75 | | google::protobuf::Arena* absl_nonnull arena |
76 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
77 | 0 | return BytesValue( |
78 | 0 | common_internal::ByteString::From(std::move(value), arena)); |
79 | 0 | } |
80 | | |
81 | | static BytesValue Wrap(absl::string_view value, |
82 | | google::protobuf::Arena* absl_nullable arena |
83 | 24.3k | ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
84 | 24.3k | return BytesValue(common_internal::ByteString::Wrap(value, arena)); |
85 | 24.3k | } |
86 | | static BytesValue Wrap( |
87 | | const absl::Cord* absl_nonnull value ABSL_ATTRIBUTE_LIFETIME_BOUND, |
88 | 0 | google::protobuf::Arena* absl_nullable arena ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
89 | 0 | return BytesValue(common_internal::ByteString::Wrap(value, arena)); |
90 | 0 | } |
91 | | static BytesValue Wrap(std::nullptr_t, google::protobuf::Arena*) = delete; |
92 | | static BytesValue Wrap(std::string&& value, google::protobuf::Arena*) = delete; |
93 | | |
94 | | // Returns a BytesValue that aliases the provided string. Caller must ensure |
95 | | // the provided string outlives the use of the returned BytesValue. |
96 | 0 | static BytesValue WrapUnsafe(absl::string_view value) { |
97 | 0 | return BytesValue(common_internal::ByteString::WrapUnsafe(value)); |
98 | 0 | } |
99 | 0 | static BytesValue WrapUnsafe(const absl::Cord* absl_nonnull value) { |
100 | 0 | return BytesValue(common_internal::ByteString::WrapUnsafe(value)); |
101 | 0 | } |
102 | | static BytesValue WrapUnsafe(std::nullptr_t) = delete; |
103 | | |
104 | | static BytesValue Concat(const BytesValue& lhs, const BytesValue& rhs, |
105 | | google::protobuf::Arena* absl_nonnull arena |
106 | | ABSL_ATTRIBUTE_LIFETIME_BOUND); |
107 | | |
108 | 147 | BytesValue() = default; |
109 | | BytesValue(const BytesValue&) = default; |
110 | | BytesValue(BytesValue&&) = default; |
111 | | BytesValue& operator=(const BytesValue&) = default; |
112 | | BytesValue& operator=(BytesValue&&) = default; |
113 | | |
114 | | explicit BytesValue(const StringValue& other); |
115 | | |
116 | 0 | constexpr ValueKind kind() const { return kKind; } |
117 | | |
118 | 0 | absl::string_view GetTypeName() const { return BytesType::kName; } |
119 | | |
120 | | std::string DebugString() const; |
121 | | |
122 | | // See Value::SerializeTo(). |
123 | | absl::Status SerializeTo( |
124 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
125 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
126 | | google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const; |
127 | | |
128 | | // See Value::ConvertToJson(). |
129 | | absl::Status ConvertToJson( |
130 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
131 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
132 | | google::protobuf::Message* absl_nonnull json) const; |
133 | | |
134 | | absl::Status Equal(const Value& other, |
135 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
136 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
137 | | google::protobuf::Arena* absl_nonnull arena, |
138 | | Value* absl_nonnull result) const; |
139 | | using ValueMixin::Equal; |
140 | | |
141 | 0 | bool IsZeroValue() const { return value_.empty(); } |
142 | | |
143 | 0 | BytesValue Clone(google::protobuf::Arena* absl_nonnull arena) const { |
144 | 0 | return BytesValue(value_.Clone(arena)); |
145 | 0 | } |
146 | | |
147 | | ABSL_DEPRECATED("Use ToString()") |
148 | 0 | std::string NativeString() const { return value_.ToString(); } |
149 | | |
150 | | ABSL_DEPRECATED("Use ToStringView()") |
151 | | absl::string_view NativeString( |
152 | | std::string& scratch |
153 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND) const ABSL_ATTRIBUTE_LIFETIME_BOUND { |
154 | 0 | return value_.ToStringView(&scratch); |
155 | 0 | } |
156 | | |
157 | | ABSL_DEPRECATED("Use ToCord()") |
158 | 0 | absl::Cord NativeCord() const { return value_.ToCord(); } |
159 | | |
160 | | template <typename Visitor> |
161 | | ABSL_DEPRECATED("Use TryFlat()") |
162 | | std::common_type_t< |
163 | | std::invoke_result_t<Visitor, absl::string_view>, |
164 | | std::invoke_result_t<Visitor, const absl::Cord&>> NativeValue(Visitor&& |
165 | | visitor) |
166 | 7.00k | const { |
167 | 7.00k | return value_.Visit(std::forward<Visitor>(visitor)); |
168 | 7.00k | } type_conversion_functions.cc:std::__1::common_type<cel::(anonymous namespace)::RegisterStringConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(cel::BytesValue const&, cel::Function::InvokeContext const&) const::{lambda(auto:1 const&)#1}::__invoke_result_impl<void, cel::(anonymous namespace)::RegisterStringConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(cel::BytesValue const&, cel::Function::InvokeContext const&) const::{lambda(auto:1 const&)#1}, cel::(anonymous namespace)::RegisterStringConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(cel::BytesValue const&, cel::Function::InvokeContext const&) const::{lambda(auto:1 const&)#1}::basic_string_view<char, cel::(anonymous namespace)::RegisterStringConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(cel::BytesValue const&, cel::Function::InvokeContext const&) const::{lambda(auto:1 const&)#1}::char_traits<char> > >::type, std::__1::common_type<void, cel::(anonymous namespace)::RegisterStringConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(cel::BytesValue const&, cel::Function::InvokeContext const&) const::{lambda(auto:1 const&)#1}, absl::lts_20260526::Cord const&>::type>::type cel::BytesValue::NativeValue<cel::(anonymous namespace)::RegisterStringConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(cel::BytesValue const&, cel::Function::InvokeContext const&) const::{lambda(auto:1 const&)#1}>(cel::(anonymous namespace)::RegisterStringConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(cel::BytesValue const&, cel::Function::InvokeContext const&) const::{lambda(auto:1 const&)#1}&&) constLine | Count | Source | 166 | 2.38k | const { | 167 | 2.38k | return value_.Visit(std::forward<Visitor>(visitor)); | 168 | 2.38k | } |
Unexecuted instantiation: bytes_value.cc:std::__1::common_type<std::__1::__invoke_result_impl<void, absl::lts_20260526::Overload<cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(std::__1::basic_string_view<char, std::__1::char_traits<char> >)#1}, cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(absl::lts_20260526::Cord const&)#1}>, std::__1::basic_string_view<char, std::__1::char_traits<char> > >::type, absl::lts_20260526::Overload<cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(std::__1::basic_string_view<char, std::__1::char_traits<char> >)#1}, cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(absl::lts_20260526::Cord const&)#1}><void, absl::lts_20260526::Overload<cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(std::__1::basic_string_view<char, std::__1::char_traits<char> >)#1}, cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(absl::lts_20260526::Cord const&)#1}>, absl::lts_20260526::Cord const>::type>::type cel::BytesValue::NativeValue<absl::lts_20260526::Overload<cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(std::__1::basic_string_view<char, std::__1::char_traits<char> >)#1}, cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(absl::lts_20260526::Cord const&)#1}> >(absl::lts_20260526::Overload<cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(std::__1::basic_string_view<char, std::__1::char_traits<char> >)#1}, cel::(anonymous namespace)::BytesDebugString<cel::BytesValue>(cel::BytesValue const&)::{lambda(absl::lts_20260526::Cord const&)#1}>&&) constbytes_value.cc:std::__1::common_type<std::__1::__invoke_result_impl<void, cel::BytesValue::ConvertToJson(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Message*) const::$_0, std::__1::basic_string_view<char, std::__1::char_traits<char> > >::type, std::__1::__invoke_result_impl<void, cel::BytesValue::ConvertToJson(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Message*) const::$_0, absl::lts_20260526::Cord const&>::type>::type cel::BytesValue::NativeValue<cel::BytesValue::ConvertToJson(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Message*) const::$_0>(cel::BytesValue::ConvertToJson(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Message*) const::$_0&&) const Line | Count | Source | 166 | 2.50k | const { | 167 | 2.50k | return value_.Visit(std::forward<Visitor>(visitor)); | 168 | 2.50k | } |
bytes_value.cc:std::__1::common_type<std::__1::__invoke_result_impl<void, cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0, std::__1::basic_string_view<char, std::__1::char_traits<char> > >::type, std::__1::__invoke_result_impl<void, cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0, absl::lts_20260526::Cord const&>::type>::type cel::BytesValue::NativeValue<cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0>(cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0&&) const Line | Count | Source | 166 | 1.05k | const { | 167 | 1.05k | return value_.Visit(std::forward<Visitor>(visitor)); | 168 | 1.05k | } |
bytes_value.cc:std::__1::common_type<std::__1::__invoke_result_impl<void, cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> > const&) const::{lambda(auto:1 const&)#1}, std::__1::basic_string_view<char, std::__1::char_traits<char> > >::type, std::__1::common_type<void, cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> > const&) const::{lambda(auto:1 const&)#1}, absl::lts_20260526::Cord const&>::type>::type cel::BytesValue::NativeValue<cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> > const&) const::{lambda(auto:1 const&)#1}>(cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> > const&) const::{lambda(auto:1 const&)#1}&&) constLine | Count | Source | 166 | 1.05k | const { | 167 | 1.05k | return value_.Visit(std::forward<Visitor>(visitor)); | 168 | 1.05k | } |
Unexecuted instantiation: bytes_value.cc:std::__1::common_type<cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<absl::lts_20260526::Cord>(absl::lts_20260526::Cord const&) const::{lambda(auto:1 const&)#1}::__invoke_result_impl<void, cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<absl::lts_20260526::Cord>(absl::lts_20260526::Cord const&) const::{lambda(auto:1 const&)#1}, cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<absl::lts_20260526::Cord>(absl::lts_20260526::Cord const&) const::{lambda(auto:1 const&)#1}::basic_string_view<char, cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<absl::lts_20260526::Cord>(absl::lts_20260526::Cord const&) const::{lambda(auto:1 const&)#1}::char_traits<char> > >::type, std::__1::common_type<void, cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<absl::lts_20260526::Cord>(absl::lts_20260526::Cord const&) const::{lambda(auto:1 const&)#1}, absl::lts_20260526::Cord const&>::type>::type cel::BytesValue::NativeValue<cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<absl::lts_20260526::Cord>(absl::lts_20260526::Cord const&) const::{lambda(auto:1 const&)#1}>(cel::BytesValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()<absl::lts_20260526::Cord>(absl::lts_20260526::Cord const&) const::{lambda(auto:1 const&)#1}&&) constUnexecuted instantiation: struct_value_builder.cc:std::__1::common_type<std::__1::__invoke_result_impl<void, absl::lts_20260526::Overload<cel::common_internal::(anonymous namespace)::MessageValueBuilderImpl::SetSingularField(google::protobuf::FieldDescriptor const*, cel::Value)::{lambda(std::__1::basic_string_view<char, std::__1::char_traits<char> >)#1}, cel::common_internal::(anonymous namespace)::MessageValueBuilderImpl::SetSingularField(google::protobuf::FieldDescriptor const*, cel::Value)::{lambda(absl::lts_20260526::Cord const&)#1}>, std::__1::basic_string_view<char, std::__1::char_traits<char> > >::type, absl::lts_20260526::Overload<cel::common_internal::(anonymous namespace)::MessageValueBuilderImpl::SetSingularField(google::protobuf::FieldDescriptor const*, cel::Value)::{lambda(std::__1::basic_string_view<char, std::__1::char_traits<char> >)#1}, cel::common_internal::(anonymous namespace)::MessageValueBuilderImpl::SetSingularField(google::protobuf::FieldDescriptor const*, cel::Value)::{lambda(absl::lts_20260526::Cord const&)#1}><void, std::__1::common_type, absl::lts_20260526::Cord const>::type>::type cel::BytesValue::NativeValue<absl::lts_20260526::Overload<cel::common_internal::(anonymous namespace)::MessageValueBuilderImpl::SetSingularField(google::protobuf::FieldDescriptor const*, cel::Value)::{lambda(std::__1::basic_string_view<char, std::__1::char_traits<char> >)#1}, cel::common_internal::(anonymous namespace)::MessageValueBuilderImpl::SetSingularField(google::protobuf::FieldDescriptor const*, cel::Value)::{lambda(absl::lts_20260526::Cord const&)#1}> >(std::__1::common_type&&) const |
169 | | |
170 | 0 | friend void swap(BytesValue& lhs, BytesValue& rhs) noexcept { |
171 | 0 | using std::swap; |
172 | 0 | swap(lhs.value_, rhs.value_); |
173 | 0 | } |
174 | | |
175 | 398 | size_t Size() const { return value_.size(); } |
176 | | |
177 | 0 | bool IsEmpty() const { return value_.empty(); } |
178 | | |
179 | 0 | bool Equals(absl::string_view bytes) const { return value_.Equals(bytes); } |
180 | 0 | bool Equals(const absl::Cord& bytes) const { return value_.Equals(bytes); } |
181 | 720 | bool Equals(const BytesValue& bytes) const { |
182 | 720 | return value_.Equals(bytes.value_); |
183 | 720 | } |
184 | | |
185 | 0 | int Compare(absl::string_view bytes) const { return value_.Compare(bytes); } |
186 | 0 | int Compare(const absl::Cord& bytes) const { return value_.Compare(bytes); } |
187 | 2.51k | int Compare(const BytesValue& bytes) const { |
188 | 2.51k | return value_.Compare(bytes.value_); |
189 | 2.51k | } |
190 | | |
191 | | absl::optional<absl::string_view> TryFlat() const |
192 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
193 | 0 | return value_.TryFlat(); |
194 | 0 | } |
195 | | |
196 | 0 | std::string ToString() const { return value_.ToString(); } |
197 | | |
198 | 0 | void CopyToString(std::string* absl_nonnull out) const { |
199 | 0 | value_.CopyToString(out); |
200 | 0 | } |
201 | | |
202 | 0 | void AppendToString(std::string* absl_nonnull out) const { |
203 | 0 | value_.AppendToString(out); |
204 | 0 | } |
205 | | |
206 | 0 | absl::Cord ToCord() const { return value_.ToCord(); } |
207 | | |
208 | 0 | void CopyToCord(absl::Cord* absl_nonnull out) const { |
209 | 0 | value_.CopyToCord(out); |
210 | 0 | } |
211 | | |
212 | 0 | void AppendToCord(absl::Cord* absl_nonnull out) const { |
213 | 0 | value_.AppendToCord(out); |
214 | 0 | } |
215 | | |
216 | | absl::string_view ToStringView( |
217 | | std::string* absl_nonnull scratch |
218 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND) const ABSL_ATTRIBUTE_LIFETIME_BOUND { |
219 | 0 | return value_.ToStringView(scratch); |
220 | 0 | } |
221 | | |
222 | 0 | friend bool operator<(const BytesValue& lhs, const BytesValue& rhs) { |
223 | 0 | return lhs.value_ < rhs.value_; |
224 | 0 | } |
225 | | |
226 | | private: |
227 | | friend class StringValue; |
228 | | friend class common_internal::ValueMixin<BytesValue>; |
229 | | friend class BytesValueInputStream; |
230 | | friend class BytesValueOutputStream; |
231 | | friend absl::string_view common_internal::LegacyBytesValue( |
232 | | const BytesValue& value, bool stable, google::protobuf::Arena* absl_nonnull arena); |
233 | | |
234 | | explicit BytesValue(common_internal::ByteString value) noexcept |
235 | 27.4k | : value_(std::move(value)) {} |
236 | | |
237 | | common_internal::ByteString value_; |
238 | | }; |
239 | | |
240 | 0 | inline std::ostream& operator<<(std::ostream& out, const BytesValue& value) { |
241 | 0 | return out << value.DebugString(); |
242 | 0 | } |
243 | | |
244 | 0 | inline bool operator==(const BytesValue& lhs, absl::string_view rhs) { |
245 | 0 | return lhs.Equals(rhs); |
246 | 0 | } |
247 | | |
248 | 0 | inline bool operator==(absl::string_view lhs, const BytesValue& rhs) { |
249 | 0 | return rhs == lhs; |
250 | 0 | } |
251 | | |
252 | 0 | inline bool operator!=(const BytesValue& lhs, absl::string_view rhs) { |
253 | 0 | return !lhs.Equals(rhs); |
254 | 0 | } |
255 | | |
256 | 0 | inline bool operator!=(absl::string_view lhs, const BytesValue& rhs) { |
257 | 0 | return rhs != lhs; |
258 | 0 | } |
259 | | |
260 | | namespace common_internal { |
261 | | |
262 | | inline absl::string_view LegacyBytesValue(const BytesValue& value, bool stable, |
263 | 73 | google::protobuf::Arena* absl_nonnull arena) { |
264 | 73 | return LegacyByteString(value.value_, stable, arena); |
265 | 73 | } |
266 | | |
267 | | } // namespace common_internal |
268 | | |
269 | | } // namespace cel |
270 | | |
271 | | #endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_BYTES_VALUE_H_ |