chromium/third_party/perfetto/src/trace_processor/util/protozero_to_json.cc

/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "src/trace_processor/util/protozero_to_json.h"

#include <optional>
#include <unordered_set>
#include <utility>
#include <vector>

#include "perfetto/ext/base/string_utils.h"
#include "perfetto/ext/base/string_view.h"
#include "perfetto/protozero/field.h"
#include "perfetto/protozero/proto_decoder.h"
#include "perfetto/protozero/proto_utils.h"
#include "protos/perfetto/common/descriptor.pbzero.h"
#include "src/trace_processor/util/descriptors.h"

namespace perfetto {
namespace trace_processor {
namespace protozero_to_json {

namespace {

FieldDescriptorProto;
PackedRepeatedFieldIterator;
ProtoWireType;

class JsonBuilder {};

bool HasFieldOptions(const FieldDescriptor& field_desc) {}

std::string FulllyQualifiedFieldName(const ProtoDescriptor& desc,
                                     const FieldDescriptor& field_desc) {}

bool IsTypeMatch(ProtoWireType wire, uint32_t type) {}

bool IsNumericFieldType(uint32_t type) {}

void MessageField(const DescriptorPool& pool,
                  const std::string& type,
                  protozero::ConstBytes protobytes,
                  bool fully_qualify_extensions,
                  JsonBuilder* out);
void EnumField(const DescriptorPool& pool,
               const FieldDescriptor& fd,
               int32_t value,
               JsonBuilder* out);

template <ProtoWireType W, typename T>
void PackedField(const DescriptorPool& pool,
                 const FieldDescriptor& fd,
                 const protozero::Field& field,
                 JsonBuilder* out) {}

template <ProtoWireType W>
void PackedBoolField(const DescriptorPool&,
                     const FieldDescriptor& fd,
                     const protozero::Field& field,
                     JsonBuilder* out) {}

void LengthField(const DescriptorPool& pool,
                 const FieldDescriptor* fd,
                 const protozero::Field& field,
                 bool fully_qualify_extensions,
                 JsonBuilder* out) {}

void EnumField(const DescriptorPool& pool,
               const FieldDescriptor& fd,
               int32_t value,
               JsonBuilder* out) {}

void VarIntField(const DescriptorPool& pool,
                 const FieldDescriptor* fd,
                 const protozero::Field& field,
                 JsonBuilder* out) {}

void Fixed32Field(const FieldDescriptor* fd,
                  const protozero::Field& field,
                  JsonBuilder* out) {}

void Fixed64Field(const FieldDescriptor* fd,
                  const protozero::Field& field,
                  JsonBuilder* out) {}

void RepeatedVarInt(const DescriptorPool& pool,
                    protozero::ConstBytes protobytes,
                    const FieldDescriptor* fd,
                    uint32_t id,
                    JsonBuilder* out) {}

void RepeatedLengthField(const DescriptorPool& pool,
                         protozero::ConstBytes protobytes,
                         const FieldDescriptor* fd,
                         uint32_t id,
                         bool fully_qualify_extensions,
                         JsonBuilder* out) {}

void RepeatedFixed64(protozero::ConstBytes protobytes,
                     const FieldDescriptor* fd,
                     uint32_t id,
                     JsonBuilder* out) {}

void RepeatedFixed32(protozero::ConstBytes protobytes,
                     const FieldDescriptor* fd,
                     uint32_t id,
                     JsonBuilder* out) {}

void InnerMessageField(const DescriptorPool& pool,
                       const std::string& type,
                       protozero::ConstBytes protobytes,
                       bool fully_qualify_extensions,
                       JsonBuilder* out) {}

void MessageField(const DescriptorPool& pool,
                  const std::string& type,
                  protozero::ConstBytes protobytes,
                  bool fully_qualify_extensions,
                  JsonBuilder* out) {}

// Prints all field options for non-empty fields of a message. Example:
// --- Message definitions ---
// FooMessage {
//   repeated int64 foo = 1 [op1 = val1, op2 = val2];
//   optional BarMessage bar = 2 [op3 = val3];
// }
//
// BarMessage {
//   optional int64 baz = 1 [op4 = val4];
// }
// --- MessageInstance ---
// foo_msg = {  // (As JSON)
//   foo: [23, 24, 25],
//   bar: {
//     baz: 42
//   }
// }
// --- Output of MessageFieldOptionsToJson(foo_msg) ---
//   foo: {
//     __field_options: {
//       op1: val1,
//       op2: val2,
//     },
//     __repeated: true
//   }
//   bar: {
//     __field_options: {
//       op3 = val3,
//     },
//     baz: {
//       __field_options: {
//         op4 = val4
//       },
//     }
//   }
void MessageFieldOptionsToJson(
    const DescriptorPool& pool,
    const std::string& type,
    const std::string& field_prefix,
    const std::unordered_set<std::string>& allowed_fields,
    JsonBuilder* out) {}

bool PopulateAllowedFieldOptionsSet(
    const DescriptorPool& pool,
    const std::string& type,
    const std::string& field_prefix,
    protozero::ConstBytes protobytes,
    std::unordered_set<std::string>& allowed_fields) {}

}  // namespace

std::string ProtozeroToJson(const DescriptorPool& pool,
                            const std::string& type,
                            protozero::ConstBytes protobytes,
                            int flags) {}

std::string ProtozeroToJson(const DescriptorPool& pool,
                            const std::string& type,
                            const std::vector<uint8_t>& protobytes,
                            int flags) {}

}  // namespace protozero_to_json
}  // namespace trace_processor
}  // namespace perfetto