From bb8e0f7b84d50def4a24b2fc994d985c65796852 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 15 Nov 2023 21:24:42 +0100 Subject: [PATCH] Fix unnecessary JSON <-> gRPC headers --- common/CMakeLists.txt | 2 +- common/ZMQPreviewPublisher.cpp | 1 - common/grpcToJson.h | 24 ------------------------ common/jsonToGrpc.h | 24 ------------------------ tests/ZMQPreviewPublisherTest.cpp | 1 - 5 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 common/grpcToJson.h delete mode 100644 common/jsonToGrpc.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 2a72c875..5808c2fe 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -40,7 +40,7 @@ ADD_LIBRARY( CommonFunctions STATIC TestImagePusher.cpp TestImagePusher.h SpotToSave.h NetworkAddressConvert.h NetworkAddressConvert.cpp - grpcToJson.h jsonToGrpc.h to_fixed.h + to_fixed.h DetectorGeometry.cpp DetectorGeometry.h DetectorModuleGeometry.cpp DetectorModuleGeometry.h DetectorSetup.h DetectorSetup.cpp ZeroCopyReturnValue.h Histogram.h DiffractionGeometry.h diff --git a/common/ZMQPreviewPublisher.cpp b/common/ZMQPreviewPublisher.cpp index bf86cda5..768dc03d 100644 --- a/common/ZMQPreviewPublisher.cpp +++ b/common/ZMQPreviewPublisher.cpp @@ -1,7 +1,6 @@ // Copyright (2019-2023) Paul Scherrer Institute #include "ZMQPreviewPublisher.h" -#include "grpcToJson.h" ZMQPreviewPublisher::ZMQPreviewPublisher(ZMQContext& context, const std::string& addr) : socket(context, ZMQSocketType::Pub) { diff --git a/common/grpcToJson.h b/common/grpcToJson.h deleted file mode 100644 index 3614fdb6..00000000 --- a/common/grpcToJson.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (2019-2023) Paul Scherrer Institute - -#ifndef JUNGFRAUJOCH_GRPCTOJSON_H -#define JUNGFRAUJOCH_GRPCTOJSON_H - -#include - -#include "../common/JFJochException.h" - -inline std::string grpcToJson(const google::protobuf::Message &message) { - google::protobuf::util::JsonPrintOptions opts; - opts.always_print_primitive_fields = true; - opts.add_whitespace = true; - opts.always_print_enums_as_ints = false; - opts.preserve_proto_field_names = true; - - std::string s; - auto status = google::protobuf::util::MessageToJsonString(message, &s, opts); - if (!status.ok()) - throw JFJochException(JFJochExceptionCategory::JSON, "Error in generating JSON from ProtoBuf"); - - return s; -} -#endif //JUNGFRAUJOCH_GRPCTOJSON_H diff --git a/common/jsonToGrpc.h b/common/jsonToGrpc.h deleted file mode 100644 index 5e88135b..00000000 --- a/common/jsonToGrpc.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (2019-2023) Paul Scherrer Institute - -#ifndef JUNGFRAUJOCH_JSONTOGRPC_H -#define JUNGFRAUJOCH_JSONTOGRPC_H - -#include - -#include "../common/JFJochException.h" - -template -T jsonToGrpc(const std::string& json) { - T output; - - google::protobuf::util::JsonParseOptions opts; - opts.case_insensitive_enum_parsing = false; - opts.ignore_unknown_fields = false; - - auto status = google::protobuf::util::JsonStringToMessage(json, &output, opts); - if (!status.ok()) - throw JFJochException(JFJochExceptionCategory::JSON, "Error in generating ProtoBuf from JSON"); - return output; -} - -#endif //JUNGFRAUJOCH_JSONTOGRPC_H diff --git a/tests/ZMQPreviewPublisherTest.cpp b/tests/ZMQPreviewPublisherTest.cpp index 2d1e0d19..caab3b47 100644 --- a/tests/ZMQPreviewPublisherTest.cpp +++ b/tests/ZMQPreviewPublisherTest.cpp @@ -2,7 +2,6 @@ #include #include "../common/ZMQPreviewPublisher.h" -#include "../common/jsonToGrpc.h" TEST_CASE("ZMQPreviewPublisher","[ZMQ]") { ZMQContext context;