From 81f1fe9aa82e32f48cf3ea8d6857b0f0921d5efd Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 25 Oct 2025 21:24:56 +0200 Subject: [PATCH 01/16] minor changes --- .github/workflows/lint-and-test.yml | 1 - {config => configs}/dev.yaml | 0 {config => configs}/prod.yaml | 0 sonar-project.properties | 0 tools/load_envs.sh | 2 +- 5 files changed, 1 insertion(+), 2 deletions(-) rename {config => configs}/dev.yaml (100%) rename {config => configs}/prod.yaml (100%) delete mode 100644 sonar-project.properties diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index d3f5a12..e69de29 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -1 +0,0 @@ - diff --git a/config/dev.yaml b/configs/dev.yaml similarity index 100% rename from config/dev.yaml rename to configs/dev.yaml diff --git a/config/prod.yaml b/configs/prod.yaml similarity index 100% rename from config/prod.yaml rename to configs/prod.yaml diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index e69de29..0000000 diff --git a/tools/load_envs.sh b/tools/load_envs.sh index 28eecc9..e713b7b 100644 --- a/tools/load_envs.sh +++ b/tools/load_envs.sh @@ -5,7 +5,7 @@ if [ -f .env ]; then export $(grep -v '^#' .env | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed 's/"//g' | sed "s/'//g" | xargs) fi -CONFIG="config/${ENV}.yaml" +CONFIG="configs/${ENV}.yaml" [ ! -f "$CONFIG" ] && echo "ERROR: Config not found: $CONFIG" >&2 && exit 1 eval "$(yq eval 'to_entries | .[] | "export " + .key + "='\''" + (.value | tostring) + "'\''"' "$CONFIG")" From f9249bb07955b640f3456b03b20f1161a5006551 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 25 Oct 2025 22:04:44 +0200 Subject: [PATCH 02/16] implemented algorithms text normalization algorithm with TextNormalization, WhitespaceNormalization, RepetitionNormalization, InvisibleCharacterNormalization functions. Implemented leetspeak normalization with LeetspeakNormalization and IsPrimarlyCyrillic functions. Implemented word checker with Tokenization and Hash-Trie building with further checking with Wordchecking and Tokenize functions. Currently they are NOT adapted to the moderation-service environment and require further adjustments and combination with proto and with the database --- .gitignore | 3 + CMakeLists.txt | 8 + src/moderationservice/main.cpp | 2 +- .../service/leetspeak_normalization.cpp | 132 +++++++++++++++ .../service/leetspeak_normalization.hpp | 13 ++ .../service/text_normalization.cpp | 159 ++++++++++++++++++ .../service/text_normalization.hpp | 14 ++ .../service/word_checker.cpp | 64 +++++++ .../service/word_checker.hpp | 16 ++ 9 files changed, 410 insertions(+), 1 deletion(-) create mode 100644 src/moderationservice/service/leetspeak_normalization.cpp create mode 100644 src/moderationservice/service/leetspeak_normalization.hpp create mode 100644 src/moderationservice/service/text_normalization.cpp create mode 100644 src/moderationservice/service/text_normalization.hpp create mode 100644 src/moderationservice/service/word_checker.cpp create mode 100644 src/moderationservice/service/word_checker.hpp diff --git a/.gitignore b/.gitignore index 07b9aeb..7c1162d 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ *.dll *.so *.log + +external/ +external/tsl-hat-trie/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ff38d6f..4f02e18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(moderation-service) find_package(Protobuf REQUIRED) find_package(gRPC REQUIRED) +find_package(ICU REQUIRED COMPONENTS uc i18n) #find_package(utf8_range REQUIRED) # set necessary variables for genproto lib target @@ -33,16 +34,23 @@ add_executable(${PROJECT_NAME} src/moderationservice/main.cpp src/moderationservice/server/server.cpp src/moderationservice/service/service.cpp + src/moderationservice/service/text_normalization.cpp + src/moderationservice/service/leetspeak_normalization.cpp + src/moderationservice/service/word_checker.cpp ) target_link_libraries(${PROJECT_NAME} PRIVATE ${GENPROTO_LIB} gRPC::grpc++_reflection + ICU::uc + ICU::i18n ) #link header files target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include + PRIVATE + ${PROJECT_SOURCE_DIR}/external/tsl-hat-trie/include ) diff --git a/src/moderationservice/main.cpp b/src/moderationservice/main.cpp index 34b83ba..df51107 100644 --- a/src/moderationservice/main.cpp +++ b/src/moderationservice/main.cpp @@ -9,7 +9,7 @@ int main() { Config config = Config::New(); std::shared_ptr mService = std::make_shared(); std::unique_ptr server = std::make_unique(config.host + ":" + config.port, mService, "ModerationService"); - + server->Start(); } catch (const std::exception &e) diff --git a/src/moderationservice/service/leetspeak_normalization.cpp b/src/moderationservice/service/leetspeak_normalization.cpp new file mode 100644 index 0000000..034dcb8 --- /dev/null +++ b/src/moderationservice/service/leetspeak_normalization.cpp @@ -0,0 +1,132 @@ +#include "leetspeak_normalization.hpp" + +namespace LeetspeakNormalization { + + std::string LeetspeakNormalization(const std::string& textN, bool isCyrillic) + { + icu::UnicodeString text = icu::UnicodeString::fromUTF8(textN); + if (text.length() == 0) { + text = icu::UnicodeString(textN.c_str(), textN.length(), "UTF-8"); + } + + icu::UnicodeString result; + + static const std::unordered_map leetMapLatin = { + { U'0', U'o' }, { U'!', U'i' }, + { U'1', U'i' }, { U'%', U'o' }, + { U'3', U'e' }, { U'^', U'a' }, + { U'4', U'a' }, { U'[', U'c' }, + { U'5', U's' }, { U'&', U'a' }, + { U'6', U'g' }, { U'$', U's' }, + { U'7', U't' }, { U'8', U'b' }, + { U'9', U'g' }, { U'@', U'a' }, + { U'*', U'a' }, { U'#', U'h' }, + { U'+', U't' }, { U'|', U'i' }, + { U'/', U'l' }, { U')', U'd' }, + { U'~', U'n' }, { U'(', U'c' }, + { U'{', U'c' }, { U'<', U'c' }, + { U'>', U'd' }, + + }; + static const std::unordered_map leetMapCyrillic = { + { U'0', U'о' }, + { U'1', U'і' }, + { U'3', U'з' }, + { U'4', U'ч' }, + { U'5', U'ѕ' }, + { U'6', U'б' }, + { U'8', U'в' }, + { U'9', U'я' }, + { U'@', U'а' }, + { U'$', U'з' }, + { U'|', U'і' }, + { U'/', U'г' } + }; + static const std::unordered_map homoglyphMap = { + + { U'a', U'а' }, + { U'e', U'е' }, + { U'o', U'о' }, + { U'p', U'р' }, + { U'c', U'с' }, + { U'y', U'у' }, + { U'x', U'х' }, + { U'k', U'к' }, + { U'b', U'в' }, + { U'h', U'н' }, + { U'm', U'м' }, + { U't', U'т' } + }; + + for (int32_t i = 0; i < text.length(); i++) + { + UChar32 c = text.char32At(i); + UChar32 normalized = c; + + if (isCyrillic) + { + auto homoglyphText = homoglyphMap.find(c); + if (homoglyphText != homoglyphMap.end()) + { + normalized = homoglyphText->second; + } + + else { + auto leetedTextCyrillic = leetMapCyrillic.find(c); + if (leetedTextCyrillic != leetMapCyrillic.end()) + { + normalized = leetedTextCyrillic->second; + } + } + } + else { + auto leetedText = leetMapLatin.find(c); + if (leetedText != leetMapLatin.end()) { + normalized = leetedText->second; + } + } + + + result.append(normalized); + if (U16_IS_LEAD(text.charAt(i))) { + i++; + } + } + + std::string output; + result.toUTF8String(output); + return output; + + } + + bool IsPrimarilyCyrillic(const std::string& textN) + { + icu::UnicodeString text = icu::UnicodeString::fromUTF8(textN); + + if (text.length() == 0) { + text = icu::UnicodeString(textN.c_str(), textN.length(), "UTF-8"); + } + + int cyrillicCount = 0; + int latinCount = 0; + + for (int32_t i = 0; i < text.length(); i++) { + UChar32 c = text.char32At(i); + + // Cyrillic range: U+0400 to U+04FF + if (c >= 0x0400 && c <= 0x04FF) { + cyrillicCount++; + } + // Latin range + else if ((c >= 0x0041 && c <= 0x005A) || + (c >= 0x0061 && c <= 0x007A)) { + latinCount++; + } + + if (U16_IS_LEAD(text.charAt(i))) i++; + } + + return cyrillicCount > latinCount; + } + +} //namespace LeetspeakNormalization diff --git a/src/moderationservice/service/leetspeak_normalization.hpp b/src/moderationservice/service/leetspeak_normalization.hpp new file mode 100644 index 0000000..31ddcaf --- /dev/null +++ b/src/moderationservice/service/leetspeak_normalization.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include +#include +#include +#include "unicode/unistr.h" + +namespace LeetspeakNormalization { + + std::string LeetspeakNormalization(const std::string& textN, bool isCyrillic); + bool IsPrimarilyCyrillic(const std::string& textN); + +} //namespace LeetspeakNormalization diff --git a/src/moderationservice/service/text_normalization.cpp b/src/moderationservice/service/text_normalization.cpp new file mode 100644 index 0000000..0b0dec6 --- /dev/null +++ b/src/moderationservice/service/text_normalization.cpp @@ -0,0 +1,159 @@ +#include "text_normalization.hpp" + +namespace TextNormalization { + + std::string TextNormalization(const std::string& textN) + { + icu::UnicodeString text = icu::UnicodeString::fromUTF8(textN); + + UErrorCode status = U_ZERO_ERROR; + const icu::Normalizer2* normalizer = icu::Normalizer2::getNFCInstance(status); + + if (U_FAILURE(status)) + { + std::cerr << "Error getting normalizer" << std::endl; + return ""; + } + + if (text.length() == 0) { + text = icu::UnicodeString(textN.c_str(), textN.length(), "UTF-8"); + } + + icu::UnicodeString normalized = normalizer->normalize(text, status); + + if (U_FAILURE(status)) + { + std::cerr << "Error normalizing" << std::endl; + return ""; + } + + icu::UnicodeString result_ = normalized.toLower(); + result_.trim(); + + std::string result; + + result_.toUTF8String(result); + + return result; + } + + std::string WhitespaceNormalization(const std::string& textN) + { + icu::UnicodeString text = icu::UnicodeString::fromUTF8(textN); + icu::UnicodeString result; + + if (text.length() == 0) { + text = icu::UnicodeString(textN.c_str(), textN.length(), "UTF-8"); + } + + bool prev_space = false; + + for (int32_t i = 0; i < text.length(); i++) + { + UChar32 c = text.char32At(i); + + if (u_isWhitespace(c)) { + if (!prev_space && result.length() > 0) { + result.append((UChar32)' '); + prev_space = true; + + } + } + else { + result.append(c); + prev_space = false; + } + if (U16_IS_LEAD(text.charAt(i))) { + i++; + } + } + std::string output; + result.toUTF8String(output); + return output; + } + + std::string RepetitionNormalization(const std::string& textN) + { + icu::UnicodeString text = icu::UnicodeString::fromUTF8(textN); + icu::UnicodeString result; + + UChar32 prevChar = 0; + int repeatCount = 0; + + if (text.length() == 0) { + text = icu::UnicodeString(textN.c_str(), textN.length(), "UTF-8"); + } + + for (int32_t i = 0; i < text.length(); i++) + { + UChar32 c = text.char32At(i); + + if (c == prevChar) + { + repeatCount++; + + if (repeatCount < 2) + { + result.append(c); + } + } + else + { + result.append(c); + prevChar = c; + repeatCount = 0; + } + + if (U16_IS_LEAD(text.charAt(i))) i++; + + } + + std::string output; + result.toUTF8String(output); + return output; + } + + std::string InvisibleCharacterNormalization(const std::string& textN) + { + icu::UnicodeString text = icu::UnicodeString::fromUTF8(textN); + if (text.length() == 0) { + text = icu::UnicodeString(textN.c_str(), textN.length(), "UTF-8"); + } + icu::UnicodeString result; + + for (int32_t i = 0; i < text.length(); i++) { + UChar32 c = text.char32At(i); + + // Skip zero-width and format characters + if (c == 0x200B || // Zero Width Space + c == 0x200C || // Zero Width Non-Joiner + c == 0x200D || // Zero Width Joiner + c == 0x200E || // Left-to-Right Mark + c == 0x200F || // Right-to-Left Mark + c == 0xFEFF || // Zero Width No-Break Space (BOM) + c == 0x2060 || // Word Joiner + c == 0x2061 || // Function Application + c == 0x2062 || // Invisible Times + c == 0x2063 || // Invisible Separator + c == 0x2064 || // Invisible Plus + c == 0x00AD || // Soft Hyphen + c == 0x034F || // Combining Grapheme Joiner + c == 0x061C || // Arabic Letter Mark + c == 0x180E || // Mongolian Vowel Separator + c == 0x2028 || // Line Separator + c == 0x2029 || // Paragraph Separator + (c >= 0x202A && c <= 0x202E)) { // Bidirectional markers + continue; + } + + result.append(c); + + if (U16_IS_LEAD(text.charAt(i))) i++; + } + + std::string output; + result.toUTF8String(output); + return output; + } + +} //namespace TextNormalization diff --git a/src/moderationservice/service/text_normalization.hpp b/src/moderationservice/service/text_normalization.hpp new file mode 100644 index 0000000..aa34891 --- /dev/null +++ b/src/moderationservice/service/text_normalization.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include +#include "unicode/normalizer2.h" + +namespace TextNormalization { + + std::string TextNormalization(const std::string& textN); + std::string WhitespaceNormalization(const std::string& textN); + std::string RepetitionNormalization(const std::string& textN); + std::string InvisibleCharacterNormalization(const std::string& textN); +} //namespace TextNormalization diff --git a/src/moderationservice/service/word_checker.cpp b/src/moderationservice/service/word_checker.cpp new file mode 100644 index 0000000..822e603 --- /dev/null +++ b/src/moderationservice/service/word_checker.cpp @@ -0,0 +1,64 @@ +#include "word_checker.hpp" + +namespace WordChecker { + std::vector Tokenize(const std::string& textN) + { + std::vector tokens; + icu::UnicodeString text = icu::UnicodeString::fromUTF8(textN); + if (text.length() == 0) { + text = icu::UnicodeString(textN.c_str(), textN.length(), "UTF-8"); + } + std::string currentWord; + + for (int32_t i = 0; i < text.length(); i++) + { + UChar32 c = text.char32At(i); + + if (u_isalnum(c)) { + icu::UnicodeString charStr(c); + std::string utf8char; + charStr.toUTF8String(utf8char); + currentWord += utf8char; + } + else { + if (!currentWord.empty()) { + tokens.push_back(currentWord); + currentWord.clear(); + } + } + + if (U16_IS_LEAD(text[i]) && i + 1 < text.length()) { + i++; + } + } + + if (!currentWord.empty()) { + tokens.push_back(currentWord); + } + + return tokens; + } + + bool TrieBuildingAndWordChecking(const std::vector < std::string> &textN) + { + tsl::htrie_set words; + + unsigned int forbiddenWordCount = 0; + + words.insert("Gay"); + words.insert("еблан"); + words.insert("шутка"); + + for (int i = 0; i < textN.size(); i++) + { + if (words.find(textN[i]) != words.end()) + { + forbiddenWordCount++; + } + + } + + return (forbiddenWordCount > 3); + } + +} //namespace WordChecker diff --git a/src/moderationservice/service/word_checker.hpp b/src/moderationservice/service/word_checker.hpp new file mode 100644 index 0000000..794f198 --- /dev/null +++ b/src/moderationservice/service/word_checker.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace WordChecker { + + std::vector Tokenize(const std::string& textN); + bool WordChecking(const std::vector < std::string> &textN); + +} //namespace WordChecker From bef56bf1db450e6d96eb0eaa1a144982f8e3c87a Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 25 Oct 2025 22:32:13 +0200 Subject: [PATCH 03/16] Text processor implementation added united namespace TextProcessor for optimal usage of all new functions. Implemented the text processing in the service. The attempt was successful --- CMakeLists.txt | 1 + src/moderationservice/service/service.cpp | 20 ++++++++++++++---- .../service/text_processor.cpp | 21 +++++++++++++++++++ .../service/text_processor.hpp | 11 ++++++++++ .../service/word_checker.cpp | 4 ++-- 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 src/moderationservice/service/text_processor.cpp create mode 100644 src/moderationservice/service/text_processor.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f02e18..8d8812a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ add_executable(${PROJECT_NAME} src/moderationservice/service/text_normalization.cpp src/moderationservice/service/leetspeak_normalization.cpp src/moderationservice/service/word_checker.cpp + src/moderationservice/service/text_processor.cpp ) target_link_libraries(${PROJECT_NAME} diff --git a/src/moderationservice/service/service.cpp b/src/moderationservice/service/service.cpp index ca65e44..805a425 100644 --- a/src/moderationservice/service/service.cpp +++ b/src/moderationservice/service/service.cpp @@ -1,10 +1,11 @@ #include "service.hpp" +#include "text_processor.hpp" ModerationService::ModerationService() { // Initialize mock data moderation::ModerateObjectRequest mod1; mod1.set_id(1); - mod1.set_text("Inappropriate content"); + mod1.set_text("Very b@d w0rd! Please m0d3rate. This is a t3st. You are gay. Super gay! Super super gay!"); moderation::ModerateObjectResponse mod2; mod2.set_success(true); @@ -18,12 +19,23 @@ Status ModerationService::ModerateObject(grpc::ServerContext* context, const mod std::lock_guard Lock(this->mutex_); int64_t id = request->id(); + bool testingWordModeration = TextProcessor::TextProcessing(request->text()); + if(this->moderations_.find(id) == this->moderations_.end()) { return Status(grpc::StatusCode::NOT_FOUND, "Not found"); } moderation::ModerateObjectRequest moderation = this->moderations_[id]; - response->set_success(true); - - return Status::OK; + if(!testingWordModeration) + { + response->set_success(false); + std::cout << "Moderation check passed for ID: " << id << std::endl; + return Status::OK; + } + else{ + response->set_success(true); + std::cout << "Text flagged for moderation: " << request->text() << std::endl; + std::cout << "Moderation check failed for ID: " << id << std::endl; + return Status::OK; + } } diff --git a/src/moderationservice/service/text_processor.cpp b/src/moderationservice/service/text_processor.cpp new file mode 100644 index 0000000..a4fdc20 --- /dev/null +++ b/src/moderationservice/service/text_processor.cpp @@ -0,0 +1,21 @@ +#include "text_processor.hpp" + +namespace TextProcessor { + + bool TextProcessing(const std::string& textN) + { + std::string text = TextNormalization::TextNormalization(textN); + text = TextNormalization::InvisibleCharacterNormalization(text); + text = TextNormalization::WhitespaceNormalization(text); + text = TextNormalization::RepetitionNormalization(text); + + bool AlphabetOrientation = LeetspeakNormalization::IsPrimarilyCyrillic(text); + text = LeetspeakNormalization::LeetspeakNormalization(text, AlphabetOrientation); + + std::vector wordTokens = WordChecker::Tokenize(text); + bool bannedWordsFound = WordChecker::WordChecking(wordTokens); + + return bannedWordsFound; + } + +} //namespace TextProcessor \ No newline at end of file diff --git a/src/moderationservice/service/text_processor.hpp b/src/moderationservice/service/text_processor.hpp new file mode 100644 index 0000000..776c999 --- /dev/null +++ b/src/moderationservice/service/text_processor.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "leetspeak_normalization.hpp" +#include "text_normalization.hpp" +#include "word_checker.hpp" + +namespace TextProcessor { + + bool TextProcessing(const std::string& textN); + +} //namespace TextProcessor diff --git a/src/moderationservice/service/word_checker.cpp b/src/moderationservice/service/word_checker.cpp index 822e603..f9c4c6f 100644 --- a/src/moderationservice/service/word_checker.cpp +++ b/src/moderationservice/service/word_checker.cpp @@ -39,13 +39,13 @@ namespace WordChecker { return tokens; } - bool TrieBuildingAndWordChecking(const std::vector < std::string> &textN) + bool WordChecking(const std::vector < std::string> &textN) { tsl::htrie_set words; unsigned int forbiddenWordCount = 0; - words.insert("Gay"); + words.insert("gay"); words.insert("еблан"); words.insert("шутка"); From 5df361752ac337b910ea963a303ff91690fa7d41 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 25 Oct 2025 22:43:48 +0200 Subject: [PATCH 04/16] Service bug fix --- src/moderationservice/service/service.cpp | 33 +++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/moderationservice/service/service.cpp b/src/moderationservice/service/service.cpp index 805a425..c3ac48f 100644 --- a/src/moderationservice/service/service.cpp +++ b/src/moderationservice/service/service.cpp @@ -18,24 +18,23 @@ Status ModerationService::ModerateObject(grpc::ServerContext* context, const mod { std::lock_guard Lock(this->mutex_); - int64_t id = request->id(); - bool testingWordModeration = TextProcessor::TextProcessing(request->text()); - - if(this->moderations_.find(id) == this->moderations_.end()) { - return Status(grpc::StatusCode::NOT_FOUND, "Not found"); - } - - moderation::ModerateObjectRequest moderation = this->moderations_[id]; - if(!testingWordModeration) - { - response->set_success(false); - std::cout << "Moderation check passed for ID: " << id << std::endl; + try { + bool testingWordModeration = TextProcessor::TextProcessing(request->text()); + if(!testingWordModeration) + { + response->set_success(false); + std::cout << "Moderation check passed for ID: " << id << std::endl; + } + else{ + response->set_success(true); + std::cout << "Text flagged for moderation: " << request->text() << std::endl; + std::cout << "Moderation check failed for ID: " << id << std::endl; + } return Status::OK; } - else{ - response->set_success(true); - std::cout << "Text flagged for moderation: " << request->text() << std::endl; - std::cout << "Moderation check failed for ID: " << id << std::endl; - return Status::OK; + catch (const std::exception &e) + { + std::cerr << "[Service] ERROR: " << e.what() << std::endl; + return Status(grpc::StatusCode::INTERNAL, e.what()); } } From cc9059b42accdd76884c7260f872884f3529de0b Mon Sep 17 00:00:00 2001 From: Samuel Date: Sun, 26 Oct 2025 13:04:46 +0100 Subject: [PATCH 05/16] maintenance adjustments added model folder with constants used by the algorithm, cleaned up functions --- CMakeLists.txt | 3 + src/moderationservice/model/constants.cpp | 64 +++++++++++++++++++ src/moderationservice/model/constants.hpp | 25 ++++++++ .../service/leetspeak_normalization.cpp | 61 +++--------------- src/moderationservice/service/service.cpp | 16 ++--- .../service/word_checker.cpp | 12 ++-- 6 files changed, 110 insertions(+), 71 deletions(-) create mode 100644 src/moderationservice/model/constants.cpp create mode 100644 src/moderationservice/model/constants.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d8812a..ae754f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ add_executable(${PROJECT_NAME} src/moderationservice/service/leetspeak_normalization.cpp src/moderationservice/service/word_checker.cpp src/moderationservice/service/text_processor.cpp + src/moderationservice/model/constants.cpp ) target_link_libraries(${PROJECT_NAME} @@ -53,5 +54,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include PRIVATE + ${PROJECT_SOURCE_DIR}/src/moderationservice/service + ${PROJECT_SOURCE_DIR}/src/moderationservice/model ${PROJECT_SOURCE_DIR}/external/tsl-hat-trie/include ) diff --git a/src/moderationservice/model/constants.cpp b/src/moderationservice/model/constants.cpp new file mode 100644 index 0000000..74cf84c --- /dev/null +++ b/src/moderationservice/model/constants.cpp @@ -0,0 +1,64 @@ +#include "constants.hpp" + + +namespace TextProcessingConstants +{ + namespace LeetspeakMaps { + const std::unordered_map leetMapLatin = { + { U'0', U'o' }, { U'!', U'i' }, + { U'1', U'i' }, { U'%', U'o' }, + { U'3', U'e' }, { U'^', U'a' }, + { U'4', U'a' }, { U'[', U'c' }, + { U'5', U's' }, { U'&', U'a' }, + { U'6', U'g' }, { U'$', U's' }, + { U'7', U't' }, { U'8', U'b' }, + { U'9', U'g' }, { U'@', U'a' }, + { U'*', U'a' }, { U'#', U'h' }, + { U'+', U't' }, { U'|', U'i' }, + { U'/', U'l' }, { U')', U'd' }, + { U'~', U'n' }, { U'(', U'c' }, + { U'{', U'c' }, { U'<', U'c' }, + { U'>', U'd' } + }; + const std::unordered_map leetMapCyrillic = { + { U'0', U'о' }, + { U'1', U'і' }, + { U'3', U'з' }, + { U'4', U'ч' }, + { U'5', U'ѕ' }, + { U'6', U'б' }, + { U'8', U'в' }, + { U'9', U'я' }, + { U'@', U'а' }, + { U'$', U'з' }, + { U'|', U'і' }, + { U'/', U'г' } + }; + const std::unordered_map homoglyphMap = { + + { U'a', U'а' }, + { U'e', U'е' }, + { U'o', U'о' }, + { U'p', U'р' }, + { U'c', U'с' }, + { U'y', U'у' }, + { U'x', U'х' }, + { U'k', U'к' }, + { U'b', U'в' }, + { U'h', U'н' }, + { U'm', U'м' }, + { U't', U'т' } + }; + } + namespace HashTrieMaps { + tsl::htrie_set forbiddenWords; + + void InitializeForbiddenWords() { + forbiddenWords.insert("gay"); + forbiddenWords.insert("еблан"); + forbiddenWords.insert("шутка"); + } + } + + +} //namespace TextProcessingConstants \ No newline at end of file diff --git a/src/moderationservice/model/constants.hpp b/src/moderationservice/model/constants.hpp new file mode 100644 index 0000000..6b11346 --- /dev/null +++ b/src/moderationservice/model/constants.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include "unicode/unistr.h" +#include +#include + + +namespace TextProcessingConstants{ + namespace LeetspeakMaps { + + extern const std::unordered_map leetMapLatin; + extern const std::unordered_map leetMapCyrillic; + extern const std::unordered_map homoglyphMap; + + } //namespace LeetspeakMaps + namespace HashTrieMaps { + + extern tsl::htrie_set forbiddenWords; + void InitializeForbiddenWords(); + + } //namespace HashTrieMaps +} //namespace TextProcessingConstants diff --git a/src/moderationservice/service/leetspeak_normalization.cpp b/src/moderationservice/service/leetspeak_normalization.cpp index 034dcb8..b079c72 100644 --- a/src/moderationservice/service/leetspeak_normalization.cpp +++ b/src/moderationservice/service/leetspeak_normalization.cpp @@ -1,7 +1,12 @@ #include "leetspeak_normalization.hpp" +#include "constants.hpp" namespace LeetspeakNormalization { + const auto& latinMap = TextProcessingConstants::LeetspeakMaps::leetMapLatin; + const auto& cyrillicMap = TextProcessingConstants::LeetspeakMaps::leetMapCyrillic; + const auto& homoglyphMap = TextProcessingConstants::LeetspeakMaps::homoglyphMap; + std::string LeetspeakNormalization(const std::string& textN, bool isCyrillic) { icu::UnicodeString text = icu::UnicodeString::fromUTF8(textN); @@ -11,53 +16,6 @@ namespace LeetspeakNormalization { icu::UnicodeString result; - static const std::unordered_map leetMapLatin = { - { U'0', U'o' }, { U'!', U'i' }, - { U'1', U'i' }, { U'%', U'o' }, - { U'3', U'e' }, { U'^', U'a' }, - { U'4', U'a' }, { U'[', U'c' }, - { U'5', U's' }, { U'&', U'a' }, - { U'6', U'g' }, { U'$', U's' }, - { U'7', U't' }, { U'8', U'b' }, - { U'9', U'g' }, { U'@', U'a' }, - { U'*', U'a' }, { U'#', U'h' }, - { U'+', U't' }, { U'|', U'i' }, - { U'/', U'l' }, { U')', U'd' }, - { U'~', U'n' }, { U'(', U'c' }, - { U'{', U'c' }, { U'<', U'c' }, - { U'>', U'd' }, - - }; - static const std::unordered_map leetMapCyrillic = { - { U'0', U'о' }, - { U'1', U'і' }, - { U'3', U'з' }, - { U'4', U'ч' }, - { U'5', U'ѕ' }, - { U'6', U'б' }, - { U'8', U'в' }, - { U'9', U'я' }, - { U'@', U'а' }, - { U'$', U'з' }, - { U'|', U'і' }, - { U'/', U'г' } - }; - static const std::unordered_map homoglyphMap = { - - { U'a', U'а' }, - { U'e', U'е' }, - { U'o', U'о' }, - { U'p', U'р' }, - { U'c', U'с' }, - { U'y', U'у' }, - { U'x', U'х' }, - { U'k', U'к' }, - { U'b', U'в' }, - { U'h', U'н' }, - { U'm', U'м' }, - { U't', U'т' } - }; - for (int32_t i = 0; i < text.length(); i++) { UChar32 c = text.char32At(i); @@ -72,16 +30,16 @@ namespace LeetspeakNormalization { } else { - auto leetedTextCyrillic = leetMapCyrillic.find(c); - if (leetedTextCyrillic != leetMapCyrillic.end()) + auto leetedTextCyrillic = cyrillicMap.find(c); + if (leetedTextCyrillic != cyrillicMap.end()) { normalized = leetedTextCyrillic->second; } } } else { - auto leetedText = leetMapLatin.find(c); - if (leetedText != leetMapLatin.end()) { + auto leetedText = latinMap.find(c); + if (leetedText != latinMap.end()) { normalized = leetedText->second; } } @@ -96,7 +54,6 @@ namespace LeetspeakNormalization { std::string output; result.toUTF8String(output); return output; - } bool IsPrimarilyCyrillic(const std::string& textN) diff --git a/src/moderationservice/service/service.cpp b/src/moderationservice/service/service.cpp index c3ac48f..6558059 100644 --- a/src/moderationservice/service/service.cpp +++ b/src/moderationservice/service/service.cpp @@ -1,17 +1,9 @@ #include "service.hpp" #include "text_processor.hpp" +#include "constants.hpp" ModerationService::ModerationService() { - // Initialize mock data - moderation::ModerateObjectRequest mod1; - mod1.set_id(1); - mod1.set_text("Very b@d w0rd! Please m0d3rate. This is a t3st. You are gay. Super gay! Super super gay!"); - - moderation::ModerateObjectResponse mod2; - mod2.set_success(true); - - moderations_[mod1.id()] = mod1; - + TextProcessingConstants::HashTrieMaps::InitializeForbiddenWords(); } Status ModerationService::ModerateObject(grpc::ServerContext* context, const moderation::ModerateObjectRequest* request, moderation::ModerateObjectResponse* response) @@ -23,12 +15,12 @@ Status ModerationService::ModerateObject(grpc::ServerContext* context, const mod if(!testingWordModeration) { response->set_success(false); - std::cout << "Moderation check passed for ID: " << id << std::endl; + std::cout << "Moderation check passed for ID: " << request->id() << std::endl; } else{ response->set_success(true); std::cout << "Text flagged for moderation: " << request->text() << std::endl; - std::cout << "Moderation check failed for ID: " << id << std::endl; + std::cout << "Moderation check failed for ID: " << request->id() << std::endl; } return Status::OK; } diff --git a/src/moderationservice/service/word_checker.cpp b/src/moderationservice/service/word_checker.cpp index f9c4c6f..111fbb7 100644 --- a/src/moderationservice/service/word_checker.cpp +++ b/src/moderationservice/service/word_checker.cpp @@ -1,6 +1,10 @@ #include "word_checker.hpp" +#include "constants.hpp" namespace WordChecker { + + const auto& forbiddenWords = TextProcessingConstants::HashTrieMaps::forbiddenWords; + std::vector Tokenize(const std::string& textN) { std::vector tokens; @@ -38,20 +42,14 @@ namespace WordChecker { return tokens; } - bool WordChecking(const std::vector < std::string> &textN) { - tsl::htrie_set words; unsigned int forbiddenWordCount = 0; - words.insert("gay"); - words.insert("еблан"); - words.insert("шутка"); - for (int i = 0; i < textN.size(); i++) { - if (words.find(textN[i]) != words.end()) + if (forbiddenWords.find(textN[i]) != forbiddenWords.end()) { forbiddenWordCount++; } From 08379badbaf0bb5d340232072f037d453225368b Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 27 Oct 2025 21:52:22 +0100 Subject: [PATCH 06/16] package manager implemented --- CMakeLists.txt | 57 +++++++++++++++++++---- src/moderationservice/model/constants.cpp | 5 +- tools/common.just | 24 ++++++---- 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae754f1..22bdaaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,49 @@ cmake_minimum_required(VERSION 3.20) project(moderation-service) -find_package(Protobuf REQUIRED) -find_package(gRPC REQUIRED) -find_package(ICU REQUIRED COMPONENTS uc i18n) -#find_package(utf8_range REQUIRED) +set(CPM_DOWNLOAD_VERSION 0.40.2) +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) + message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") + file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} + ) +endif() + +include(${CPM_DOWNLOAD_LOCATION}) + +CPMAddPackage( + NAME gRPC + GITHUB_REPOSITORY grpc/grpc + GIT_TAG v1.51.1 + OPTIONS + "gRPC_BUILD_TESTS OFF" + "gRPC_BUILD_CODEGEN ON" + "gRPC_BUILD_CSHARP_EXT OFF" +) + +CPMAddPackage( + NAME ICU + GITHUB_REPOSITORY unicode-org/icu + GIT_TAG release-74-2 + SOURCE_SUBDIR icu4c/source + OPTIONS + "ICU_BUILD_TESTS OFF" +) + +CPMAddPackage( + NAME tsl-hat-trie + GITHUB_REPOSITORY Tessil/hat-trie + VERSION 0.6.0 +) # set necessary variables for genproto lib target set(GENPROTO_LIB "genproto_lib") @@ -18,7 +57,7 @@ add_library(${GENPROTO_LIB} ${PROTO_SRC} ${PROTO_HDR}) target_link_libraries(${GENPROTO_LIB} PUBLIC - gRPC::grpc++ + grpc++ protobuf::libprotobuf #utf8_range::utf8_range #utf8_range::utf8_validity @@ -44,9 +83,10 @@ add_executable(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE ${GENPROTO_LIB} - gRPC::grpc++_reflection - ICU::uc - ICU::i18n + grpc++_reflection + uc + i18n + tsl::hat_trie ) #link header files @@ -56,5 +96,4 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src/moderationservice/service ${PROJECT_SOURCE_DIR}/src/moderationservice/model - ${PROJECT_SOURCE_DIR}/external/tsl-hat-trie/include ) diff --git a/src/moderationservice/model/constants.cpp b/src/moderationservice/model/constants.cpp index 74cf84c..0d70dfb 100644 --- a/src/moderationservice/model/constants.cpp +++ b/src/moderationservice/model/constants.cpp @@ -1,6 +1,5 @@ #include "constants.hpp" - namespace TextProcessingConstants { namespace LeetspeakMaps { @@ -59,6 +58,4 @@ namespace TextProcessingConstants forbiddenWords.insert("шутка"); } } - - -} //namespace TextProcessingConstants \ No newline at end of file +} //namespace TextProcessingConstants diff --git a/tools/common.just b/tools/common.just index c09bf2f..e091f2f 100644 --- a/tools/common.just +++ b/tools/common.just @@ -22,18 +22,26 @@ gen-stubs: fetch-proto update: gen-stubs clean build: - mkdir -p build - cd build && cmake .. && cmake --build . - + @cmake -S . -B build -DCMAKE_BUILD_TYPE=Release 2>/dev/null || true + @cmake --build build -j$(nproc) + rebuild: - rm -rf build - mkdir -p build - cd build && cmake .. && cmake --build . - + #!/usr/bin/env bash + if [ -d "build" ]; then + chmod -R u+w build 2>/dev/null || true + rm -rf build + fi + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + cmake --build build -j$(nproc) + +reconfigure: + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + cmake --build build -j$(nproc) --clean-first run: build ENV=dev tools/load_envs.sh ./build/moderation-service -run-new: rebuild +dev: + @cmake --build build -j$(nproc) ENV=dev tools/load_envs.sh ./build/moderation-service From 25cc18ccc214ea606d5a932dc761e531d21d12b6 Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 28 Oct 2025 15:40:10 +0100 Subject: [PATCH 07/16] icu issues fix --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22bdaaf..ca0932a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,8 +59,6 @@ target_link_libraries(${GENPROTO_LIB} PUBLIC grpc++ protobuf::libprotobuf - #utf8_range::utf8_range - #utf8_range::utf8_validity ) target_include_directories(${GENPROTO_LIB} @@ -84,8 +82,11 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${GENPROTO_LIB} grpc++_reflection - uc - i18n + icuuc + icui18n + icudata + icuio + icutu tsl::hat_trie ) From f94995bfbd35c891b98bfbf67862e1287b7603a8 Mon Sep 17 00:00:00 2001 From: Andrey Kataev Date: Thu, 30 Oct 2025 13:26:32 +0300 Subject: [PATCH 08/16] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca0932a..d5eb2e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ include(${CPM_DOWNLOAD_LOCATION}) CPMAddPackage( NAME gRPC GITHUB_REPOSITORY grpc/grpc - GIT_TAG v1.51.1 + GIT_TAG v1.76.0 OPTIONS "gRPC_BUILD_TESTS OFF" "gRPC_BUILD_CODEGEN ON" @@ -33,7 +33,7 @@ CPMAddPackage( CPMAddPackage( NAME ICU GITHUB_REPOSITORY unicode-org/icu - GIT_TAG release-74-2 + GIT_TAG release-74-2 SOURCE_SUBDIR icu4c/source OPTIONS "ICU_BUILD_TESTS OFF" From b3b332da4a642c9cf1257a0ea57880e722cb6b9b Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 31 Oct 2025 23:16:57 +0100 Subject: [PATCH 09/16] implemented Conan, adjusted CPM, fixed version issues --- .gitignore | 16 ++++++++++-- CMakeLists.txt | 66 +++++++++++++++++++++-------------------------- conanfile.txt | 20 ++++++++++++++ tools/common.just | 24 ++++------------- 4 files changed, 68 insertions(+), 58 deletions(-) create mode 100644 conanfile.txt diff --git a/.gitignore b/.gitignore index 7c1162d..293fd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -41,17 +41,29 @@ *.dwo *.env -*.log + +# IDE .vscode/ +.idea/ +*.swp +*.swo # CMake build folder /build/ *.o *.obj -*.exe *.dll *.so *.log +build/ +cmake-build-*/ + +# Conan +.conan2/ +conan.lock + +# CMake user presets +CMakeUserPresets.json external/ external/tsl-hat-trie/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ca0932a..bff2455 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,21 @@ cmake_minimum_required(VERSION 3.20) project(moderation-service) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE) +set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE) + +include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake OPTIONAL) + +if(WIN32) + add_definitions(-D_WIN32_WINNT=0x0A00) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif() + +find_package(gRPC CONFIG REQUIRED PATHS ${CMAKE_BINARY_DIR}) +find_package(ICU REQUIRED COMPONENTS uc i18n data) +find_package(Threads REQUIRED) set(CPM_DOWNLOAD_VERSION 0.40.2) if(CPM_SOURCE_CACHE) @@ -20,25 +36,6 @@ endif() include(${CPM_DOWNLOAD_LOCATION}) -CPMAddPackage( - NAME gRPC - GITHUB_REPOSITORY grpc/grpc - GIT_TAG v1.51.1 - OPTIONS - "gRPC_BUILD_TESTS OFF" - "gRPC_BUILD_CODEGEN ON" - "gRPC_BUILD_CSHARP_EXT OFF" -) - -CPMAddPackage( - NAME ICU - GITHUB_REPOSITORY unicode-org/icu - GIT_TAG release-74-2 - SOURCE_SUBDIR icu4c/source - OPTIONS - "ICU_BUILD_TESTS OFF" -) - CPMAddPackage( NAME tsl-hat-trie GITHUB_REPOSITORY Tessil/hat-trie @@ -49,23 +46,18 @@ CPMAddPackage( set(GENPROTO_LIB "genproto_lib") set(GENPROTO_DIR "${PROJECT_SOURCE_DIR}/src/moderationservice/grpc") -# loop through genproto dir -file(GLOB_RECURSE PROTO_SRC "${GENPROTO_DIR}/*.pb.cc") -file(GLOB_RECURSE PROTO_HDR "${GENPROTO_DIR}/*.pb.h") - -add_library(${GENPROTO_LIB} ${PROTO_SRC} ${PROTO_HDR}) +# Explicitly list proto files +add_library(${GENPROTO_LIB} + ${GENPROTO_DIR}/moderation.pb.cc + ${GENPROTO_DIR}/moderation.grpc.pb.cc +) target_link_libraries(${GENPROTO_LIB} PUBLIC - grpc++ + gRPC::grpc++ protobuf::libprotobuf ) -target_include_directories(${GENPROTO_LIB} - PUBLIC - ${GENPROTO_DIR} -) - #link source files add_executable(${PROJECT_NAME} src/moderationservice/main.cpp @@ -81,13 +73,12 @@ add_executable(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE ${GENPROTO_LIB} - grpc++_reflection - icuuc - icui18n - icudata - icuio - icutu + gRPC::grpc++_reflection + ICU::uc + ICU::i18n + ICU::data tsl::hat_trie + Threads::Threads ) #link header files @@ -97,4 +88,5 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src/moderationservice/service ${PROJECT_SOURCE_DIR}/src/moderationservice/model -) + ${GENPROTO_DIR} +) \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..d9636ef --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,20 @@ +[requires] + grpc/1.54.3 + protobuf/3.21.12 + icu/74.2 + +[generators] + CMakeDeps + CMakeToolchain + +[options] + grpc/*:codegen=True + grpc/*:cpp_plugin=True + grpc/*:csharp_ext=False + grpc/*:csharp_plugin=False + grpc/*:node_plugin=False + grpc/*:objective_c_plugin=False + grpc/*:php_plugin=False + grpc/*:python_plugin=False + grpc/*:ruby_plugin=False + grpc/*:shared=False \ No newline at end of file diff --git a/tools/common.just b/tools/common.just index e091f2f..e5fa710 100644 --- a/tools/common.just +++ b/tools/common.just @@ -22,26 +22,12 @@ gen-stubs: fetch-proto update: gen-stubs clean build: - @cmake -S . -B build -DCMAKE_BUILD_TYPE=Release 2>/dev/null || true - @cmake --build build -j$(nproc) - -rebuild: - #!/usr/bin/env bash - if [ -d "build" ]; then - chmod -R u+w build 2>/dev/null || true - rm -rf build - fi - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release - cmake --build build -j$(nproc) - -reconfigure: - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release - cmake --build build -j$(nproc) --clean-first + conan install . --output-folder=build --build=missing + cmake -S . -B build \ + -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \ + -DCMAKE_BUILD_TYPE=Release + cmake --build build run: build ENV=dev tools/load_envs.sh ./build/moderation-service -dev: - @cmake --build build -j$(nproc) - ENV=dev tools/load_envs.sh ./build/moderation-service - From b35e12c3b4bf44695a389ade9e2b64d54e5f4054 Mon Sep 17 00:00:00 2001 From: Andrey Kataev Date: Sat, 1 Nov 2025 12:32:37 +0300 Subject: [PATCH 10/16] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BB=D0=B8=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- conanfile.txt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bff2455..76c82df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,4 +89,4 @@ target_include_directories(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/src/moderationservice/service ${PROJECT_SOURCE_DIR}/src/moderationservice/model ${GENPROTO_DIR} -) \ No newline at end of file +) diff --git a/conanfile.txt b/conanfile.txt index d9636ef..7c0c494 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,7 +1,7 @@ [requires] - grpc/1.54.3 - protobuf/3.21.12 - icu/74.2 + grpc/1.72.0 + protobuf/6.32.1 + icu/77.1 [generators] CMakeDeps @@ -17,4 +17,4 @@ grpc/*:php_plugin=False grpc/*:python_plugin=False grpc/*:ruby_plugin=False - grpc/*:shared=False \ No newline at end of file + grpc/*:shared=False From d908e167baf632f66132423c0b6a05ce3afccae4 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 1 Nov 2025 13:47:29 +0100 Subject: [PATCH 11/16] refactored grpc stubs generation. now grpc stubs are being generated directly by cmake to avoid any versioning issues --- CMakeLists.txt | 54 +- conanfile.txt | 2 +- .../grpc/moderation.grpc.pb.cc | 86 --- .../grpc/moderation.grpc.pb.h | 240 ------- src/moderationservice/grpc/moderation.pb.cc | 589 ------------------ src/moderationservice/grpc/moderation.pb.h | 560 ----------------- tools/common.just | 13 +- 7 files changed, 49 insertions(+), 1495 deletions(-) delete mode 100644 src/moderationservice/grpc/moderation.grpc.pb.cc delete mode 100644 src/moderationservice/grpc/moderation.grpc.pb.h delete mode 100644 src/moderationservice/grpc/moderation.pb.cc delete mode 100644 src/moderationservice/grpc/moderation.pb.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 76c82df..0e4286b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,8 @@ if(WIN32) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) endif() -find_package(gRPC CONFIG REQUIRED PATHS ${CMAKE_BINARY_DIR}) +find_package(Protobuf REQUIRED CONFIG) +find_package(gRPC REQUIRED CONFIG) find_package(ICU REQUIRED COMPONENTS uc i18n data) find_package(Threads REQUIRED) @@ -42,20 +43,59 @@ CPMAddPackage( VERSION 0.6.0 ) -# set necessary variables for genproto lib target +# Set necessary variables for genproto lib target set(GENPROTO_LIB "genproto_lib") -set(GENPROTO_DIR "${PROJECT_SOURCE_DIR}/src/moderationservice/grpc") +set(GENPROTO_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/grpc") +set(PROTO_FILE "${CMAKE_CURRENT_SOURCE_DIR}/.proto/moderation.proto") -# Explicitly list proto files +# Create output directory for generated files +file(MAKE_DIRECTORY ${GENPROTO_DIR}) + +# Define generated file paths +set(PROTO_SRCS "${GENPROTO_DIR}/moderation.pb.cc") +set(PROTO_HDRS "${GENPROTO_DIR}/moderation.pb.h") +set(GRPC_SRCS "${GENPROTO_DIR}/moderation.grpc.pb.cc") +set(GRPC_HDRS "${GENPROTO_DIR}/moderation.grpc.pb.h") + +add_custom_command( + OUTPUT ${PROTO_SRCS} ${PROTO_HDRS} + COMMAND $ + ARGS --proto_path=${CMAKE_CURRENT_SOURCE_DIR}/.proto + --cpp_out=${GENPROTO_DIR} + ${PROTO_FILE} + DEPENDS ${PROTO_FILE} + COMMENT "Generating protobuf files" +) + +# Generate gRPC files using custom command +add_custom_command( + OUTPUT ${GRPC_SRCS} ${GRPC_HDRS} + COMMAND $ + ARGS --proto_path=${CMAKE_CURRENT_SOURCE_DIR}/.proto + --grpc_out=${GENPROTO_DIR} + --plugin=protoc-gen-grpc=$ + ${PROTO_FILE} + DEPENDS ${PROTO_FILE} ${PROTO_HDRS} + COMMENT "Generating gRPC files" +) + +# Create library from generated sources add_library(${GENPROTO_LIB} - ${GENPROTO_DIR}/moderation.pb.cc - ${GENPROTO_DIR}/moderation.grpc.pb.cc + ${PROTO_SRCS} + ${PROTO_HDRS} + ${GRPC_SRCS} + ${GRPC_HDRS} +) + +target_include_directories(${GENPROTO_LIB} + PUBLIC + ${GENPROTO_DIR} ) target_link_libraries(${GENPROTO_LIB} PUBLIC - gRPC::grpc++ protobuf::libprotobuf + gRPC::grpc++ ) #link source files diff --git a/conanfile.txt b/conanfile.txt index 7c0c494..5671ca9 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,6 +1,6 @@ [requires] grpc/1.72.0 - protobuf/6.32.1 + protobuf/5.27.0 icu/77.1 [generators] diff --git a/src/moderationservice/grpc/moderation.grpc.pb.cc b/src/moderationservice/grpc/moderation.grpc.pb.cc deleted file mode 100644 index 1ca0ed3..0000000 --- a/src/moderationservice/grpc/moderation.grpc.pb.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Generated by the gRPC C++ plugin. -// If you make any local change, they will be lost. -// source: moderation.proto - -#include "moderation.pb.h" -#include "moderation.grpc.pb.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -namespace moderation { - -static const char* ModerationService_method_names[] = { - "/moderation.ModerationService/ModerateObject", -}; - -std::unique_ptr< ModerationService::Stub> ModerationService::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { - (void)options; - std::unique_ptr< ModerationService::Stub> stub(new ModerationService::Stub(channel, options)); - return stub; -} - -ModerationService::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) - : channel_(channel), rpcmethod_ModerateObject_(ModerationService_method_names[0], options.suffix_for_stats(),::grpc::internal::RpcMethod::NORMAL_RPC, channel) - {} - -::grpc::Status ModerationService::Stub::ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::moderation::ModerateObjectResponse* response) { - return ::grpc::internal::BlockingUnaryCall< ::moderation::ModerateObjectRequest, ::moderation::ModerateObjectResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_ModerateObject_, context, request, response); -} - -void ModerationService::Stub::async::ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::moderation::ModerateObjectRequest, ::moderation::ModerateObjectResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_ModerateObject_, context, request, response, std::move(f)); -} - -void ModerationService::Stub::async::ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response, ::grpc::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_ModerateObject_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::moderation::ModerateObjectResponse>* ModerationService::Stub::PrepareAsyncModerateObjectRaw(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::moderation::ModerateObjectResponse, ::moderation::ModerateObjectRequest, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_ModerateObject_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::moderation::ModerateObjectResponse>* ModerationService::Stub::AsyncModerateObjectRaw(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncModerateObjectRaw(context, request, cq); - result->StartCall(); - return result; -} - -ModerationService::Service::Service() { - AddMethod(new ::grpc::internal::RpcServiceMethod( - ModerationService_method_names[0], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< ModerationService::Service, ::moderation::ModerateObjectRequest, ::moderation::ModerateObjectResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](ModerationService::Service* service, - ::grpc::ServerContext* ctx, - const ::moderation::ModerateObjectRequest* req, - ::moderation::ModerateObjectResponse* resp) { - return service->ModerateObject(ctx, req, resp); - }, this))); -} - -ModerationService::Service::~Service() { -} - -::grpc::Status ModerationService::Service::ModerateObject(::grpc::ServerContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - - -} // namespace moderation - diff --git a/src/moderationservice/grpc/moderation.grpc.pb.h b/src/moderationservice/grpc/moderation.grpc.pb.h deleted file mode 100644 index f332137..0000000 --- a/src/moderationservice/grpc/moderation.grpc.pb.h +++ /dev/null @@ -1,240 +0,0 @@ -// Generated by the gRPC C++ plugin. -// If you make any local change, they will be lost. -// source: moderation.proto -#ifndef GRPC_moderation_2eproto__INCLUDED -#define GRPC_moderation_2eproto__INCLUDED - -#include "moderation.pb.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace moderation { - -class ModerationService final { - public: - static constexpr char const* service_full_name() { - return "moderation.ModerationService"; - } - class StubInterface { - public: - virtual ~StubInterface() {} - virtual ::grpc::Status ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::moderation::ModerateObjectResponse* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::moderation::ModerateObjectResponse>> AsyncModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::moderation::ModerateObjectResponse>>(AsyncModerateObjectRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::moderation::ModerateObjectResponse>> PrepareAsyncModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::moderation::ModerateObjectResponse>>(PrepareAsyncModerateObjectRaw(context, request, cq)); - } - class async_interface { - public: - virtual ~async_interface() {} - virtual void ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response, std::function) = 0; - virtual void ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response, ::grpc::ClientUnaryReactor* reactor) = 0; - }; - typedef class async_interface experimental_async_interface; - virtual class async_interface* async() { return nullptr; } - class async_interface* experimental_async() { return async(); } - private: - virtual ::grpc::ClientAsyncResponseReaderInterface< ::moderation::ModerateObjectResponse>* AsyncModerateObjectRaw(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::moderation::ModerateObjectResponse>* PrepareAsyncModerateObjectRaw(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) = 0; - }; - class Stub final : public StubInterface { - public: - Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); - ::grpc::Status ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::moderation::ModerateObjectResponse* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::moderation::ModerateObjectResponse>> AsyncModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::moderation::ModerateObjectResponse>>(AsyncModerateObjectRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::moderation::ModerateObjectResponse>> PrepareAsyncModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::moderation::ModerateObjectResponse>>(PrepareAsyncModerateObjectRaw(context, request, cq)); - } - class async final : - public StubInterface::async_interface { - public: - void ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response, std::function) override; - void ModerateObject(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response, ::grpc::ClientUnaryReactor* reactor) override; - private: - friend class Stub; - explicit async(Stub* stub): stub_(stub) { } - Stub* stub() { return stub_; } - Stub* stub_; - }; - class async* async() override { return &async_stub_; } - - private: - std::shared_ptr< ::grpc::ChannelInterface> channel_; - class async async_stub_{this}; - ::grpc::ClientAsyncResponseReader< ::moderation::ModerateObjectResponse>* AsyncModerateObjectRaw(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::moderation::ModerateObjectResponse>* PrepareAsyncModerateObjectRaw(::grpc::ClientContext* context, const ::moderation::ModerateObjectRequest& request, ::grpc::CompletionQueue* cq) override; - const ::grpc::internal::RpcMethod rpcmethod_ModerateObject_; - }; - static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); - - class Service : public ::grpc::Service { - public: - Service(); - virtual ~Service(); - virtual ::grpc::Status ModerateObject(::grpc::ServerContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response); - }; - template - class WithAsyncMethod_ModerateObject : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_ModerateObject() { - ::grpc::Service::MarkMethodAsync(0); - } - ~WithAsyncMethod_ModerateObject() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status ModerateObject(::grpc::ServerContext* /*context*/, const ::moderation::ModerateObjectRequest* /*request*/, ::moderation::ModerateObjectResponse* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestModerateObject(::grpc::ServerContext* context, ::moderation::ModerateObjectRequest* request, ::grpc::ServerAsyncResponseWriter< ::moderation::ModerateObjectResponse>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); - } - }; - typedef WithAsyncMethod_ModerateObject AsyncService; - template - class WithCallbackMethod_ModerateObject : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithCallbackMethod_ModerateObject() { - ::grpc::Service::MarkMethodCallback(0, - new ::grpc::internal::CallbackUnaryHandler< ::moderation::ModerateObjectRequest, ::moderation::ModerateObjectResponse>( - [this]( - ::grpc::CallbackServerContext* context, const ::moderation::ModerateObjectRequest* request, ::moderation::ModerateObjectResponse* response) { return this->ModerateObject(context, request, response); }));} - void SetMessageAllocatorFor_ModerateObject( - ::grpc::MessageAllocator< ::moderation::ModerateObjectRequest, ::moderation::ModerateObjectResponse>* allocator) { - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(0); - static_cast<::grpc::internal::CallbackUnaryHandler< ::moderation::ModerateObjectRequest, ::moderation::ModerateObjectResponse>*>(handler) - ->SetMessageAllocator(allocator); - } - ~WithCallbackMethod_ModerateObject() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status ModerateObject(::grpc::ServerContext* /*context*/, const ::moderation::ModerateObjectRequest* /*request*/, ::moderation::ModerateObjectResponse* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - virtual ::grpc::ServerUnaryReactor* ModerateObject( - ::grpc::CallbackServerContext* /*context*/, const ::moderation::ModerateObjectRequest* /*request*/, ::moderation::ModerateObjectResponse* /*response*/) { return nullptr; } - }; - typedef WithCallbackMethod_ModerateObject CallbackService; - typedef CallbackService ExperimentalCallbackService; - template - class WithGenericMethod_ModerateObject : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_ModerateObject() { - ::grpc::Service::MarkMethodGeneric(0); - } - ~WithGenericMethod_ModerateObject() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status ModerateObject(::grpc::ServerContext* /*context*/, const ::moderation::ModerateObjectRequest* /*request*/, ::moderation::ModerateObjectResponse* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithRawMethod_ModerateObject : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_ModerateObject() { - ::grpc::Service::MarkMethodRaw(0); - } - ~WithRawMethod_ModerateObject() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status ModerateObject(::grpc::ServerContext* /*context*/, const ::moderation::ModerateObjectRequest* /*request*/, ::moderation::ModerateObjectResponse* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestModerateObject(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawCallbackMethod_ModerateObject : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawCallbackMethod_ModerateObject() { - ::grpc::Service::MarkMethodRawCallback(0, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - ::grpc::CallbackServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->ModerateObject(context, request, response); })); - } - ~WithRawCallbackMethod_ModerateObject() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status ModerateObject(::grpc::ServerContext* /*context*/, const ::moderation::ModerateObjectRequest* /*request*/, ::moderation::ModerateObjectResponse* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - virtual ::grpc::ServerUnaryReactor* ModerateObject( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) { return nullptr; } - }; - template - class WithStreamedUnaryMethod_ModerateObject : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_ModerateObject() { - ::grpc::Service::MarkMethodStreamed(0, - new ::grpc::internal::StreamedUnaryHandler< - ::moderation::ModerateObjectRequest, ::moderation::ModerateObjectResponse>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::moderation::ModerateObjectRequest, ::moderation::ModerateObjectResponse>* streamer) { - return this->StreamedModerateObject(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_ModerateObject() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status ModerateObject(::grpc::ServerContext* /*context*/, const ::moderation::ModerateObjectRequest* /*request*/, ::moderation::ModerateObjectResponse* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedModerateObject(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::moderation::ModerateObjectRequest,::moderation::ModerateObjectResponse>* server_unary_streamer) = 0; - }; - typedef WithStreamedUnaryMethod_ModerateObject StreamedUnaryService; - typedef Service SplitStreamedService; - typedef WithStreamedUnaryMethod_ModerateObject StreamedService; -}; - -} // namespace moderation - - -#endif // GRPC_moderation_2eproto__INCLUDED diff --git a/src/moderationservice/grpc/moderation.pb.cc b/src/moderationservice/grpc/moderation.pb.cc deleted file mode 100644 index aca5bd8..0000000 --- a/src/moderationservice/grpc/moderation.pb.cc +++ /dev/null @@ -1,589 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: moderation.proto - -#include "moderation.pb.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) -#include - -PROTOBUF_PRAGMA_INIT_SEG - -namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = _pb::internal; - -namespace moderation { -PROTOBUF_CONSTEXPR ModerateObjectRequest::ModerateObjectRequest( - ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.text_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} - , /*decltype(_impl_.id_)*/int64_t{0} - , /*decltype(_impl_.type_)*/0 - , /*decltype(_impl_._cached_size_)*/{}} {} -struct ModerateObjectRequestDefaultTypeInternal { - PROTOBUF_CONSTEXPR ModerateObjectRequestDefaultTypeInternal() - : _instance(::_pbi::ConstantInitialized{}) {} - ~ModerateObjectRequestDefaultTypeInternal() {} - union { - ModerateObjectRequest _instance; - }; -}; -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ModerateObjectRequestDefaultTypeInternal _ModerateObjectRequest_default_instance_; -PROTOBUF_CONSTEXPR ModerateObjectResponse::ModerateObjectResponse( - ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.success_)*/false - , /*decltype(_impl_._cached_size_)*/{}} {} -struct ModerateObjectResponseDefaultTypeInternal { - PROTOBUF_CONSTEXPR ModerateObjectResponseDefaultTypeInternal() - : _instance(::_pbi::ConstantInitialized{}) {} - ~ModerateObjectResponseDefaultTypeInternal() {} - union { - ModerateObjectResponse _instance; - }; -}; -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ModerateObjectResponseDefaultTypeInternal _ModerateObjectResponse_default_instance_; -} // namespace moderation -static ::_pb::Metadata file_level_metadata_moderation_2eproto[2]; -static const ::_pb::EnumDescriptor* file_level_enum_descriptors_moderation_2eproto[1]; -static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_moderation_2eproto = nullptr; - -const uint32_t TableStruct_moderation_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::moderation::ModerateObjectRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - PROTOBUF_FIELD_OFFSET(::moderation::ModerateObjectRequest, _impl_.id_), - PROTOBUF_FIELD_OFFSET(::moderation::ModerateObjectRequest, _impl_.type_), - PROTOBUF_FIELD_OFFSET(::moderation::ModerateObjectRequest, _impl_.text_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::moderation::ModerateObjectResponse, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - PROTOBUF_FIELD_OFFSET(::moderation::ModerateObjectResponse, _impl_.success_), -}; -static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::moderation::ModerateObjectRequest)}, - { 9, -1, -1, sizeof(::moderation::ModerateObjectResponse)}, -}; - -static const ::_pb::Message* const file_default_instances[] = { - &::moderation::_ModerateObjectRequest_default_instance_._instance, - &::moderation::_ModerateObjectResponse_default_instance_._instance, -}; - -const char descriptor_table_protodef_moderation_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = - "\n\020moderation.proto\022\nmoderation\"W\n\025Modera" - "teObjectRequest\022\n\n\002id\030\001 \001(\003\022$\n\004type\030\002 \001(" - "\0162\026.moderation.ObjectType\022\014\n\004text\030\003 \001(\t\"" - ")\n\026ModerateObjectResponse\022\017\n\007success\030\001 \001" - "(\010*\203\001\n\nObjectType\022\033\n\027OBJECT_TYPE_UNSPECI" - "FIED\020\000\022\037\n\033OBJECT_TYPE_MOD_DESCRIPTION\020\001\022" - "\034\n\030OBJECT_TYPE_COMMENT_TEXT\020\002\022\031\n\025OBJECT_" - "TYPE_USER_NAME\020\0032l\n\021ModerationService\022W\n" - "\016ModerateObject\022!.moderation.ModerateObj" - "ectRequest\032\".moderation.ModerateObjectRe" - "sponseb\006proto3" - ; -static ::_pbi::once_flag descriptor_table_moderation_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_moderation_2eproto = { - false, false, 414, descriptor_table_protodef_moderation_2eproto, - "moderation.proto", - &descriptor_table_moderation_2eproto_once, nullptr, 0, 2, - schemas, file_default_instances, TableStruct_moderation_2eproto::offsets, - file_level_metadata_moderation_2eproto, file_level_enum_descriptors_moderation_2eproto, - file_level_service_descriptors_moderation_2eproto, -}; -PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_moderation_2eproto_getter() { - return &descriptor_table_moderation_2eproto; -} - -// Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_moderation_2eproto(&descriptor_table_moderation_2eproto); -namespace moderation { -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* ObjectType_descriptor() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_moderation_2eproto); - return file_level_enum_descriptors_moderation_2eproto[0]; -} -bool ObjectType_IsValid(int value) { - switch (value) { - case 0: - case 1: - case 2: - case 3: - return true; - default: - return false; - } -} - - -// =================================================================== - -class ModerateObjectRequest::_Internal { - public: -}; - -ModerateObjectRequest::ModerateObjectRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena, - bool is_message_owned) - : ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) { - SharedCtor(arena, is_message_owned); - // @@protoc_insertion_point(arena_constructor:moderation.ModerateObjectRequest) -} -ModerateObjectRequest::ModerateObjectRequest(const ModerateObjectRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - ModerateObjectRequest* const _this = this; (void)_this; - new (&_impl_) Impl_{ - decltype(_impl_.text_){} - , decltype(_impl_.id_){} - , decltype(_impl_.type_){} - , /*decltype(_impl_._cached_size_)*/{}}; - - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - _impl_.text_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.text_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (!from._internal_text().empty()) { - _this->_impl_.text_.Set(from._internal_text(), - _this->GetArenaForAllocation()); - } - ::memcpy(&_impl_.id_, &from._impl_.id_, - static_cast(reinterpret_cast(&_impl_.type_) - - reinterpret_cast(&_impl_.id_)) + sizeof(_impl_.type_)); - // @@protoc_insertion_point(copy_constructor:moderation.ModerateObjectRequest) -} - -inline void ModerateObjectRequest::SharedCtor( - ::_pb::Arena* arena, bool is_message_owned) { - (void)arena; - (void)is_message_owned; - new (&_impl_) Impl_{ - decltype(_impl_.text_){} - , decltype(_impl_.id_){int64_t{0}} - , decltype(_impl_.type_){0} - , /*decltype(_impl_._cached_size_)*/{} - }; - _impl_.text_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.text_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING -} - -ModerateObjectRequest::~ModerateObjectRequest() { - // @@protoc_insertion_point(destructor:moderation.ModerateObjectRequest) - if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { - (void)arena; - return; - } - SharedDtor(); -} - -inline void ModerateObjectRequest::SharedDtor() { - GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); - _impl_.text_.Destroy(); -} - -void ModerateObjectRequest::SetCachedSize(int size) const { - _impl_._cached_size_.Set(size); -} - -void ModerateObjectRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:moderation.ModerateObjectRequest) - uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - _impl_.text_.ClearToEmpty(); - ::memset(&_impl_.id_, 0, static_cast( - reinterpret_cast(&_impl_.type_) - - reinterpret_cast(&_impl_.id_)) + sizeof(_impl_.type_)); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* ModerateObjectRequest::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - while (!ctx->Done(&ptr)) { - uint32_t tag; - ptr = ::_pbi::ReadTag(ptr, &tag); - switch (tag >> 3) { - // int64 id = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { - _impl_.id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - } else - goto handle_unusual; - continue; - // .moderation.ObjectType type = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 16)) { - uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - _internal_set_type(static_cast<::moderation::ObjectType>(val)); - } else - goto handle_unusual; - continue; - // string text = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 26)) { - auto str = _internal_mutable_text(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "moderation.ModerateObjectRequest.text")); - } else - goto handle_unusual; - continue; - default: - goto handle_unusual; - } // switch - handle_unusual: - if ((tag == 0) || ((tag & 7) == 4)) { - CHK_(ptr); - ctx->SetLastTag(tag); - goto message_done; - } - ptr = UnknownFieldParse( - tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - } // while -message_done: - return ptr; -failure: - ptr = nullptr; - goto message_done; -#undef CHK_ -} - -uint8_t* ModerateObjectRequest::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:moderation.ModerateObjectRequest) - uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - // int64 id = 1; - if (this->_internal_id() != 0) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteInt64ToArray(1, this->_internal_id(), target); - } - - // .moderation.ObjectType type = 2; - if (this->_internal_type() != 0) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteEnumToArray( - 2, this->_internal_type(), target); - } - - // string text = 3; - if (!this->_internal_text().empty()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_text().data(), static_cast(this->_internal_text().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "moderation.ModerateObjectRequest.text"); - target = stream->WriteStringMaybeAliased( - 3, this->_internal_text(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:moderation.ModerateObjectRequest) - return target; -} - -size_t ModerateObjectRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:moderation.ModerateObjectRequest) - size_t total_size = 0; - - uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string text = 3; - if (!this->_internal_text().empty()) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_text()); - } - - // int64 id = 1; - if (this->_internal_id() != 0) { - total_size += ::_pbi::WireFormatLite::Int64SizePlusOne(this->_internal_id()); - } - - // .moderation.ObjectType type = 2; - if (this->_internal_type() != 0) { - total_size += 1 + - ::_pbi::WireFormatLite::EnumSize(this->_internal_type()); - } - - return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); -} - -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ModerateObjectRequest::_class_data_ = { - ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, - ModerateObjectRequest::MergeImpl -}; -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ModerateObjectRequest::GetClassData() const { return &_class_data_; } - - -void ModerateObjectRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { - auto* const _this = static_cast(&to_msg); - auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:moderation.ModerateObjectRequest) - GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - if (!from._internal_text().empty()) { - _this->_internal_set_text(from._internal_text()); - } - if (from._internal_id() != 0) { - _this->_internal_set_id(from._internal_id()); - } - if (from._internal_type() != 0) { - _this->_internal_set_type(from._internal_type()); - } - _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); -} - -void ModerateObjectRequest::CopyFrom(const ModerateObjectRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:moderation.ModerateObjectRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool ModerateObjectRequest::IsInitialized() const { - return true; -} - -void ModerateObjectRequest::InternalSwap(ModerateObjectRequest* other) { - using std::swap; - auto* lhs_arena = GetArenaForAllocation(); - auto* rhs_arena = other->GetArenaForAllocation(); - _internal_metadata_.InternalSwap(&other->_internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( - &_impl_.text_, lhs_arena, - &other->_impl_.text_, rhs_arena - ); - ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(ModerateObjectRequest, _impl_.type_) - + sizeof(ModerateObjectRequest::_impl_.type_) - - PROTOBUF_FIELD_OFFSET(ModerateObjectRequest, _impl_.id_)>( - reinterpret_cast(&_impl_.id_), - reinterpret_cast(&other->_impl_.id_)); -} - -::PROTOBUF_NAMESPACE_ID::Metadata ModerateObjectRequest::GetMetadata() const { - return ::_pbi::AssignDescriptors( - &descriptor_table_moderation_2eproto_getter, &descriptor_table_moderation_2eproto_once, - file_level_metadata_moderation_2eproto[0]); -} - -// =================================================================== - -class ModerateObjectResponse::_Internal { - public: -}; - -ModerateObjectResponse::ModerateObjectResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena, - bool is_message_owned) - : ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) { - SharedCtor(arena, is_message_owned); - // @@protoc_insertion_point(arena_constructor:moderation.ModerateObjectResponse) -} -ModerateObjectResponse::ModerateObjectResponse(const ModerateObjectResponse& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - ModerateObjectResponse* const _this = this; (void)_this; - new (&_impl_) Impl_{ - decltype(_impl_.success_){} - , /*decltype(_impl_._cached_size_)*/{}}; - - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - _this->_impl_.success_ = from._impl_.success_; - // @@protoc_insertion_point(copy_constructor:moderation.ModerateObjectResponse) -} - -inline void ModerateObjectResponse::SharedCtor( - ::_pb::Arena* arena, bool is_message_owned) { - (void)arena; - (void)is_message_owned; - new (&_impl_) Impl_{ - decltype(_impl_.success_){false} - , /*decltype(_impl_._cached_size_)*/{} - }; -} - -ModerateObjectResponse::~ModerateObjectResponse() { - // @@protoc_insertion_point(destructor:moderation.ModerateObjectResponse) - if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { - (void)arena; - return; - } - SharedDtor(); -} - -inline void ModerateObjectResponse::SharedDtor() { - GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); -} - -void ModerateObjectResponse::SetCachedSize(int size) const { - _impl_._cached_size_.Set(size); -} - -void ModerateObjectResponse::Clear() { -// @@protoc_insertion_point(message_clear_start:moderation.ModerateObjectResponse) - uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - _impl_.success_ = false; - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* ModerateObjectResponse::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - while (!ctx->Done(&ptr)) { - uint32_t tag; - ptr = ::_pbi::ReadTag(ptr, &tag); - switch (tag >> 3) { - // bool success = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { - _impl_.success_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - } else - goto handle_unusual; - continue; - default: - goto handle_unusual; - } // switch - handle_unusual: - if ((tag == 0) || ((tag & 7) == 4)) { - CHK_(ptr); - ctx->SetLastTag(tag); - goto message_done; - } - ptr = UnknownFieldParse( - tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - } // while -message_done: - return ptr; -failure: - ptr = nullptr; - goto message_done; -#undef CHK_ -} - -uint8_t* ModerateObjectResponse::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:moderation.ModerateObjectResponse) - uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - // bool success = 1; - if (this->_internal_success() != 0) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteBoolToArray(1, this->_internal_success(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:moderation.ModerateObjectResponse) - return target; -} - -size_t ModerateObjectResponse::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:moderation.ModerateObjectResponse) - size_t total_size = 0; - - uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // bool success = 1; - if (this->_internal_success() != 0) { - total_size += 1 + 1; - } - - return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); -} - -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ModerateObjectResponse::_class_data_ = { - ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, - ModerateObjectResponse::MergeImpl -}; -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ModerateObjectResponse::GetClassData() const { return &_class_data_; } - - -void ModerateObjectResponse::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { - auto* const _this = static_cast(&to_msg); - auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:moderation.ModerateObjectResponse) - GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - if (from._internal_success() != 0) { - _this->_internal_set_success(from._internal_success()); - } - _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); -} - -void ModerateObjectResponse::CopyFrom(const ModerateObjectResponse& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:moderation.ModerateObjectResponse) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool ModerateObjectResponse::IsInitialized() const { - return true; -} - -void ModerateObjectResponse::InternalSwap(ModerateObjectResponse* other) { - using std::swap; - _internal_metadata_.InternalSwap(&other->_internal_metadata_); - swap(_impl_.success_, other->_impl_.success_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata ModerateObjectResponse::GetMetadata() const { - return ::_pbi::AssignDescriptors( - &descriptor_table_moderation_2eproto_getter, &descriptor_table_moderation_2eproto_once, - file_level_metadata_moderation_2eproto[1]); -} - -// @@protoc_insertion_point(namespace_scope) -} // namespace moderation -PROTOBUF_NAMESPACE_OPEN -template<> PROTOBUF_NOINLINE ::moderation::ModerateObjectRequest* -Arena::CreateMaybeMessage< ::moderation::ModerateObjectRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::moderation::ModerateObjectRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::moderation::ModerateObjectResponse* -Arena::CreateMaybeMessage< ::moderation::ModerateObjectResponse >(Arena* arena) { - return Arena::CreateMessageInternal< ::moderation::ModerateObjectResponse >(arena); -} -PROTOBUF_NAMESPACE_CLOSE - -// @@protoc_insertion_point(global_scope) -#include diff --git a/src/moderationservice/grpc/moderation.pb.h b/src/moderationservice/grpc/moderation.pb.h deleted file mode 100644 index a5a43be..0000000 --- a/src/moderationservice/grpc/moderation.pb.h +++ /dev/null @@ -1,560 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: moderation.proto - -#ifndef GOOGLE_PROTOBUF_INCLUDED_moderation_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_moderation_2eproto - -#include -#include - -#include -#if PROTOBUF_VERSION < 3021000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -#include -// @@protoc_insertion_point(includes) -#include -#define PROTOBUF_INTERNAL_EXPORT_moderation_2eproto -PROTOBUF_NAMESPACE_OPEN -namespace internal { -class AnyMetadata; -} // namespace internal -PROTOBUF_NAMESPACE_CLOSE - -// Internal implementation detail -- do not use these members. -struct TableStruct_moderation_2eproto { - static const uint32_t offsets[]; -}; -extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_moderation_2eproto; -namespace moderation { -class ModerateObjectRequest; -struct ModerateObjectRequestDefaultTypeInternal; -extern ModerateObjectRequestDefaultTypeInternal _ModerateObjectRequest_default_instance_; -class ModerateObjectResponse; -struct ModerateObjectResponseDefaultTypeInternal; -extern ModerateObjectResponseDefaultTypeInternal _ModerateObjectResponse_default_instance_; -} // namespace moderation -PROTOBUF_NAMESPACE_OPEN -template<> ::moderation::ModerateObjectRequest* Arena::CreateMaybeMessage<::moderation::ModerateObjectRequest>(Arena*); -template<> ::moderation::ModerateObjectResponse* Arena::CreateMaybeMessage<::moderation::ModerateObjectResponse>(Arena*); -PROTOBUF_NAMESPACE_CLOSE -namespace moderation { - -enum ObjectType : int { - OBJECT_TYPE_UNSPECIFIED = 0, - OBJECT_TYPE_MOD_DESCRIPTION = 1, - OBJECT_TYPE_COMMENT_TEXT = 2, - OBJECT_TYPE_USER_NAME = 3, - ObjectType_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), - ObjectType_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() -}; -bool ObjectType_IsValid(int value); -constexpr ObjectType ObjectType_MIN = OBJECT_TYPE_UNSPECIFIED; -constexpr ObjectType ObjectType_MAX = OBJECT_TYPE_USER_NAME; -constexpr int ObjectType_ARRAYSIZE = ObjectType_MAX + 1; - -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* ObjectType_descriptor(); -template -inline const std::string& ObjectType_Name(T enum_t_value) { - static_assert(::std::is_same::value || - ::std::is_integral::value, - "Incorrect type passed to function ObjectType_Name."); - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( - ObjectType_descriptor(), enum_t_value); -} -inline bool ObjectType_Parse( - ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, ObjectType* value) { - return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - ObjectType_descriptor(), name, value); -} -// =================================================================== - -class ModerateObjectRequest final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:moderation.ModerateObjectRequest) */ { - public: - inline ModerateObjectRequest() : ModerateObjectRequest(nullptr) {} - ~ModerateObjectRequest() override; - explicit PROTOBUF_CONSTEXPR ModerateObjectRequest(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - ModerateObjectRequest(const ModerateObjectRequest& from); - ModerateObjectRequest(ModerateObjectRequest&& from) noexcept - : ModerateObjectRequest() { - *this = ::std::move(from); - } - - inline ModerateObjectRequest& operator=(const ModerateObjectRequest& from) { - CopyFrom(from); - return *this; - } - inline ModerateObjectRequest& operator=(ModerateObjectRequest&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const ModerateObjectRequest& default_instance() { - return *internal_default_instance(); - } - static inline const ModerateObjectRequest* internal_default_instance() { - return reinterpret_cast( - &_ModerateObjectRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 0; - - friend void swap(ModerateObjectRequest& a, ModerateObjectRequest& b) { - a.Swap(&b); - } - inline void Swap(ModerateObjectRequest* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(ModerateObjectRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - ModerateObjectRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const ModerateObjectRequest& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const ModerateObjectRequest& from) { - ModerateObjectRequest::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(ModerateObjectRequest* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "moderation.ModerateObjectRequest"; - } - protected: - explicit ModerateObjectRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena, - bool is_message_owned = false); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kTextFieldNumber = 3, - kIdFieldNumber = 1, - kTypeFieldNumber = 2, - }; - // string text = 3; - void clear_text(); - const std::string& text() const; - template - void set_text(ArgT0&& arg0, ArgT... args); - std::string* mutable_text(); - PROTOBUF_NODISCARD std::string* release_text(); - void set_allocated_text(std::string* text); - private: - const std::string& _internal_text() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_text(const std::string& value); - std::string* _internal_mutable_text(); - public: - - // int64 id = 1; - void clear_id(); - int64_t id() const; - void set_id(int64_t value); - private: - int64_t _internal_id() const; - void _internal_set_id(int64_t value); - public: - - // .moderation.ObjectType type = 2; - void clear_type(); - ::moderation::ObjectType type() const; - void set_type(::moderation::ObjectType value); - private: - ::moderation::ObjectType _internal_type() const; - void _internal_set_type(::moderation::ObjectType value); - public: - - // @@protoc_insertion_point(class_scope:moderation.ModerateObjectRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr text_; - int64_t id_; - int type_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_moderation_2eproto; -}; -// ------------------------------------------------------------------- - -class ModerateObjectResponse final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:moderation.ModerateObjectResponse) */ { - public: - inline ModerateObjectResponse() : ModerateObjectResponse(nullptr) {} - ~ModerateObjectResponse() override; - explicit PROTOBUF_CONSTEXPR ModerateObjectResponse(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - ModerateObjectResponse(const ModerateObjectResponse& from); - ModerateObjectResponse(ModerateObjectResponse&& from) noexcept - : ModerateObjectResponse() { - *this = ::std::move(from); - } - - inline ModerateObjectResponse& operator=(const ModerateObjectResponse& from) { - CopyFrom(from); - return *this; - } - inline ModerateObjectResponse& operator=(ModerateObjectResponse&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const ModerateObjectResponse& default_instance() { - return *internal_default_instance(); - } - static inline const ModerateObjectResponse* internal_default_instance() { - return reinterpret_cast( - &_ModerateObjectResponse_default_instance_); - } - static constexpr int kIndexInFileMessages = - 1; - - friend void swap(ModerateObjectResponse& a, ModerateObjectResponse& b) { - a.Swap(&b); - } - inline void Swap(ModerateObjectResponse* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(ModerateObjectResponse* other) { - if (other == this) return; - GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - ModerateObjectResponse* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const ModerateObjectResponse& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const ModerateObjectResponse& from) { - ModerateObjectResponse::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(ModerateObjectResponse* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "moderation.ModerateObjectResponse"; - } - protected: - explicit ModerateObjectResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena, - bool is_message_owned = false); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kSuccessFieldNumber = 1, - }; - // bool success = 1; - void clear_success(); - bool success() const; - void set_success(bool value); - private: - bool _internal_success() const; - void _internal_set_success(bool value); - public: - - // @@protoc_insertion_point(class_scope:moderation.ModerateObjectResponse) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - bool success_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_moderation_2eproto; -}; -// =================================================================== - - -// =================================================================== - -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif // __GNUC__ -// ModerateObjectRequest - -// int64 id = 1; -inline void ModerateObjectRequest::clear_id() { - _impl_.id_ = int64_t{0}; -} -inline int64_t ModerateObjectRequest::_internal_id() const { - return _impl_.id_; -} -inline int64_t ModerateObjectRequest::id() const { - // @@protoc_insertion_point(field_get:moderation.ModerateObjectRequest.id) - return _internal_id(); -} -inline void ModerateObjectRequest::_internal_set_id(int64_t value) { - - _impl_.id_ = value; -} -inline void ModerateObjectRequest::set_id(int64_t value) { - _internal_set_id(value); - // @@protoc_insertion_point(field_set:moderation.ModerateObjectRequest.id) -} - -// .moderation.ObjectType type = 2; -inline void ModerateObjectRequest::clear_type() { - _impl_.type_ = 0; -} -inline ::moderation::ObjectType ModerateObjectRequest::_internal_type() const { - return static_cast< ::moderation::ObjectType >(_impl_.type_); -} -inline ::moderation::ObjectType ModerateObjectRequest::type() const { - // @@protoc_insertion_point(field_get:moderation.ModerateObjectRequest.type) - return _internal_type(); -} -inline void ModerateObjectRequest::_internal_set_type(::moderation::ObjectType value) { - - _impl_.type_ = value; -} -inline void ModerateObjectRequest::set_type(::moderation::ObjectType value) { - _internal_set_type(value); - // @@protoc_insertion_point(field_set:moderation.ModerateObjectRequest.type) -} - -// string text = 3; -inline void ModerateObjectRequest::clear_text() { - _impl_.text_.ClearToEmpty(); -} -inline const std::string& ModerateObjectRequest::text() const { - // @@protoc_insertion_point(field_get:moderation.ModerateObjectRequest.text) - return _internal_text(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void ModerateObjectRequest::set_text(ArgT0&& arg0, ArgT... args) { - - _impl_.text_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:moderation.ModerateObjectRequest.text) -} -inline std::string* ModerateObjectRequest::mutable_text() { - std::string* _s = _internal_mutable_text(); - // @@protoc_insertion_point(field_mutable:moderation.ModerateObjectRequest.text) - return _s; -} -inline const std::string& ModerateObjectRequest::_internal_text() const { - return _impl_.text_.Get(); -} -inline void ModerateObjectRequest::_internal_set_text(const std::string& value) { - - _impl_.text_.Set(value, GetArenaForAllocation()); -} -inline std::string* ModerateObjectRequest::_internal_mutable_text() { - - return _impl_.text_.Mutable(GetArenaForAllocation()); -} -inline std::string* ModerateObjectRequest::release_text() { - // @@protoc_insertion_point(field_release:moderation.ModerateObjectRequest.text) - return _impl_.text_.Release(); -} -inline void ModerateObjectRequest::set_allocated_text(std::string* text) { - if (text != nullptr) { - - } else { - - } - _impl_.text_.SetAllocated(text, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.text_.IsDefault()) { - _impl_.text_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:moderation.ModerateObjectRequest.text) -} - -// ------------------------------------------------------------------- - -// ModerateObjectResponse - -// bool success = 1; -inline void ModerateObjectResponse::clear_success() { - _impl_.success_ = false; -} -inline bool ModerateObjectResponse::_internal_success() const { - return _impl_.success_; -} -inline bool ModerateObjectResponse::success() const { - // @@protoc_insertion_point(field_get:moderation.ModerateObjectResponse.success) - return _internal_success(); -} -inline void ModerateObjectResponse::_internal_set_success(bool value) { - - _impl_.success_ = value; -} -inline void ModerateObjectResponse::set_success(bool value) { - _internal_set_success(value); - // @@protoc_insertion_point(field_set:moderation.ModerateObjectResponse.success) -} - -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif // __GNUC__ -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace moderation - -PROTOBUF_NAMESPACE_OPEN - -template <> struct is_proto_enum< ::moderation::ObjectType> : ::std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::moderation::ObjectType>() { - return ::moderation::ObjectType_descriptor(); -} - -PROTOBUF_NAMESPACE_CLOSE - -// @@protoc_insertion_point(global_scope) - -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_moderation_2eproto diff --git a/tools/common.just b/tools/common.just index e5fa710..566ee9f 100644 --- a/tools/common.just +++ b/tools/common.just @@ -10,18 +10,7 @@ fetch-proto: {{MKDIR}} "{{TMP_DIR}}" {{DOWN}} "https://raw.githubusercontent.com/esclient/protos/{{PROTO_TAG}}/{{PROTO_NAME}}" {{DOWN_OUT}} "{{TMP_DIR}}/{{PROTO_NAME}}" -gen-stubs: fetch-proto - {{MKDIR}} "{{OUT_DIR}}" - protoc \ - --proto_path="{{TMP_DIR}}" \ - --cpp_out="{{OUT_DIR}}" \ - --grpc_out="{{OUT_DIR}}" \ - --plugin=protoc-gen-grpc=$(which grpc_cpp_plugin) \ - "{{TMP_DIR}}/{{PROTO_NAME}}" - -update: gen-stubs clean - -build: +build: fetch-proto conan install . --output-folder=build --build=missing cmake -S . -B build \ -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \ From 60859d83b5ead319985a4bad77fee03e3593a2d8 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 1 Nov 2025 14:00:57 +0100 Subject: [PATCH 12/16] few minor changes --- .gitignore | 4 +++- README.md | 12 ++++++++++++ tools/common.just | 1 - 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 293fd8a..9baef35 100644 --- a/.gitignore +++ b/.gitignore @@ -66,4 +66,6 @@ conan.lock CMakeUserPresets.json external/ -external/tsl-hat-trie/ \ No newline at end of file +external/tsl-hat-trie/ + +.proto diff --git a/README.md b/README.md index a87f1b7..33a5267 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,15 @@ Unbenannt-2025-10-16-0020(1) + + + +To build and run you need the following installed: + +-CMake +-Just +-Conan +-C++ compiler (gcc/clang/MSVC) (gcc recommended) +-curl +-sh/bash (Windows only) +-Internet connection diff --git a/tools/common.just b/tools/common.just index 566ee9f..775d667 100644 --- a/tools/common.just +++ b/tools/common.just @@ -19,4 +19,3 @@ build: fetch-proto run: build ENV=dev tools/load_envs.sh ./build/moderation-service - From 1f5ae180aa36fe4fc47114044f7cadb3ff6e2500 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 1 Nov 2025 14:40:51 +0100 Subject: [PATCH 13/16] path issue fix --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e4286b..5b9091a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,8 @@ add_library(${GENPROTO_LIB} target_include_directories(${GENPROTO_LIB} PUBLIC ${GENPROTO_DIR} + $ + $ ) target_link_libraries(${GENPROTO_LIB} From 763daae93483ac4b17687ae2d03976b635ecb016 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 1 Nov 2025 21:00:31 +0100 Subject: [PATCH 14/16] adjusted cmake for windows and linux compatibility --- CMakeLists.txt | 25 +++++++++++++++++++++---- tools/common.just | 14 +++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b9091a..28f95b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,27 @@ cmake_minimum_required(VERSION 3.20) project(moderation-service) set(CMAKE_CXX_STANDARD 17) + +if(MSVC) + add_compile_options(/utf-8) +endif() + set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE) set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE) -include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake OPTIONAL) - if(WIN32) add_definitions(-D_WIN32_WINNT=0x0A00) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + add_compile_definitions(U_STATIC_IMPLEMENTATION) endif() +include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake OPTIONAL) + find_package(Protobuf REQUIRED CONFIG) find_package(gRPC REQUIRED CONFIG) +find_package(absl REQUIRED CONFIG) find_package(ICU REQUIRED COMPONENTS uc i18n data) find_package(Threads REQUIRED) @@ -90,14 +97,17 @@ add_library(${GENPROTO_LIB} target_include_directories(${GENPROTO_LIB} PUBLIC ${GENPROTO_DIR} - $ - $ + ${protobuf_INCLUDE_DIRS_RELEASE} + ${abseil_INCLUDE_DIRS_RELEASE} + ${grpc_INCLUDE_DIRS_RELEASE} + ${icu_INCLUDE_DIRS_RELEASE} ) target_link_libraries(${GENPROTO_LIB} PUBLIC protobuf::libprotobuf gRPC::grpc++ + gRPC::grpc ) #link source files @@ -115,6 +125,9 @@ add_executable(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE ${GENPROTO_LIB} + gRPC::grpc++ + gRPC::grpc + protobuf::libprotobuf gRPC::grpc++_reflection ICU::uc ICU::i18n @@ -123,6 +136,10 @@ target_link_libraries(${PROJECT_NAME} Threads::Threads ) +if(WIN32) + target_compile_definitions(${PROJECT_NAME} PRIVATE U_STATIC_IMPLEMENTATION) +endif() + #link header files target_include_directories(${PROJECT_NAME} PUBLIC diff --git a/tools/common.just b/tools/common.just index 775d667..ce3ddbb 100644 --- a/tools/common.just +++ b/tools/common.just @@ -15,7 +15,19 @@ build: fetch-proto cmake -S . -B build \ -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \ -DCMAKE_BUILD_TYPE=Release - cmake --build build + cmake --build build --config Release + +build-test: fetch-proto + conan install . --output-folder=build --build=missing + cmake -S . -B build \ + -G "Visual Studio 17 2022" \ + -A x64 \ + -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \ + -DCMAKE_BUILD_TYPE=Release + cmake --build build --config Release run: build ENV=dev tools/load_envs.sh ./build/moderation-service + +run-test: build-test + wsl ENV=dev tools/load_envs.sh ./build/moderation-service From 0dddc728d41beef2154ae31f3292ff8facb204a5 Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 3 Nov 2025 22:02:32 +0100 Subject: [PATCH 15/16] cleanups --- CMakeLists.txt | 4 +--- justfile | 1 - tools/common.just | 11 ++++------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28f95b1..a90e01e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,6 @@ include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake OPTIONAL) find_package(Protobuf REQUIRED CONFIG) find_package(gRPC REQUIRED CONFIG) -find_package(absl REQUIRED CONFIG) find_package(ICU REQUIRED COMPONENTS uc i18n data) find_package(Threads REQUIRED) @@ -64,6 +63,7 @@ set(PROTO_HDRS "${GENPROTO_DIR}/moderation.pb.h") set(GRPC_SRCS "${GENPROTO_DIR}/moderation.grpc.pb.cc") set(GRPC_HDRS "${GENPROTO_DIR}/moderation.grpc.pb.h") +# Generate protobuf files using custom command add_custom_command( OUTPUT ${PROTO_SRCS} ${PROTO_HDRS} COMMAND $ @@ -107,7 +107,6 @@ target_link_libraries(${GENPROTO_LIB} PUBLIC protobuf::libprotobuf gRPC::grpc++ - gRPC::grpc ) #link source files @@ -126,7 +125,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${GENPROTO_LIB} gRPC::grpc++ - gRPC::grpc protobuf::libprotobuf gRPC::grpc++_reflection ICU::uc diff --git a/justfile b/justfile index 4cb57a2..d4e710b 100644 --- a/justfile +++ b/justfile @@ -7,7 +7,6 @@ LOAD_ENVS_URL := 'https://raw.githubusercontent.com/esclient/tools/refs/heads/ma PROTO_TAG := 'v0.1.3' PROTO_NAME := 'moderation.proto' TMP_DIR := '.proto' -OUT_DIR := 'src/moderationservice/grpc' SERVICE_NAME := 'moderation' MKDIR_TOOLS := 'mkdir -p tools' diff --git a/tools/common.just b/tools/common.just index ce3ddbb..1145b4e 100644 --- a/tools/common.just +++ b/tools/common.just @@ -3,21 +3,18 @@ RM := 'rm -rf ' + TMP_DIR DOWN := 'curl -fsSL' DOWN_OUT := '-o' -clean: - {{RM}} - fetch-proto: {{MKDIR}} "{{TMP_DIR}}" {{DOWN}} "https://raw.githubusercontent.com/esclient/protos/{{PROTO_TAG}}/{{PROTO_NAME}}" {{DOWN_OUT}} "{{TMP_DIR}}/{{PROTO_NAME}}" -build: fetch-proto +build-linux: fetch-proto conan install . --output-folder=build --build=missing cmake -S . -B build \ -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \ -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release -build-test: fetch-proto +build-windows: fetch-proto conan install . --output-folder=build --build=missing cmake -S . -B build \ -G "Visual Studio 17 2022" \ @@ -26,8 +23,8 @@ build-test: fetch-proto -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release -run: build +run-l: build-linux ENV=dev tools/load_envs.sh ./build/moderation-service -run-test: build-test +run-w: build-windows wsl ENV=dev tools/load_envs.sh ./build/moderation-service From 7cf5b1cd0fffdaac4dc841951041ab8d94aba862 Mon Sep 17 00:00:00 2001 From: Andrey Kataev Date: Wed, 5 Nov 2025 15:55:16 +0300 Subject: [PATCH 16/16] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/common.just | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/common.just b/tools/common.just index 1145b4e..68bd7ea 100644 --- a/tools/common.just +++ b/tools/common.just @@ -27,4 +27,4 @@ run-l: build-linux ENV=dev tools/load_envs.sh ./build/moderation-service run-w: build-windows - wsl ENV=dev tools/load_envs.sh ./build/moderation-service + ENV=dev tools/load_envs.sh ./build/Release/moderation-service.exe