From ff41eb3fc9209e6197595b54f7addfa244c0bdb6 Mon Sep 17 00:00:00 2001 From: Xuyang Tao Date: Wed, 7 Jun 2023 12:25:36 -0700 Subject: [PATCH] Depend on grpc-ecosystem/proto-converter (#95) --- .bazelrc | 3 + WORKSPACE | 17 +++--- perf_benchmark/BUILD | 15 +++-- perf_benchmark/benchmark_input_stream.cc | 6 +- perf_benchmark/benchmark_input_stream.h | 4 +- ...nput_stream_translator_integration_test.cc | 3 +- perf_benchmark/benchmark_main.cc | 3 +- perf_benchmark/utils.h | 2 +- repositories.bzl | 37 ++++++------ src/BUILD | 4 ++ .../internal/protobuf_types.h | 3 +- .../json_request_translator.h | 2 +- src/include/grpc_transcoding/message_reader.h | 6 +- src/include/grpc_transcoding/message_stream.h | 4 +- src/include/grpc_transcoding/prefix_writer.h | 2 +- .../request_message_translator.h | 6 +- .../request_stream_translator.h | 6 +- src/include/grpc_transcoding/request_weaver.h | 4 +- .../response_to_json_translator.h | 5 +- .../grpc_transcoding/status_error_listener.h | 12 ++-- src/include/grpc_transcoding/transcoder.h | 5 +- src/include/grpc_transcoding/type_helper.h | 8 +-- src/json_request_translator.cc | 11 ++-- src/message_reader.cc | 12 ++-- src/prefix_writer.cc | 2 +- src/request_message_translator.cc | 4 +- src/request_stream_translator.cc | 10 ++-- src/request_weaver.cc | 56 +++++++++++-------- src/response_to_json_translator.cc | 13 ++--- src/status_error_listener.cc | 13 ++--- src/type_helper.cc | 40 ++++++------- test/BUILD | 2 + test/json_request_translator_test.cc | 6 +- test/message_stream_test.cc | 4 +- test/prefix_writer_test.cc | 2 +- test/proto_stream_tester.cc | 10 ++-- test/proto_stream_tester.h | 7 +-- test/request_message_translator_test.cc | 6 +- test/request_stream_translator_test.cc | 12 ++-- test/request_translator_test_base.cc | 2 +- test/request_weaver_test.cc | 46 +++++++-------- test/response_to_json_translator_test.cc | 2 +- test/status_error_listener_test.cc | 6 +- 43 files changed, 218 insertions(+), 205 deletions(-) diff --git a/.bazelrc b/.bazelrc index 9ea4a2a..1255602 100644 --- a/.bazelrc +++ b/.bazelrc @@ -19,6 +19,9 @@ build --action_env=CC=clang-10 build --action_env=CXX=clang++-10 +build --cxxopt=-std=c++14 +build --host_cxxopt=-std=c++14 + # The ASAN configuration suitable for C++ unit tests. build:asan --copt=-fsanitize=address build:asan --linkopt=-fsanitize=address diff --git a/WORKSPACE b/WORKSPACE index 476df4d..692ab12 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -24,6 +24,7 @@ load( "io_bazel_rules_docker", "nlohmannjson_repositories", "protobuf_repositories", + "protoconverter_repositories", ) # See @@ -39,6 +40,8 @@ http_archive( urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.3.2.zip"], ) +absl_repositories() + load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") rules_fuzzing_dependencies() @@ -47,10 +50,14 @@ load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init") rules_fuzzing_init() -absl_repositories() - protobuf_repositories() +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() + +protoconverter_repositories() + googletest_repositories() googleapis_repositories() @@ -79,14 +86,8 @@ load( _cc_image_repos() # END io_bazel_rules_docker -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") -rules_proto_dependencies() - rules_proto_toolchains() load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language") diff --git a/perf_benchmark/BUILD b/perf_benchmark/BUILD index a8c9565..14c0a35 100644 --- a/perf_benchmark/BUILD +++ b/perf_benchmark/BUILD @@ -33,8 +33,8 @@ cc_proto_library( proto_library( name = "benchmark_proto", - srcs = ["benchmark.proto"], testonly = 1, + srcs = ["benchmark.proto"], deps = [ "@com_google_googleapis//google/api:annotations_proto", "@com_google_protobuf//:struct_proto", @@ -43,11 +43,11 @@ proto_library( cc_binary( name = "benchmark_main", + testonly = 1, srcs = ["benchmark_main.cc"], data = [ "benchmark_service.textproto", ], - testonly = 1, deps = [ "benchmark_cc_proto", ":benchmark_input_stream", @@ -72,8 +72,8 @@ cc_binary( # Please make sure if you're building from Debian 11 system as well. cc_image( name = "benchmark_main_image", - binary = ":benchmark_main", testonly = 1, + binary = ":benchmark_main", ) # Example run command: @@ -83,9 +83,9 @@ cc_image( # --define=PUSH_TAG=latest container_push( name = "benchmark_main_image_push", + testonly = 1, format = "Docker", image = ":benchmark_main_image", - testonly = 1, registry = "$(PUSH_REGISTRY)", repository = "$(PUSH_PROJECT)/grpc-httpjson-transcoding-benchmark", tag = "$(PUSH_TAG)", @@ -93,9 +93,9 @@ container_push( cc_library( name = "utils", + testonly = 1, srcs = ["utils.cc"], hdrs = ["utils.h"], - testonly = 1, deps = [ "benchmark_cc_proto", "//src:type_helper", @@ -112,11 +112,13 @@ cc_library( cc_library( name = "benchmark_input_stream", + testonly = 1, srcs = ["benchmark_input_stream.cc"], hdrs = ["benchmark_input_stream.h"], - testonly = 1, deps = [ "//src:transcoder_input_stream", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", ], @@ -166,6 +168,7 @@ cc_test( "//src:response_to_json_translator", "//src:type_helper", "@com_github_nlohmann_json//:json", + "@com_google_absl//absl/log:absl_check", "@com_google_googleapis//google/api:service_cc_proto", "@com_google_googletest//:gtest_main", ], diff --git a/perf_benchmark/benchmark_input_stream.cc b/perf_benchmark/benchmark_input_stream.cc index 61134e3..e3c68ce 100644 --- a/perf_benchmark/benchmark_input_stream.cc +++ b/perf_benchmark/benchmark_input_stream.cc @@ -16,7 +16,7 @@ // #include "perf_benchmark/benchmark_input_stream.h" -#include "google/protobuf/stubs/logging.h" +#include "absl/log/absl_check.h" namespace google { namespace grpc { @@ -29,7 +29,7 @@ BenchmarkZeroCopyInputStream::BenchmarkZeroCopyInputStream( msg_(std::move(json_data)), chunk_size_(msg_.size() / num_checks), pos_(0) { - GOOGLE_CHECK(num_checks <= msg_.size()); + ABSL_CHECK(num_checks <= msg_.size()); } int64_t BenchmarkZeroCopyInputStream::BytesAvailable() const { @@ -74,7 +74,7 @@ uint64_t BenchmarkZeroCopyInputStream::TotalBytes() const { } void BenchmarkZeroCopyInputStream::BackUp(int count) { - GOOGLE_CHECK(count <= pos_); + ABSL_CHECK(count <= pos_); pos_ -= count; finished_ = false; } diff --git a/perf_benchmark/benchmark_input_stream.h b/perf_benchmark/benchmark_input_stream.h index 69ff53d..2ff51a6 100644 --- a/perf_benchmark/benchmark_input_stream.h +++ b/perf_benchmark/benchmark_input_stream.h @@ -18,7 +18,7 @@ #define PERF_BENCHMARK_BENCHMARK_INPUT_STREAM_H_ #include "absl/strings/string_view.h" -#include "google/protobuf/stubs/logging.h" +#include "absl/log/absl_log.h" #include "grpc_transcoding/transcoder_input_stream.h" namespace google { @@ -55,7 +55,7 @@ class BenchmarkZeroCopyInputStream : public TranscoderInputStream { bool Next(const void** data, int* size) override; void BackUp(int count) override; bool Skip(int count) override { - GOOGLE_LOG(FATAL) << "Not implemented"; + ABSL_LOG(FATAL) << "Not implemented"; return false; }; int64_t ByteCount() const override; diff --git a/perf_benchmark/benchmark_input_stream_translator_integration_test.cc b/perf_benchmark/benchmark_input_stream_translator_integration_test.cc index 1751c6b..954028a 100644 --- a/perf_benchmark/benchmark_input_stream_translator_integration_test.cc +++ b/perf_benchmark/benchmark_input_stream_translator_integration_test.cc @@ -17,6 +17,7 @@ #include "perf_benchmark/benchmark_input_stream.h" #include "absl/strings/escaping.h" #include "absl/strings/str_format.h" +#include "absl/log/absl_check.h" #include "google/api/service.pb.h" #include "google/protobuf/text_format.h" #include "grpc_transcoding/json_request_translator.h" @@ -48,7 +49,7 @@ constexpr absl::string_view kServiceConfigTextProtoFile = // unnecessary heap allocations and create minor performance concerns. // For a small benchmark script, this is okay. auto* service = new google::api::Service(); - GOOGLE_CHECK_OK( + ABSL_CHECK_OK( LoadService(std::string(kServiceConfigTextProtoFile), service)); // Create a TypeHelper based on the service config. diff --git a/perf_benchmark/benchmark_main.cc b/perf_benchmark/benchmark_main.cc index 150d299..d36dc2e 100644 --- a/perf_benchmark/benchmark_main.cc +++ b/perf_benchmark/benchmark_main.cc @@ -20,6 +20,7 @@ #include "absl/strings/escaping.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" +#include "absl/log/absl_check.h" #include "google/api/service.pb.h" #include "google/protobuf/text_format.h" #include "grpc_transcoding/json_request_translator.h" @@ -85,7 +86,7 @@ constexpr absl::string_view kMultiStringFieldPrefix = "f"; // unnecessary heap allocations and create minor performance concerns. // For a small benchmark script, this is okay. auto* service = new google::api::Service(); - GOOGLE_CHECK_OK( + ABSL_CHECK_OK( LoadService(std::string(kServiceConfigTextProtoFile), service)); // Create a TypeHelper based on the service config. diff --git a/perf_benchmark/utils.h b/perf_benchmark/utils.h index 2e88c48..1e5913b 100644 --- a/perf_benchmark/utils.h +++ b/perf_benchmark/utils.h @@ -22,7 +22,7 @@ #include "absl/status/status.h" #include "absl/strings/string_view.h" #include "google/api/service.pb.h" -#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/converter/type_info.h" #include "perf_benchmark/benchmark.pb.h" #include "src/include/grpc_transcoding/type_helper.h" diff --git a/repositories.bzl b/repositories.bzl index 39b6c28..68d98be 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -15,16 +15,14 @@ ################################################################################ # load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -ABSEIL_COMMIT = "99477fa9f1e89a7d8253c8aeee331864710d080c" -ABSEIL_SHA256 = "495e8e1c481018126b2a84bfe36e273907ce282b135e7d161e138e463d295f3d" +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") def absl_repositories(bind = True): http_archive( name = "com_google_absl", - strip_prefix = "abseil-cpp-" + ABSEIL_COMMIT, - url = "https://github.com/abseil/abseil-cpp/archive/" + ABSEIL_COMMIT + ".tar.gz", - sha256 = ABSEIL_SHA256, + sha256 = "ea1d31db00eb37e607bfda17ffac09064670ddf05da067944c4766f517876390", + strip_prefix = "abseil-cpp-c2435f8342c2d0ed8101cb43adfd605fdc52dca2", # May 04, 2023. + urls = ["https://github.com/abseil/abseil-cpp/archive/c2435f8342c2d0ed8101cb43adfd605fdc52dca2.zip"], ) def zlib_repositories(bind = True): @@ -92,28 +90,17 @@ cc_library( build_file_content = BUILD, ) -PROTOBUF_COMMIT = "3.16.0" # Mar 04, 2021 -PROTOBUF_SHA256 = "7892a35d979304a404400a101c46ce90e85ec9e2a766a86041bb361f626247f5" - -RULES_PROTO_SHA = "97d8af4dc474595af3900dd85cb3a29ad28cc313" # Oct 31, 2019 -RULES_PROTO_SHA256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208" +PROTOBUF_COMMIT = "315ffb5be89460f2857387d20aefc59b76b8bdc3" # May 31, 2023 +PROTOBUF_SHA256 = "aa61db6ff113a1c76eac9408144c6e996c5e2d6b2410818fd7f1b0d222a50bf8" def protobuf_repositories(bind = True): http_archive( name = "com_google_protobuf", strip_prefix = "protobuf-" + PROTOBUF_COMMIT, - url = "https://github.com/google/protobuf/archive/v" + PROTOBUF_COMMIT + ".tar.gz", - sha256 = PROTOBUF_SHA256, - ) - - http_archive( - name = "rules_proto", - sha256 = RULES_PROTO_SHA256, - strip_prefix = "rules_proto-" + RULES_PROTO_SHA, urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/" + RULES_PROTO_SHA + ".tar.gz", - "https://github.com/bazelbuild/rules_proto/archive/" + RULES_PROTO_SHA + ".tar.gz", + "https://github.com/google/protobuf/archive/" + PROTOBUF_COMMIT + ".tar.gz", ], + sha256 = PROTOBUF_SHA256, ) GOOGLETEST_COMMIT = "703bd9caab50b139428cea1aaff9974ebee5742e" # v1.10.0: Oct 2, 2019 @@ -194,3 +181,11 @@ def io_bazel_rules_docker(bind = True): sha256 = RULES_DOCKER_SHA256, urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v" + RULES_DOCKER_COMMIT + "/rules_docker-v" + RULES_DOCKER_COMMIT + ".tar.gz"], ) + +def protoconverter_repositories(bind = True): + http_archive( + name = "com_google_protoconverter", + sha256 = "6081836fa3838ebb1aa15089a5c3e20f877a0244c7a39b92a2000efb40408dcb", + strip_prefix = "proto-converter-d77ff301f48bf2e7a0f8935315e847c1a8e00017", + urls = ["https://github.com/grpc-ecosystem/proto-converter/archive/d77ff301f48bf2e7a0f8935315e847c1a8e00017.zip"], + ) diff --git a/src/BUILD b/src/BUILD index 981f283..1367b3e 100644 --- a/src/BUILD +++ b/src/BUILD @@ -26,6 +26,7 @@ cc_library( ], deps = [ "@com_google_protobuf//:protobuf", + "@com_google_protoconverter//:all", ], ) @@ -78,6 +79,7 @@ cc_library( ], deps = [ ":transcoder_input_stream", + "@com_google_absl//absl/status", "@com_google_protobuf//:protobuf", ], ) @@ -276,6 +278,7 @@ cc_library( "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", "@com_google_protobuf//:protobuf", + "@com_google_protoconverter//:all", ], ) @@ -292,6 +295,7 @@ cc_library( ], deps = [ ":protobuf", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", ], diff --git a/src/include/grpc_transcoding/internal/protobuf_types.h b/src/include/grpc_transcoding/internal/protobuf_types.h index 763a69d..6f2289c 100644 --- a/src/include/grpc_transcoding/internal/protobuf_types.h +++ b/src/include/grpc_transcoding/internal/protobuf_types.h @@ -15,14 +15,13 @@ #ifndef GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_ #define GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_ -#include "google/protobuf/stubs/stringpiece.h" namespace google { namespace grpc { namespace transcoding { namespace internal { -typedef ::google::protobuf::StringPiece string_view; +typedef ::absl::string_view string_view; } // namespace internal } // namespace transcoding diff --git a/src/include/grpc_transcoding/json_request_translator.h b/src/include/grpc_transcoding/json_request_translator.h index 5a3add7..00887fb 100644 --- a/src/include/grpc_transcoding/json_request_translator.h +++ b/src/include/grpc_transcoding/json_request_translator.h @@ -18,7 +18,7 @@ #include #include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/util/internal/json_stream_parser.h" +#include "google/protobuf/util/converter/json_stream_parser.h" #include "google/protobuf/util/type_resolver.h" #include "message_stream.h" #include "request_message_translator.h" diff --git a/src/include/grpc_transcoding/message_reader.h b/src/include/grpc_transcoding/message_reader.h index 8330e71..6cf88e6 100644 --- a/src/include/grpc_transcoding/message_reader.h +++ b/src/include/grpc_transcoding/message_reader.h @@ -17,8 +17,8 @@ #include -#include "google/protobuf/stubs/status.h" #include "transcoder_input_stream.h" +#include "absl/status/status.h" namespace google { namespace grpc { @@ -92,7 +92,7 @@ class MessageReader { // is OK before consuming the `grpc_frame`. MessageAndGrpcFrame NextMessageAndGrpcFrame(); - ::google::protobuf::util::Status Status() const { return status_; } + absl::Status Status() const { return status_; } // Returns true if the stream has ended (this is permanent); otherwise returns // false. @@ -107,7 +107,7 @@ class MessageReader { // Are we all done? bool finished_; // Status - ::google::protobuf::util::Status status_; + absl::Status status_; // Buffer to store the current delimiter value. unsigned char delimiter_[kGrpcDelimiterByteSize]; diff --git a/src/include/grpc_transcoding/message_stream.h b/src/include/grpc_transcoding/message_stream.h index 4f40449..42bef6c 100644 --- a/src/include/grpc_transcoding/message_stream.h +++ b/src/include/grpc_transcoding/message_stream.h @@ -19,8 +19,8 @@ #include #include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/stubs/status.h" #include "transcoder_input_stream.h" +#include "absl/status/status.h" namespace google { namespace grpc { @@ -70,7 +70,7 @@ class MessageStream { // false. virtual bool Finished() const = 0; // Stream status to report errors - virtual ::google::protobuf::util::Status Status() const = 0; + virtual absl::Status Status() const = 0; // Virtual destructor virtual ~MessageStream() {} // Creates ZeroCopyInputStream implementation based on this stream diff --git a/src/include/grpc_transcoding/prefix_writer.h b/src/include/grpc_transcoding/prefix_writer.h index 7d32635..aa94e5e 100644 --- a/src/include/grpc_transcoding/prefix_writer.h +++ b/src/include/grpc_transcoding/prefix_writer.h @@ -18,7 +18,7 @@ #include #include -#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/converter/object_writer.h" #include "grpc_transcoding/internal/protobuf_types.h" namespace google { diff --git a/src/include/grpc_transcoding/request_message_translator.h b/src/include/grpc_transcoding/request_message_translator.h index 0ad0b60..acf9aff 100644 --- a/src/include/grpc_transcoding/request_message_translator.h +++ b/src/include/grpc_transcoding/request_message_translator.h @@ -20,8 +20,8 @@ #include "google/protobuf/stubs/bytestream.h" #include "google/protobuf/type.pb.h" -#include "google/protobuf/util/internal/error_listener.h" -#include "google/protobuf/util/internal/protostream_objectwriter.h" +#include "google/protobuf/util/converter/error_listener.h" +#include "google/protobuf/util/converter/protostream_objectwriter.h" #include "google/protobuf/util/type_resolver.h" #include "grpc_transcoding/internal/protobuf_types.h" #include "message_stream.h" @@ -118,7 +118,7 @@ class RequestMessageTranslator : public MessageStream { // MessageStream methods bool NextMessage(std::string* message); bool Finished() const; - google::protobuf::util::Status Status() const { + absl::Status Status() const { return error_listener_.status(); } diff --git a/src/include/grpc_transcoding/request_stream_translator.h b/src/include/grpc_transcoding/request_stream_translator.h index 6b900fa..88ad8c6 100644 --- a/src/include/grpc_transcoding/request_stream_translator.h +++ b/src/include/grpc_transcoding/request_stream_translator.h @@ -19,7 +19,7 @@ #include #include -#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/converter/object_writer.h" #include "google/protobuf/util/type_resolver.h" #include "grpc_transcoding/internal/protobuf_types.h" #include "message_stream.h" @@ -71,7 +71,7 @@ class RequestStreamTranslator // MessageStream methods bool NextMessage(std::string* message); bool Finished() const; - google::protobuf::util::Status Status() const { return status_; } + absl::Status Status() const { return status_; } private: // ObjectWriter methods. @@ -110,7 +110,7 @@ class RequestStreamTranslator google::protobuf::util::TypeResolver& type_resolver_; // The status of the translation - google::protobuf::util::Status status_; + absl::Status status_; // The request info RequestInfo request_info_; diff --git a/src/include/grpc_transcoding/request_weaver.h b/src/include/grpc_transcoding/request_weaver.h index 11ff6bf..af6a82b 100644 --- a/src/include/grpc_transcoding/request_weaver.h +++ b/src/include/grpc_transcoding/request_weaver.h @@ -21,7 +21,7 @@ #include #include "google/protobuf/type.pb.h" -#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/converter/object_writer.h" #include "grpc_transcoding/internal/protobuf_types.h" #include "grpc_transcoding/status_error_listener.h" @@ -78,7 +78,7 @@ class RequestWeaver : public google::protobuf::util::converter::ObjectWriter { google::protobuf::util::converter::ObjectWriter* ow, StatusErrorListener* el, bool report_collisions); - ::google::protobuf::util::Status Status() { + absl::Status Status() { return error_listener_->status(); } diff --git a/src/include/grpc_transcoding/response_to_json_translator.h b/src/include/grpc_transcoding/response_to_json_translator.h index 2582535..cb5f435 100644 --- a/src/include/grpc_transcoding/response_to_json_translator.h +++ b/src/include/grpc_transcoding/response_to_json_translator.h @@ -18,7 +18,6 @@ #include #include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/stubs/status.h" #include "google/protobuf/util/json_util.h" #include "google/protobuf/util/type_resolver.h" #include "message_reader.h" @@ -90,7 +89,7 @@ class ResponseToJsonTranslator : public MessageStream { // MessageStream implementation bool NextMessage(std::string* message); bool Finished() const { return finished_ || !status_.ok(); } - ::google::protobuf::util::Status Status() const { return status_; } + absl::Status Status() const { return status_; } private: // Translates a single message @@ -110,7 +109,7 @@ class ResponseToJsonTranslator : public MessageStream { bool first_; bool finished_; - ::google::protobuf::util::Status status_; + absl::Status status_; }; } // namespace transcoding diff --git a/src/include/grpc_transcoding/status_error_listener.h b/src/include/grpc_transcoding/status_error_listener.h index 7169e53..8a9f5c7 100644 --- a/src/include/grpc_transcoding/status_error_listener.h +++ b/src/include/grpc_transcoding/status_error_listener.h @@ -1,8 +1,9 @@ #ifndef GRPC_TRANSCODING_STATUS_ERROR_LISTENER_H_ #define GRPC_TRANSCODING_STATUS_ERROR_LISTENER_H_ -#include "google/protobuf/util/internal/error_listener.h" +#include "google/protobuf/util/converter/error_listener.h" #include "grpc_transcoding/internal/protobuf_types.h" +#include "absl/status/status.h" namespace google { namespace grpc { @@ -16,7 +17,7 @@ class StatusErrorListener StatusErrorListener() {} virtual ~StatusErrorListener() {} - ::google::protobuf::util::Status status() const { return status_; } + absl::Status status() const { return status_; } // ErrorListener implementation void InvalidName( @@ -29,12 +30,13 @@ class StatusErrorListener const ::google::protobuf::util::converter::LocationTrackerInterface& loc, internal::string_view missing_name); - void set_status(::google::protobuf::util::Status status) { status_ = status; } + void set_status(absl::Status status) { status_ = status; } private: - ::google::protobuf::util::Status status_; + absl::Status status_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StatusErrorListener); + StatusErrorListener(const StatusErrorListener&) = delete; + StatusErrorListener& operator=(const StatusErrorListener&) = delete; }; } // namespace src::include::grpc_transcoding} // namespace transcoding diff --git a/src/include/grpc_transcoding/transcoder.h b/src/include/grpc_transcoding/transcoder.h index 1d83e98..8d265e2 100644 --- a/src/include/grpc_transcoding/transcoder.h +++ b/src/include/grpc_transcoding/transcoder.h @@ -15,7 +15,6 @@ #ifndef GRPC_TRANSCODING_TRANSCODER_H_ #define GRPC_TRANSCODING_TRANSCODER_H_ -#include "google/protobuf/stubs/status.h" #include "transcoder_input_stream.h" namespace google { @@ -136,13 +135,13 @@ class Transcoder { virtual TranscoderInputStream* RequestOutput() = 0; // The status of request transcoding - virtual ::google::protobuf::util::Status RequestStatus() = 0; + virtual absl::Status RequestStatus() = 0; // ZeroCopyInputStream to read the transcoded response. virtual ::google::protobuf::io::ZeroCopyInputStream* ResponseOutput() = 0; // The status of response transcoding - virtual ::google::protobuf::util::Status ResponseStatus() = 0; + virtual absl::Status ResponseStatus() = 0; // Virtual destructor virtual ~Transcoder() {} diff --git a/src/include/grpc_transcoding/type_helper.h b/src/include/grpc_transcoding/type_helper.h index 43057b5..1a4bd35 100644 --- a/src/include/grpc_transcoding/type_helper.h +++ b/src/include/grpc_transcoding/type_helper.h @@ -16,7 +16,7 @@ #define GRPC_TRANSCODING_TYPE_HELPER_H_ #include "google/protobuf/type.pb.h" -#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/converter/type_info.h" #include "google/protobuf/util/type_resolver.h" #include @@ -57,7 +57,7 @@ class TypeHelper { // list of the field names or empty: // FieldPath = "" | Field {"." Field}; // Field = ; - ::google::protobuf::util::Status ResolveFieldPath( + absl::Status ResolveFieldPath( const ::google::protobuf::Type& type, const std::string& field_path_str, std::vector* field_path) const; @@ -65,7 +65,7 @@ class TypeHelper { // vector of actual protobuf Field pointers. // Similiar to the above method but accepts the field path as a vector of // names instead of one dot-delimited string. - ::google::protobuf::util::Status ResolveFieldPath( + absl::Status ResolveFieldPath( const ::google::protobuf::Type& type, const std::vector& field_path_unresolved, std::vector* field_path_resolved) const; @@ -77,7 +77,7 @@ class TypeHelper { const google::protobuf::Field* FindField( const google::protobuf::Type* type, - google::protobuf::StringPiece name) const; + absl::string_view name) const; ::google::protobuf::util::TypeResolver* type_resolver_; std::unique_ptr<::google::protobuf::util::converter::TypeInfo> type_info_; diff --git a/src/json_request_translator.cc b/src/json_request_translator.cc index f86837c..a4086ad 100644 --- a/src/json_request_translator.cc +++ b/src/json_request_translator.cc @@ -19,9 +19,8 @@ #include #include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/stubs/status.h" -#include "google/protobuf/util/internal/json_stream_parser.h" -#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/converter/json_stream_parser.h" +#include "google/protobuf/util/converter/object_writer.h" #include "grpc_transcoding/internal/protobuf_types.h" #include "grpc_transcoding/message_stream.h" #include "grpc_transcoding/request_message_translator.h" @@ -74,7 +73,7 @@ class LazyRequestTranslator : public MessageStream { return true; } bool Finished() const { return translated_->Finished() || !status_.ok(); } - pbutil::Status Status() const { return status_; } + absl::Status Status() const { return status_; } private: // Translates one chunk of data. Returns true, if there was input to @@ -109,7 +108,7 @@ class LazyRequestTranslator : public MessageStream { // If parsing status fails, return false. // check translated status, if fails, return false. // save failed status. - bool CheckParsingStatus(pbutil::Status parsing_status) { + bool CheckParsingStatus(absl::Status parsing_status) { status_ = parsing_status; if (!status_.ok()) { return false; @@ -135,7 +134,7 @@ class LazyRequestTranslator : public MessageStream { bool seen_input_; // Translation status - pbutil::Status status_; + absl::Status status_; }; } // namespace diff --git a/src/message_reader.cc b/src/message_reader.cc index 73417bc..b2f536b 100644 --- a/src/message_reader.cc +++ b/src/message_reader.cc @@ -91,8 +91,8 @@ std::unique_ptr MessageReader::NextMessage() { // Find out whether the stream is finished and return false. finished_ = in_->Finished(); if (finished_ && in_->BytesAvailable() != 0) { - status_ = google::protobuf::util::Status( - google::protobuf::util::StatusCode::kInternal, + status_ = absl::Status( + absl::StatusCode::kInternal, "Incomplete gRPC frame header received"); } return nullptr; @@ -106,8 +106,8 @@ std::unique_ptr MessageReader::NextMessage() { } if (delimiter_[0] != 0) { - status_ = google::protobuf::util::Status( - google::protobuf::util::StatusCode::kInternal, + status_ = absl::Status( + absl::StatusCode::kInternal, "Unsupported gRPC frame flag: " + std::to_string(delimiter_[0])); return nullptr; } @@ -118,8 +118,8 @@ std::unique_ptr MessageReader::NextMessage() { if (in_->BytesAvailable() < static_cast(current_message_size_)) { if (in_->Finished()) { - status_ = google::protobuf::util::Status( - google::protobuf::util::StatusCode::kInternal, + status_ = absl::Status( + absl::StatusCode::kInternal, "Incomplete gRPC frame expected size: " + std::to_string(current_message_size_) + " actual size: " + std::to_string(in_->BytesAvailable())); diff --git a/src/prefix_writer.cc b/src/prefix_writer.cc index b06cccd..dd150e0 100644 --- a/src/prefix_writer.cc +++ b/src/prefix_writer.cc @@ -19,7 +19,7 @@ #include #include "absl/strings/str_split.h" -#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/converter/object_writer.h" namespace google { namespace grpc { diff --git a/src/request_message_translator.cc b/src/request_message_translator.cc index 2512f23..7610cf5 100644 --- a/src/request_message_translator.cc +++ b/src/request_message_translator.cc @@ -19,8 +19,8 @@ #include #include "google/protobuf/stubs/bytestream.h" -#include "google/protobuf/util/internal/error_listener.h" -#include "google/protobuf/util/internal/protostream_objectwriter.h" +#include "google/protobuf/util/converter/error_listener.h" +#include "google/protobuf/util/converter/protostream_objectwriter.h" #include "grpc_transcoding/prefix_writer.h" #include "grpc_transcoding/request_weaver.h" diff --git a/src/request_stream_translator.cc b/src/request_stream_translator.cc index 61c2783..1239448 100644 --- a/src/request_stream_translator.cc +++ b/src/request_stream_translator.cc @@ -66,7 +66,7 @@ RequestStreamTranslator* RequestStreamTranslator::StartObject( } if (depth_ == 0) { // In depth_ == 0 case we expect only StartList() - status_ = pbutil::Status(pbutil::StatusCode::kInvalidArgument, + status_ = absl::Status(absl::StatusCode::kInvalidArgument, "Expected an array instead of an object"); return this; } @@ -87,7 +87,7 @@ RequestStreamTranslator* RequestStreamTranslator::EndObject() { } --depth_; if (depth_ < 1) { - status_ = pbutil::Status(pbutil::StatusCode::kInvalidArgument, + status_ = absl::Status(absl::StatusCode::kInvalidArgument, "Mismatched end of object."); return this; } @@ -129,7 +129,7 @@ RequestStreamTranslator* RequestStreamTranslator::EndList() { } --depth_; if (depth_ < 0) { - status_ = pbutil::Status(pbutil::StatusCode::kInvalidArgument, + status_ = absl::Status(absl::StatusCode::kInvalidArgument, "Mismatched end of array."); return this; } @@ -252,7 +252,7 @@ void RequestStreamTranslator::EndMessageTranslator() { // This shouldn't happen unless something like StartList(), StartObject(), // EndList() has been called status_ = - pbutil::Status(pbutil::StatusCode::kInvalidArgument, "Invalid object"); + absl::Status(absl::StatusCode::kInvalidArgument, "Invalid object"); } translator_.reset(); } @@ -265,7 +265,7 @@ void RequestStreamTranslator::RenderData(internal::string_view name, } if (depth_ == 0) { // In depth_ == 0 case we expect only a StartList() - status_ = pbutil::Status(pbutil::StatusCode::kInvalidArgument, + status_ = absl::Status(absl::StatusCode::kInvalidArgument, "Expected an array instead of a scalar value."); } else if (depth_ == 1) { // This means we have an array of scalar values. This can happen if the HTTP diff --git a/src/request_weaver.cc b/src/request_weaver.cc index 138a806..a360e6d 100644 --- a/src/request_weaver.cc +++ b/src/request_weaver.cc @@ -18,14 +18,18 @@ #include #include +#include +#include +#include #include "absl/strings/str_format.h" +#include "absl/strings/str_cat.h" -#include "google/protobuf/stubs/mathutil.h" +#include "google/protobuf/util/field_comparator.h" #include "google/protobuf/stubs/strutil.h" #include "google/protobuf/type.pb.h" -#include "google/protobuf/util/internal/datapiece.h" -#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/converter/datapiece.h" +#include "google/protobuf/util/converter/object_writer.h" namespace google { namespace grpc { @@ -37,22 +41,28 @@ namespace pbconv = google::protobuf::util::converter; namespace { -pb::util::Status bindingFailureStatus(internal::string_view field_name, + +bool AlmostEquals(float a, float b) { + return fabs(a - b) < 32 * FLT_EPSILON; +} + + +absl::Status bindingFailureStatus(internal::string_view field_name, internal::string_view type, const pbconv::DataPiece& value) { - return pb::util::Status( - pb::util::StatusCode::kInvalidArgument, - pb::StrCat("Failed to convert binding value ", field_name, ":", + return absl::Status( + absl::StatusCode::kInvalidArgument, + absl::StrCat("Failed to convert binding value ", field_name, ":", value.ValueAsStringOrDefault(""), " to ", type)); } -pb::util::Status isEqual(internal::string_view field_name, +absl::Status isEqual(internal::string_view field_name, const pbconv::DataPiece& value_in_body, const pbconv::DataPiece& value_in_binding) { bool value_is_same = true; switch (value_in_body.type()) { case pbconv::DataPiece::TYPE_INT32: { - pb::util::StatusOr status = value_in_binding.ToInt32(); + absl::StatusOr status = value_in_binding.ToInt32(); if (!status.ok()) { return bindingFailureStatus(field_name, "int32", value_in_binding); } @@ -62,7 +72,7 @@ pb::util::Status isEqual(internal::string_view field_name, break; } case pbconv::DataPiece::TYPE_INT64: { - pb::util::StatusOr status = value_in_binding.ToInt64(); + absl::StatusOr status = value_in_binding.ToInt64(); if (!status.ok()) { return bindingFailureStatus(field_name, "int64", value_in_binding); } @@ -72,7 +82,7 @@ pb::util::Status isEqual(internal::string_view field_name, break; } case pbconv::DataPiece::TYPE_UINT32: { - pb::util::StatusOr status = value_in_binding.ToUint32(); + absl::StatusOr status = value_in_binding.ToUint32(); if (!status.ok()) { return bindingFailureStatus(field_name, "uint32", value_in_binding); } @@ -82,7 +92,7 @@ pb::util::Status isEqual(internal::string_view field_name, break; } case pbconv::DataPiece::TYPE_UINT64: { - pb::util::StatusOr status = value_in_binding.ToUint64(); + absl::StatusOr status = value_in_binding.ToUint64(); if (!status.ok()) { return bindingFailureStatus(field_name, "uint64", value_in_binding); } @@ -92,29 +102,29 @@ pb::util::Status isEqual(internal::string_view field_name, break; } case pbconv::DataPiece::TYPE_DOUBLE: { - pb::util::StatusOr status = value_in_binding.ToDouble(); + absl::StatusOr status = value_in_binding.ToDouble(); if (!status.ok()) { return bindingFailureStatus(field_name, "double", value_in_binding); } - if (!pb::MathUtil::AlmostEquals( + if (!AlmostEquals( status.value(), value_in_body.ToDouble().value())) { value_is_same = false; } break; } case pbconv::DataPiece::TYPE_FLOAT: { - pb::util::StatusOr status = value_in_binding.ToFloat(); + absl::StatusOr status = value_in_binding.ToFloat(); if (!status.ok()) { return bindingFailureStatus(field_name, "float", value_in_binding); } - if (!pb::MathUtil::AlmostEquals(status.value(), + if (!AlmostEquals(status.value(), value_in_body.ToFloat().value())) { value_is_same = false; } break; } case pbconv::DataPiece::TYPE_BOOL: { - pb::util::StatusOr status = value_in_binding.ToBool(); + absl::StatusOr status = value_in_binding.ToBool(); if (!status.ok()) { return bindingFailureStatus(field_name, "bool", value_in_binding); } @@ -124,7 +134,7 @@ pb::util::Status isEqual(internal::string_view field_name, break; } case pbconv::DataPiece::TYPE_STRING: { - pb::util::StatusOr status = value_in_binding.ToString(); + absl::StatusOr status = value_in_binding.ToString(); if (!status.ok()) { return bindingFailureStatus(field_name, "string", value_in_binding); } @@ -134,7 +144,7 @@ pb::util::Status isEqual(internal::string_view field_name, break; } case pbconv::DataPiece::TYPE_BYTES: { - pb::util::StatusOr status = value_in_binding.ToBytes(); + absl::StatusOr status = value_in_binding.ToBytes(); if (!status.ok()) { return bindingFailureStatus(field_name, "bytes", value_in_binding); } @@ -147,15 +157,15 @@ pb::util::Status isEqual(internal::string_view field_name, break; } if (!value_is_same) { - return pb::util::Status( - pb::util::StatusCode::kInvalidArgument, + return absl::Status( + absl::StatusCode::kInvalidArgument, absl::StrFormat("The binding value %s of the field %s is " "conflicting with the value %s in the body.", value_in_binding.ValueAsStringOrDefault(""), std::string(field_name), value_in_body.ValueAsStringOrDefault(""))); } - return pb::util::OkStatus(); + return absl::OkStatus(); } } // namespace @@ -361,7 +371,7 @@ void RequestWeaver::CollisionCheck(internal::string_view name, } else if (report_collisions_) { pbconv::DataPiece value_in_binding = pbconv::DataPiece(internal::string_view(it->second), true); - pb::util::Status compare_status = + absl::Status compare_status = isEqual(name, value_in_body, value_in_binding); if (!compare_status.ok()) { error_listener_->set_status(compare_status); diff --git a/src/response_to_json_translator.cc b/src/response_to_json_translator.cc index 9897b54..79ed5b5 100644 --- a/src/response_to_json_translator.cc +++ b/src/response_to_json_translator.cc @@ -19,7 +19,6 @@ #include #include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/stubs/status.h" #include "google/protobuf/util/type_resolver.h" namespace google { @@ -109,8 +108,8 @@ bool ResponseToJsonTranslator::TranslateMessage( // message, so prepend the // output JSON with a '['. if (!WriteChar(&json_stream, '[')) { - status_ = ::google::protobuf::util::Status( - ::google::protobuf::util::StatusCode::kInternal, + status_ = absl::Status( + absl::StatusCode::kInternal, "Failed to build the response message."); return false; } @@ -119,8 +118,8 @@ bool ResponseToJsonTranslator::TranslateMessage( // For non-newline-delimited streaming calls add a ',' before each message // except the first. if (!WriteChar(&json_stream, ',')) { - status_ = ::google::protobuf::util::Status( - ::google::protobuf::util::StatusCode::kInternal, + status_ = absl::Status( + absl::StatusCode::kInternal, "Failed to build the response message."); return false; } @@ -139,8 +138,8 @@ bool ResponseToJsonTranslator::TranslateMessage( // Append a newline delimiter after the message if needed. if (streaming_ && options_.stream_newline_delimited) { if (!WriteChar(&json_stream, '\n')) { - status_ = ::google::protobuf::util::Status( - ::google::protobuf::util::StatusCode::kInternal, + status_ = absl::Status( + absl::StatusCode::kInternal, "Failed to build the response message."); return false; } diff --git a/src/status_error_listener.cc b/src/status_error_listener.cc index 08510e9..d3f3dc6 100644 --- a/src/status_error_listener.cc +++ b/src/status_error_listener.cc @@ -2,7 +2,6 @@ #include -#include "google/protobuf/stubs/stringpiece.h" namespace google { namespace grpc { @@ -12,16 +11,16 @@ namespace transcoding { void StatusErrorListener::InvalidName( const ::google::protobuf::util::converter::LocationTrackerInterface& loc, internal::string_view unknown_name, internal::string_view message) { - status_ = ::google::protobuf::util::Status( - ::google::protobuf::util::StatusCode::kInvalidArgument, + status_ = absl::Status( + absl::StatusCode::kInvalidArgument, loc.ToString() + ": " + std::string(message)); } void StatusErrorListener::InvalidValue( const ::google::protobuf::util::converter::LocationTrackerInterface& loc, internal::string_view type_name, internal::string_view value) { - status_ = ::google::protobuf::util::Status( - ::google::protobuf::util::StatusCode::kInvalidArgument, + status_ = absl::Status( + absl::StatusCode::kInvalidArgument, loc.ToString() + ": invalid value " + std::string(value) + " for type " + std::string(type_name)); } @@ -29,8 +28,8 @@ void StatusErrorListener::InvalidValue( void StatusErrorListener::MissingField( const ::google::protobuf::util::converter::LocationTrackerInterface& loc, internal::string_view missing_name) { - status_ = ::google::protobuf::util::Status( - ::google::protobuf::util::StatusCode::kInvalidArgument, + status_ = absl::Status( + absl::StatusCode::kInvalidArgument, loc.ToString() + ": missing field " + std::string(missing_name)); } diff --git a/src/type_helper.cc b/src/type_helper.cc index b2801a8..39f1113 100644 --- a/src/type_helper.cc +++ b/src/type_helper.cc @@ -22,7 +22,7 @@ #include "absl/strings/str_split.h" #include "absl/synchronization/mutex.h" #include "google/protobuf/type.pb.h" -#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/converter/type_info.h" #include "google/protobuf/util/type_resolver.h" #include "grpc_transcoding/percent_encoding.h" @@ -55,31 +55,31 @@ class SimpleTypeResolver : public pbutil::TypeResolver { // TypeResolver implementation // Resolves a type url for a message type. - virtual pbutil::Status ResolveMessageType( + virtual absl::Status ResolveMessageType( const std::string& type_url, google::protobuf::Type* type) override { auto i = type_map_.find(type_url); if (end(type_map_) != i) { if (nullptr != type) { *type = *i->second; } - return pbutil::Status(); + return absl::Status(); } else { - return pbutil::Status(pbutil::StatusCode::kNotFound, + return absl::Status(absl::StatusCode::kNotFound, "Type '" + type_url + "' cannot be found."); } } // Resolves a type url for an enum type. - virtual pbutil::Status ResolveEnumType( + virtual absl::Status ResolveEnumType( const std::string& type_url, google::protobuf::Enum* enum_type) override { auto i = enum_map_.find(type_url); if (end(enum_map_) != i) { if (nullptr != enum_type) { *enum_type = *i->second; } - return pbutil::Status(); + return absl::Status(); } else { - return pbutil::Status(pbutil::StatusCode::kNotFound, + return absl::Status(absl::StatusCode::kNotFound, "Enum '" + type_url + "' cannot be found."); } } @@ -114,27 +114,27 @@ class LockedTypeInfo : public pbconv::TypeInfo { public: LockedTypeInfo(pbconv::TypeInfo* type_info) : type_info_(type_info) {} - pbutil::StatusOr ResolveTypeUrl( - google::protobuf::StringPiece type_url) const override { + absl::StatusOr ResolveTypeUrl( + absl::string_view type_url) const override { absl::MutexLock lock(&mutex_); return type_info_->ResolveTypeUrl(type_url); } const google::protobuf::Type* GetTypeByTypeUrl( - google::protobuf::StringPiece type_url) const override { + absl::string_view type_url) const override { absl::MutexLock lock(&mutex_); return type_info_->GetTypeByTypeUrl(type_url); } const google::protobuf::Enum* GetEnumByTypeUrl( - google::protobuf::StringPiece type_url) const override { + absl::string_view type_url) const override { absl::MutexLock lock(&mutex_); return type_info_->GetEnumByTypeUrl(type_url); } const google::protobuf::Field* FindField( const google::protobuf::Type* type, - google::protobuf::StringPiece camel_case_name) const override { + absl::string_view camel_case_name) const override { absl::MutexLock lock(&mutex_); return type_info_->FindField(type, camel_case_name); } @@ -174,7 +174,7 @@ void TypeHelper::AddEnum(const google::protobuf::Enum& e) { reinterpret_cast(type_resolver_)->AddEnum(e); } -pbutil::Status TypeHelper::ResolveFieldPath( +absl::Status TypeHelper::ResolveFieldPath( const google::protobuf::Type& type, const std::string& field_path_str, std::vector* field_path_out) const { // Split the field names & call ResolveFieldPath() @@ -185,7 +185,7 @@ pbutil::Status TypeHelper::ResolveFieldPath( const google::protobuf::Field* TypeHelper::FindField( const google::protobuf::Type* type, - google::protobuf::StringPiece name) const { + absl::string_view name) const { auto* field = Info()->FindField(type, name); if (field != nullptr) { return field; @@ -198,7 +198,7 @@ const google::protobuf::Field* TypeHelper::FindField( return field; } -pbutil::Status TypeHelper::ResolveFieldPath( +absl::Status TypeHelper::ResolveFieldPath( const google::protobuf::Type& type, const std::vector& field_names, std::vector* field_path_out) const { @@ -213,7 +213,7 @@ pbutil::Status TypeHelper::ResolveFieldPath( // Find the field by name in the current type auto field = FindField(current_type, field_names[i]); if (nullptr == field) { - return pbutil::Status(pbutil::StatusCode::kInvalidArgument, + return absl::Status(absl::StatusCode::kInvalidArgument, "Could not find field \"" + field_names[i] + "\" in the type \"" + current_type->name() + "\"."); @@ -223,8 +223,8 @@ pbutil::Status TypeHelper::ResolveFieldPath( if (i < field_names.size() - 1) { // If this is not the last field in the path, it must be a message if (google::protobuf::Field::TYPE_MESSAGE != field->kind()) { - return pbutil::Status( - pbutil::StatusCode::kInvalidArgument, + return absl::Status( + absl::StatusCode::kInvalidArgument, "Encountered a non-leaf field \"" + field->name() + "\" that is not a message while parsing a field path"); } @@ -232,14 +232,14 @@ pbutil::Status TypeHelper::ResolveFieldPath( // Update the type of the current message current_type = Info()->GetTypeByTypeUrl(field->type_url()); if (nullptr == current_type) { - return pbutil::Status(pbutil::StatusCode::kInvalidArgument, + return absl::Status(absl::StatusCode::kInvalidArgument, "Cannot find the type \"" + field->type_url() + "\" while parsing a field path."); } } } *field_path_out = std::move(field_path); - return pbutil::Status(); + return absl::Status(); } } // namespace transcoding diff --git a/test/BUILD b/test/BUILD index 3c838a3..657b77f 100644 --- a/test/BUILD +++ b/test/BUILD @@ -79,6 +79,7 @@ cc_test( "//src:prefix_writer", "@com_google_googletest//:gtest_main", "@com_google_protobuf//:protobuf", + "@com_google_protoconverter//:testing", ], ) @@ -92,6 +93,7 @@ cc_test( "//src:request_weaver", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", + "@com_google_protoconverter//:testing", ], ) diff --git a/test/json_request_translator_test.cc b/test/json_request_translator_test.cc index 1a63267..f3d9a91 100644 --- a/test/json_request_translator_test.cc +++ b/test/json_request_translator_test.cc @@ -528,7 +528,7 @@ TEST_F(JsonRequestTranslatorTest, ErrorInvalidJson) { Finish(); EXPECT_TRUE(Tester().ExpectNone()); EXPECT_TRUE(Tester().ExpectStatusEq( - google::protobuf::util::StatusCode::kInvalidArgument)); + absl::StatusCode::kInvalidArgument)); } } } @@ -543,7 +543,7 @@ TEST_F(JsonRequestTranslatorTest, WrongBindingType) { Finish(); EXPECT_TRUE(Tester().ExpectNone()); EXPECT_TRUE(Tester().ExpectStatusEq( - google::protobuf::util::StatusCode::kInvalidArgument)); + absl::StatusCode::kInvalidArgument)); } TEST_F(JsonRequestTranslatorTest, StreamingSimple) { @@ -791,7 +791,7 @@ TEST_F(JsonRequestTranslatorTest, StreamingErrorNotAnArray) { Finish(); EXPECT_TRUE(Tester().ExpectNone()); EXPECT_TRUE(Tester().ExpectStatusEq( - google::protobuf::util::StatusCode::kInvalidArgument)); + absl::StatusCode::kInvalidArgument)); } } // namespace diff --git a/test/message_stream_test.cc b/test/message_stream_test.cc index 341256c..7080048 100644 --- a/test/message_stream_test.cc +++ b/test/message_stream_test.cc @@ -52,8 +52,8 @@ class TestMessageStream : public MessageStream { } } bool Finished() const { return messages_.empty() && finished_; } - google::protobuf::util::Status Status() const { - return google::protobuf::util::Status(); + absl::Status Status() const { + return absl::Status(); } private: diff --git a/test/prefix_writer_test.cc b/test/prefix_writer_test.cc index 0421ec8..5484970 100644 --- a/test/prefix_writer_test.cc +++ b/test/prefix_writer_test.cc @@ -19,7 +19,7 @@ #include #include -#include "google/protobuf/util/internal/expecting_objectwriter.h" +#include "google/protobuf/util/converter/expecting_objectwriter.h" #include "gtest/gtest.h" namespace google { diff --git a/test/proto_stream_tester.cc b/test/proto_stream_tester.cc index f640a4e..d00f218 100644 --- a/test/proto_stream_tester.cc +++ b/test/proto_stream_tester.cc @@ -17,8 +17,6 @@ #include "proto_stream_tester.h" #include - -#include "google/protobuf/stubs/status.h" #include "gtest/gtest.h" namespace google { @@ -32,7 +30,7 @@ ProtoStreamTester::ProtoStreamTester(MessageStream& stream, bool delimiters) bool ProtoStreamTester::ExpectNone() { // First check the status of the stream - if (!ExpectStatusEq(google::protobuf::util::StatusCode::kOk)) { + if (!ExpectStatusEq(absl::StatusCode::kOk)) { return false; } std::string message; @@ -46,7 +44,7 @@ bool ProtoStreamTester::ExpectNone() { bool ProtoStreamTester::ExpectFinishedEq(bool expected) { // First check the status of the stream - if (!ExpectStatusEq(google::protobuf::util::StatusCode::kOk)) { + if (!ExpectStatusEq(absl::StatusCode::kOk)) { return false; } if (expected != stream_.Finished()) { @@ -78,7 +76,7 @@ unsigned DelimiterToSize(const unsigned char* delimiter) { bool ProtoStreamTester::ValidateDelimiter(const std::string& message) { // First check the status of the stream - if (!ExpectStatusEq(google::protobuf::util::StatusCode::kOk)) { + if (!ExpectStatusEq(absl::StatusCode::kOk)) { return false; } if (message.size() < kDelimiterSize) { @@ -99,7 +97,7 @@ bool ProtoStreamTester::ValidateDelimiter(const std::string& message) { } bool ProtoStreamTester::ExpectStatusEq( - google::protobuf::util::StatusCode error_code) { + absl::StatusCode error_code) { if (error_code != stream_.Status().code()) { ADD_FAILURE() << "ObjectTranslatorTest::ValidateStatus: Status doesn't match " diff --git a/test/proto_stream_tester.h b/test/proto_stream_tester.h index e05e3a2..00b818a 100644 --- a/test/proto_stream_tester.h +++ b/test/proto_stream_tester.h @@ -17,7 +17,6 @@ #include -#include "google/protobuf/stubs/status.h" #include "google/protobuf/text_format.h" #include "google/protobuf/util/message_differencer.h" #include "grpc_transcoding/message_stream.h" @@ -45,7 +44,7 @@ class ProtoStreamTester { bool ExpectNextEq(const std::string& expected_proto_text); bool ExpectNone(); bool ExpectFinishedEq(bool expected); - bool ExpectStatusEq(google::protobuf::util::StatusCode error_code); + bool ExpectStatusEq(absl::StatusCode error_code); private: // Validates the GRPC message delimiter at the beginning @@ -61,7 +60,7 @@ class ProtoStreamTester { template bool ProtoStreamTester::ExpectNextEq(const std::string& expected_proto_text) { // First check the status of the stream - if (!ExpectStatusEq(google::protobuf::util::StatusCode::kOk)) { + if (!ExpectStatusEq(absl::StatusCode::kOk)) { return false; } // Try to get a message @@ -70,7 +69,7 @@ bool ProtoStreamTester::ExpectNextEq(const std::string& expected_proto_text) { ADD_FAILURE() << "ProtoStreamTester::ValidateNext: NextMessage() " "returned false\n"; // Use ExpectStatusEq() to output the status if it's not OK. - ExpectStatusEq(google::protobuf::util::StatusCode::kOk); + ExpectStatusEq(absl::StatusCode::kOk); return false; } // Validate the delimiter if it's expected diff --git a/test/request_message_translator_test.cc b/test/request_message_translator_test.cc index 3a1cb88..9e6ab33 100644 --- a/test/request_message_translator_test.cc +++ b/test/request_message_translator_test.cc @@ -450,7 +450,7 @@ TEST_F(RequestMessageTranslatorTest, UnexpectedScalarBody) { Input().RenderString("", "History"); EXPECT_TRUE(Tester().ExpectStatusEq( - ::google::protobuf::util::StatusCode::kInvalidArgument)); + absl::StatusCode::kInvalidArgument)); } TEST_F(RequestMessageTranslatorTest, UnexpectedList) { @@ -460,7 +460,7 @@ TEST_F(RequestMessageTranslatorTest, UnexpectedList) { Input().StartList("")->EndList(); EXPECT_TRUE(Tester().ExpectStatusEq( - ::google::protobuf::util::StatusCode::kInvalidArgument)); + absl::StatusCode::kInvalidArgument)); } TEST_F(RequestMessageTranslatorTest, IgnoreUnkownFields) { @@ -524,7 +524,7 @@ TEST_F(RequestMessageTranslatorTest, EnumCaseNotMatched) { ->EndObject(); EXPECT_TRUE(Tester().ExpectStatusEq( - ::google::protobuf::util::StatusCode::kInvalidArgument)); + absl::StatusCode::kInvalidArgument)); } TEST_F(RequestMessageTranslatorTest, EnumWithCaseInsensitiveFlag) { diff --git a/test/request_stream_translator_test.cc b/test/request_stream_translator_test.cc index 1b3725a..c1d10ec 100644 --- a/test/request_stream_translator_test.cc +++ b/test/request_stream_translator_test.cc @@ -521,7 +521,7 @@ TEST_F(RequestStreamTranslatorTest, Error1) { SetMessageType("Shelf"); Build(); Input().StartObject(""); - Tester().ExpectStatusEq(google::protobuf::util::StatusCode::kInvalidArgument); + Tester().ExpectStatusEq(absl::StatusCode::kInvalidArgument); } TEST_F(RequestStreamTranslatorTest, Error2) { @@ -530,7 +530,7 @@ TEST_F(RequestStreamTranslatorTest, Error2) { Build(); Input().StartList(""); Input().EndObject(); - Tester().ExpectStatusEq(google::protobuf::util::StatusCode::kInvalidArgument); + Tester().ExpectStatusEq(absl::StatusCode::kInvalidArgument); } TEST_F(RequestStreamTranslatorTest, Error3) { @@ -538,7 +538,7 @@ TEST_F(RequestStreamTranslatorTest, Error3) { SetMessageType("Shelf"); Build(); Input().EndList(); - Tester().ExpectStatusEq(google::protobuf::util::StatusCode::kInvalidArgument); + Tester().ExpectStatusEq(absl::StatusCode::kInvalidArgument); } TEST_F(RequestStreamTranslatorTest, Error4) { @@ -546,7 +546,7 @@ TEST_F(RequestStreamTranslatorTest, Error4) { SetMessageType("Shelf"); Build(); Input().EndObject(); - Tester().ExpectStatusEq(google::protobuf::util::StatusCode::kInvalidArgument); + Tester().ExpectStatusEq(absl::StatusCode::kInvalidArgument); } TEST_F(RequestStreamTranslatorTest, Error5) { @@ -556,7 +556,7 @@ TEST_F(RequestStreamTranslatorTest, Error5) { Input().StartList(""); Input().StartList(""); Input().EndObject(); - Tester().ExpectStatusEq(google::protobuf::util::StatusCode::kInvalidArgument); + Tester().ExpectStatusEq(absl::StatusCode::kInvalidArgument); } TEST_F(RequestStreamTranslatorTest, Error6) { @@ -570,7 +570,7 @@ TEST_F(RequestStreamTranslatorTest, Error6) { Input().EndList(); // google::protobuf::ProtoStreamObjectWriter for some reason accepts EndList() // instead of EndObject(). Should be an error instead. - // Tester().ExpectStatusEq(google::protobuf::util::StatusCode::kInvalidArgument); + // Tester().ExpectStatusEq(absl::StatusCode::kInvalidArgument); Tester().ExpectNextEq(R"( theme : "Russian" )"); } diff --git a/test/request_translator_test_base.cc b/test/request_translator_test_base.cc index e8a72d6..ccefba1 100644 --- a/test/request_translator_test_base.cc +++ b/test/request_translator_test_base.cc @@ -27,7 +27,7 @@ #include "google/api/service.pb.h" #include "google/protobuf/text_format.h" #include "google/protobuf/type.pb.h" -#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/converter/type_info.h" #include "grpc_transcoding/message_stream.h" #include "gtest/gtest.h" #include "test_common.h" diff --git a/test/request_weaver_test.cc b/test/request_weaver_test.cc index 0399088..da2b026 100644 --- a/test/request_weaver_test.cc +++ b/test/request_weaver_test.cc @@ -25,7 +25,7 @@ #include "absl/strings/string_view.h" #include "google/protobuf/type.pb.h" -#include "google/protobuf/util/internal/expecting_objectwriter.h" +#include "google/protobuf/util/converter/expecting_objectwriter.h" #include "grpc_transcoding/status_error_listener.h" #include "gtest/gtest.h" @@ -122,7 +122,7 @@ TEST_F(RequestWeaverTest, PassThrough) { w->EndObject(); w->EndObject(); - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, Level0Bindings) { @@ -153,7 +153,7 @@ TEST_F(RequestWeaverTest, Level0Bindings) { w->RenderString("x", "d"); w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, Level1Bindings) { @@ -199,7 +199,7 @@ TEST_F(RequestWeaverTest, Level1Bindings) { w->EndObject(); // B w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, Level2Bindings) { @@ -265,7 +265,7 @@ TEST_F(RequestWeaverTest, Level2Bindings) { w->EndObject(); // "D" w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, Level2WeaveNewSubTree) { @@ -315,7 +315,7 @@ TEST_F(RequestWeaverTest, Level2WeaveNewSubTree) { w->EndObject(); // "D" w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, MixedBindings) { @@ -358,7 +358,7 @@ TEST_F(RequestWeaverTest, MixedBindings) { w->EndObject(); // "A" w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, MoreMixedBindings) { @@ -414,7 +414,7 @@ TEST_F(RequestWeaverTest, MoreMixedBindings) { w->EndObject(); // "B" w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, CollisionIgnored) { @@ -441,7 +441,7 @@ TEST_F(RequestWeaverTest, CollisionIgnored) { w->EndObject(); // "A" w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, CollisionReportedInvalidBinding) { @@ -471,7 +471,7 @@ TEST_F(RequestWeaverTest, CollisionReportedInvalidBinding) { w->StartObject("A"); w->RenderBool("bool_field", false); EXPECT_EQ(w->Status().code(), - ::google::protobuf::util::StatusCode::kInvalidArgument); + absl::StatusCode::kInvalidArgument); EXPECT_THAT( w->Status().ToString(), HasSubstr( @@ -541,26 +541,26 @@ TEST_F(RequestWeaverTest, CollisionNotReported) { w->StartObject(""); w->StartObject("A"); w->RenderBool("bool_field", true); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->RenderInt32("int32_field", -2); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->RenderUint32("uint32_field", 2); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->RenderInt64("int64_field", -2); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->RenderUint64("uint64_field", 2); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->RenderString("string_field", "a"); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->RenderFloat("float_field", 1.01); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->RenderDouble("double_field", 1.01); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->RenderBytes("bytes_field", "b"); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->StartObject("B"); w->RenderBool("B_bool_field", true); - EXPECT_EQ(w->Status().code(), google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); w->EndObject(); // "B" w->EndObject(); // "A" w->EndObject(); // "" @@ -601,7 +601,7 @@ TEST_F(RequestWeaverTest, CollisionReported) { w->StartObject("A"); w->RenderBool("bool_field", false); EXPECT_EQ(w->Status().code(), - google::protobuf::util::StatusCode::kInvalidArgument); + absl::StatusCode::kInvalidArgument); EXPECT_THAT(w->Status().ToString(), HasSubstr("The binding value \"true\" of the field bool_field is " "conflicting with the value false in the body.")); @@ -682,7 +682,7 @@ TEST_F(RequestWeaverTest, CollisionRepeated) { w->EndObject(); // "A" w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } TEST_F(RequestWeaverTest, IgnoreListTest) { @@ -740,7 +740,7 @@ TEST_F(RequestWeaverTest, IgnoreListTest) { w->EndObject(); // "A" w->EndObject(); // "" - EXPECT_EQ(w->Status().code(), ::google::protobuf::util::StatusCode::kOk); + EXPECT_EQ(w->Status().code(), absl::StatusCode::kOk); } } // namespace diff --git a/test/response_to_json_translator_test.cc b/test/response_to_json_translator_test.cc index 49c4eed..edaf450 100644 --- a/test/response_to_json_translator_test.cc +++ b/test/response_to_json_translator_test.cc @@ -705,7 +705,7 @@ TEST_F(ResponseToJsonTranslatorTest, ErrorInvalidType) { // Call NextMessage() to trigger the error std::string message; EXPECT_FALSE(translator.NextMessage(&message)); - EXPECT_EQ(pbutil::StatusCode::kNotFound, translator.Status().code()); + EXPECT_EQ(absl::StatusCode::kNotFound, translator.Status().code()); } TEST_F(ResponseToJsonTranslatorTest, DirectTest) { diff --git a/test/status_error_listener_test.cc b/test/status_error_listener_test.cc index 3dfdb93..0c16c07 100644 --- a/test/status_error_listener_test.cc +++ b/test/status_error_listener_test.cc @@ -1,7 +1,7 @@ #include "grpc_transcoding/status_error_listener.h" #include "gmock/gmock.h" -#include "google/protobuf/util/internal/object_location_tracker.h" +#include "google/protobuf/util/converter/object_location_tracker.h" #include "gtest/gtest.h" namespace google { @@ -12,8 +12,8 @@ namespace testing { namespace { using ::testing::HasSubstr; -using ::google::protobuf::util::Status; -using ::google::protobuf::util::StatusCode; +using absl::Status; +using absl::StatusCode; namespace pbconv = google::protobuf::util::converter; class StatusErrorListenerTest : public ::testing::Test {