blob: 77b0f46795eb791f09187565edeaee8bcdd60626 [file] [edit]
// Copyright 2026 Google Inc. All Rights Reserved.
//
// 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.
#ifndef NINJA_PROTO_READER_H_
#define NINJA_PROTO_READER_H_
#include <cstdint>
#include <string>
#include <vector>
struct InputStream;
// This file and proto_reader.cc implement a minimal read-only protobuf runtime
// to be used for testing.
// Based on https://github.com/google/protobuf/blob/3.0.x/src/google/protobuf/wire_format_lite.h
static inline int32_t ZigZagDecode32(uint32_t n) {
return (n >> 1) ^ -static_cast<int32_t>(n & 1);
}
static inline int64_t ZigZagDecode64(uint64_t n) {
return (n >> 1) ^ -static_cast<int64_t>(n & 1);
}
bool ReadVarint32(InputStream& input, uint32_t* value);
bool ReadVarint64(InputStream& input, uint64_t* value);
bool ReadFixed32(InputStream& input, uint32_t* value);
bool ReadFixed64(InputStream& input, uint64_t* value);
bool ReadTag(InputStream& input, uint32_t* tag, int* field_number, int* wire_type);
bool ReadString(InputStream& input, std::string* value);
bool ReadFloat(InputStream& input, float* value);
bool ReadDouble(InputStream& input, double* value);
bool SkipField(InputStream& input, int wire_type);
// Base Diff utility functions for primitive types.
// These are used by generated Diff functions to report specific field mismatches.
bool Diff(const std::string& a, const std::string& b,
std::vector<std::string>* diffs, const std::string& prefix);
bool Diff(int32_t a, int32_t b, std::vector<std::string>* diffs,
const std::string& prefix);
bool Diff(int64_t a, int64_t b, std::vector<std::string>* diffs,
const std::string& prefix);
bool Diff(uint32_t a, uint32_t b, std::vector<std::string>* diffs,
const std::string& prefix);
bool Diff(uint64_t a, uint64_t b, std::vector<std::string>* diffs,
const std::string& prefix);
bool Diff(bool a, bool b, std::vector<std::string>* diffs,
const std::string& prefix);
bool Diff(float a, float b, std::vector<std::string>* diffs,
const std::string& prefix);
bool Diff(double a, double b, std::vector<std::string>* diffs,
const std::string& prefix);
#endif // NINJA_PROTO_READER_H_