MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ToJson

Method ToJson

internal/json.cc:189–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187 virtual ~MessageToJsonState() = default;
188
189 absl::Status ToJson(const google::protobuf::Message& message,
190 google::protobuf::MessageLite* absl_nonnull result) {
191 const auto* descriptor = message.GetDescriptor();
192 switch (descriptor->well_known_type()) {
193 case Descriptor::WELLKNOWNTYPE_DOUBLEVALUE: {
194 CEL_RETURN_IF_ERROR(reflection_.DoubleValue().Initialize(descriptor));
195 SetNumberValue(result, reflection_.DoubleValue().GetValue(message));
196 } break;
197 case Descriptor::WELLKNOWNTYPE_FLOATVALUE: {
198 CEL_RETURN_IF_ERROR(reflection_.FloatValue().Initialize(descriptor));
199 SetNumberValue(result, reflection_.FloatValue().GetValue(message));
200 } break;
201 case Descriptor::WELLKNOWNTYPE_INT64VALUE: {
202 CEL_RETURN_IF_ERROR(reflection_.Int64Value().Initialize(descriptor));
203 SetNumberValue(result, reflection_.Int64Value().GetValue(message));
204 } break;
205 case Descriptor::WELLKNOWNTYPE_UINT64VALUE: {
206 CEL_RETURN_IF_ERROR(reflection_.UInt64Value().Initialize(descriptor));
207 SetNumberValue(result, reflection_.UInt64Value().GetValue(message));
208 } break;
209 case Descriptor::WELLKNOWNTYPE_INT32VALUE: {
210 CEL_RETURN_IF_ERROR(reflection_.Int32Value().Initialize(descriptor));
211 SetNumberValue(result, reflection_.Int32Value().GetValue(message));
212 } break;
213 case Descriptor::WELLKNOWNTYPE_UINT32VALUE: {
214 CEL_RETURN_IF_ERROR(reflection_.UInt32Value().Initialize(descriptor));
215 SetNumberValue(result, reflection_.UInt32Value().GetValue(message));
216 } break;
217 case Descriptor::WELLKNOWNTYPE_STRINGVALUE: {
218 CEL_RETURN_IF_ERROR(reflection_.StringValue().Initialize(descriptor));
219 StringValueToJson(reflection_.StringValue().GetValue(message, scratch_),
220 result);
221 } break;
222 case Descriptor::WELLKNOWNTYPE_BYTESVALUE: {
223 CEL_RETURN_IF_ERROR(reflection_.BytesValue().Initialize(descriptor));
224 BytesValueToJson(reflection_.BytesValue().GetValue(message, scratch_),
225 result);
226 } break;
227 case Descriptor::WELLKNOWNTYPE_BOOLVALUE: {
228 CEL_RETURN_IF_ERROR(reflection_.BoolValue().Initialize(descriptor));
229 SetBoolValue(result, reflection_.BoolValue().GetValue(message));
230 } break;
231 case Descriptor::WELLKNOWNTYPE_ANY: {
232 CEL_ASSIGN_OR_RETURN(auto unpacked,
233 well_known_types::UnpackAnyFrom(
234 result->GetArena(), reflection_.Any(), message,
235 descriptor_pool_, message_factory_));
236 auto* struct_result = MutableStructValue(result);
237 const auto* unpacked_descriptor = unpacked->GetDescriptor();
238 SetStringValue(InsertField(struct_result, "@type"),
239 absl::StrCat("type.googleapis.com/",
240 unpacked_descriptor->full_name()));
241 switch (unpacked_descriptor->well_known_type()) {
242 case Descriptor::WELLKNOWNTYPE_DOUBLEVALUE:
243 ABSL_FALLTHROUGH_INTENDED;
244 case Descriptor::WELLKNOWNTYPE_FLOATVALUE:
245 ABSL_FALLTHROUGH_INTENDED;
246 case Descriptor::WELLKNOWNTYPE_INT64VALUE:

Callers 1

MessageToJsonFunction · 0.80

Calls 13

MessageToJsonFunction · 0.85
SnakeCaseToCamelCaseFunction · 0.85
MutableListValueClass · 0.85
DoubleValueMethod · 0.80
BoolValueMethod · 0.80
ToStringFunction · 0.50
GetDescriptorMethod · 0.45
InitializeMethod · 0.45
GetValueMethod · 0.45
PathsSizeMethod · 0.45
PathsMethod · 0.45
GetSecondsMethod · 0.45

Tested by

no test coverage detected