chromium/third_party/mediapipe/src/mediapipe/framework/tool/proto_util_lite.cc

// Copyright 2019 The MediaPipe Authors.
//
// 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 "mediapipe/framework/tool/proto_util_lite.h"

#include <tuple>

#include "absl/log/absl_check.h"
#include "absl/strings/match.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/statusor.h"
#include "mediapipe/framework/tool/field_data.pb.h"
#include "mediapipe/framework/type_map.h"

#define RET_CHECK_NO_LOG(cond)

namespace mediapipe {
namespace tool {

ArrayInputStream;
CodedInputStream;
CodedOutputStream;
StringOutputStream;
WireFormatLite;
FieldAccess;
FieldValue;
using ProtoPath = ProtoUtilLite::ProtoPath;
FieldType;
FieldData;

// Returns true if a wire type includes a length indicator.
bool IsLengthDelimited(WireFormatLite::WireType wire_type) {}

// Reads a single data value for a wire type.
absl::Status ReadFieldValue(uint32_t tag, CodedInputStream* in,
                            std::string* result) {}

// Reads the packed sequence of data values for a wire type.
absl::Status ReadPackedValues(WireFormatLite::WireType wire_type,
                              CodedInputStream* in,
                              std::vector<std::string>* field_values) {}

// Extracts the data value(s) for one field from a serialized message.
// The message with these field values removed is written to |out|.
absl::Status GetFieldValues(uint32_t field_id, CodedInputStream* in,
                            CodedOutputStream* out,
                            std::vector<std::string>* field_values) {}

// Injects the data value(s) for one field into a serialized message.
void SetFieldValues(uint32_t field_id, WireFormatLite::WireType wire_type,
                    const std::vector<std::string>& field_values,
                    CodedOutputStream* out) {}

FieldAccess::FieldAccess(uint32_t field_id, FieldType field_type)
    :{}

absl::Status FieldAccess::SetMessage(const std::string& message) {}

void FieldAccess::GetMessage(std::string* result) {}

std::vector<FieldValue>* FieldAccess::mutable_field_values() {}

namespace {
ProtoPathEntry;

// Returns the FieldAccess and index for a field-id or a map-id.
// Returns access to the field-id if the field index is found,
// to the map-id if the map entry is found, and to the field-id otherwise.
absl::StatusOr<std::pair<FieldAccess, int>> AccessField(
    const ProtoPathEntry& entry, FieldType field_type,
    const FieldValue& message) {}

}  // namespace

// Replaces a range of field values for one field nested within a protobuf.
absl::Status ProtoUtilLite::ReplaceFieldRange(
    FieldValue* message, ProtoPath proto_path, int length, FieldType field_type,
    const std::vector<FieldValue>& field_values) {}

// Returns a range of field values from one field nested within a protobuf.
absl::Status ProtoUtilLite::GetFieldRange(
    const FieldValue& message, ProtoPath proto_path, int length,
    FieldType field_type, std::vector<FieldValue>* field_values) {}

// Returns the number of field values in a repeated protobuf field.
absl::Status ProtoUtilLite::GetFieldCount(const FieldValue& message,
                                          ProtoPath proto_path,
                                          FieldType field_type,
                                          int* field_count) {}

// If ok, returns OkStatus, otherwise returns InvalidArgumentError.
template <typename T>
absl::Status SyntaxStatus(bool ok, const std::string& text, T* result) {}

// Templated parsing of a string value.
template <typename T>
absl::Status ParseValue(const std::string& text, T* result) {}
template <>
absl::Status ParseValue<double>(const std::string& text, double* result) {}
template <>
absl::Status ParseValue<float>(const std::string& text, float* result) {}
template <>
absl::Status ParseValue<bool>(const std::string& text, bool* result) {}
template <>
absl::Status ParseValue<std::string>(const std::string& text,
                                     std::string* result) {}

// Templated formatting of a primitive value.
template <typename T>
std::string FormatValue(T v) {}

// A helper function to parse and serialize one primtive value.
template <typename T>
absl::Status WritePrimitive(void (*writer)(T, proto_ns::io::CodedOutputStream*),
                            const std::string& text, CodedOutputStream* out) {}

// Serializes a protobuf FieldValue.
static absl::Status SerializeValue(const std::string& text,
                                   FieldType field_type,
                                   FieldValue* field_value) {}

// A helper function for deserializing one text value.
template <typename CType, FieldType DeclaredType>
static absl::Status ReadPrimitive(CodedInputStream* input,
                                  std::string* result) {}

// Deserializes a protobuf FieldValue.
static absl::Status DeserializeValue(const FieldValue& bytes,
                                     FieldType field_type,
                                     std::string* result) {}

absl::Status ProtoUtilLite::Serialize(
    const std::vector<std::string>& text_values, FieldType field_type,
    std::vector<FieldValue>* result) {}

absl::Status ProtoUtilLite::Deserialize(
    const std::vector<FieldValue>& field_values, FieldType field_type,
    std::vector<std::string>* result) {}

absl::Status ProtoUtilLite::WriteValue(const FieldData& value,
                                       FieldType field_type,
                                       std::string* field_bytes) {}

template <typename ValueT, FieldType kFieldType>
static ValueT ReadValue(absl::string_view field_bytes, absl::Status* status) {}

absl::Status ReadValue(absl::string_view field_bytes, FieldType field_type,
                       absl::string_view message_type, FieldData* result) {}

absl::Status ProtoUtilLite::ReadValue(absl::string_view field_bytes,
                                      FieldType field_type,
                                      absl::string_view message_type,
                                      FieldData* result) {}

std::string ProtoUtilLite::TypeUrl(absl::string_view type_name) {}

std::string ProtoUtilLite::ParseTypeUrl(absl::string_view type_url) {}

}  // namespace tool
}  // namespace mediapipe