Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
*.out
*.app

# custom files and directories
# custom files and directories
third_party/_submodules
_out/
build/
bin/
obj/
.idea
node_modules

Expand All @@ -41,4 +42,4 @@ cmd/protoc-gen-cpp-tableau-loader/protoc-gen-cpp-tableau-loader
cmd/protoc-gen-go-tableau-loader/protoc-gen-go-tableau-loader

test/go-tableau-loader/go-tableau-loader
_lab/ts/src/protoconf
_lab/ts/src/protoconf
18 changes: 16 additions & 2 deletions cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "load.pc.h"

#if __cplusplus >= 201703L
#include <filesystem>
#endif

#include "logger.pc.h"
#include "util.pc.h"

Expand Down Expand Up @@ -175,8 +179,13 @@ bool LoadMessageWithPatch(google::protobuf::Message& msg, const std::string& pat
// patch path specified in PatchPaths, then use it instead of PatchDirs.
patch_paths = iter->second;
} else {
std::string filename = name + util::Format2Ext(fmt);
for (auto&& patch_dir : options->patch_dirs) {
patch_paths.emplace_back(patch_dir + name + util::Format2Ext(fmt));
#if __cplusplus >= 201703L
patch_paths.emplace_back((std::filesystem::path(patch_dir) / filename).make_preferred().string());
#else
patch_paths.emplace_back(patch_dir + kPathSeperator + filename);
#endif
}
}

Expand Down Expand Up @@ -276,7 +285,12 @@ bool LoadMessage(google::protobuf::Message& msg, const std::string& dir, Format
}
}
if (path.empty()) {
path = dir + name + util::Format2Ext(fmt);
std::string filename = name + util::Format2Ext(fmt);
#if __cplusplus >= 201703L
path = (std::filesystem::path(dir) / filename).make_preferred().string();
#else
path = dir + kPathSeperator + filename;
#endif
}

const google::protobuf::Descriptor* descriptor = msg.GetDescriptor();
Expand Down
4 changes: 1 addition & 3 deletions cmd/protoc-gen-cpp-tableau-loader/embed/messager.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <google/protobuf/message.h>

#include <chrono>
#include <functional>
#include <string>

Expand All @@ -14,9 +15,6 @@ class Messager {
public:
struct Stats {
std::chrono::microseconds duration; // total load time consuming.
// TODO: crc32 of config file to decide whether changed or not
// std::string crc32;
// int64_t last_modified_time = 0; // unix timestamp
};

public:
Expand Down
18 changes: 3 additions & 15 deletions cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#if __cplusplus >= 201703L
#include <filesystem>
namespace fs = std::filesystem;
#else
#ifdef _WIN32
#include <direct.h>
Expand All @@ -26,9 +25,6 @@ namespace fs = std::filesystem;
namespace tableau {
#ifdef _WIN32
#define mkdir(path, mode) _mkdir(path)
static constexpr char kPathSeperator = '\\';
#else
static constexpr char kPathSeperator = '/';
#endif

static thread_local std::string g_err_msg;
Expand All @@ -44,7 +40,7 @@ namespace util {
int Mkdir(const std::string& path) {
#if __cplusplus >= 201703L
std::error_code ec;
if (!fs::create_directories(path, ec)) {
if (!std::filesystem::create_directories(path, ec)) {
if (ec) {
std::cerr << "system error: " << ec.message() << std::endl;
return -1;
Expand Down Expand Up @@ -72,7 +68,7 @@ int Mkdir(const std::string& path) {

std::string GetDir(const std::string& path) {
#if __cplusplus >= 201703L
return fs::path(path).parent_path().string();
return std::filesystem::path(path).parent_path().string();
#else
size_t pos = path.find_last_of(kPathSeperator);
if (pos != std::string::npos) {
Expand All @@ -84,7 +80,7 @@ std::string GetDir(const std::string& path) {

bool ExistsFile(const std::string& filename) {
#if __cplusplus >= 201703L
return fs::exists(filename);
return std::filesystem::exists(filename);
#else
std::ifstream file(filename);
// returns true if the file exists and is accessible
Expand Down Expand Up @@ -137,14 +133,6 @@ const std::string& Format2Ext(Format fmt) {
}
}

bool Message2JSON(const google::protobuf::Message& msg, std::string& json) {
google::protobuf::util::JsonPrintOptions options;
options.add_whitespace = true;
options.always_print_primitive_fields = true;
options.preserve_proto_field_names = true;
return google::protobuf::util::MessageToJsonString(msg, &json, options).ok();
}

Comment thread
wenchy marked this conversation as resolved.
bool JSON2Message(const std::string& json, google::protobuf::Message& msg, const LoadOptions* options /* = nullptr */) {
google::protobuf::util::Status status;
if (options != nullptr) {
Expand Down
10 changes: 9 additions & 1 deletion cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ namespace tableau {
const std::string& GetErrMsg();
void SetErrMsg(const std::string& msg);

#if __cplusplus < 201703L
// Platform-specific path separator
#ifdef _WIN32
constexpr char kPathSeperator = '\\';
#else
constexpr char kPathSeperator = '/';
#endif
#endif

enum class Format {
kUnknown,
kJSON,
Expand Down Expand Up @@ -73,7 +82,6 @@ Format Ext2Format(const std::string& ext);
// and the error message can be obtained by GetErrMsg().
const std::string& Format2Ext(Format fmt);

bool Message2JSON(const google::protobuf::Message& msg, std::string& json);
bool JSON2Message(const std::string& json, google::protobuf::Message& msg, const LoadOptions* options = nullptr);
bool Text2Message(const std::string& text, google::protobuf::Message& msg);
bool Bin2Message(const std::string& bin, google::protobuf::Message& msg);
Expand Down
10 changes: 0 additions & 10 deletions cmd/protoc-gen-cpp-tableau-loader/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ func generateHubCppRegistry(gen *protogen.Plugin, g *protogen.GeneratedFile, pro
}

const hubHpp = `#pragma once
#include <google/protobuf/message.h>
#include <google/protobuf/util/json_util.h>
#include <tableau/protobuf/tableau.pb.h>

#include <ctime>
#include <functional>
#include <mutex>
Expand Down Expand Up @@ -290,12 +286,6 @@ void Registry::Register() {

const hubCppHeader = `#include "hub.pc.h"

#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/text_format.h>

#include <string>

#include "logger.pc.h"
#include "messager.pc.h"
#include "util.pc.h"`
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (MSVC)
if(USE_CPP17)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /DNDEBUG /std:c++17")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /DNDEBUG /std:c++11")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /DNDEBUG")
endif()
else()
if(USE_CPP17)
Expand Down
6 changes: 0 additions & 6 deletions test/cpp-tableau-loader/src/protoconf/hub.pc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

#include "hub.pc.h"

#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/text_format.h>

#include <string>

#include "logger.pc.h"
#include "messager.pc.h"
#include "util.pc.h"
Expand Down
4 changes: 0 additions & 4 deletions test/cpp-tableau-loader/src/protoconf/hub.pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
// - protoc v3.19.3

#pragma once
#include <google/protobuf/message.h>
#include <google/protobuf/util/json_util.h>
#include <tableau/protobuf/tableau.pb.h>

#include <ctime>
#include <functional>
#include <mutex>
Expand Down
18 changes: 16 additions & 2 deletions test/cpp-tableau-loader/src/protoconf/load.pc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include "load.pc.h"

#if __cplusplus >= 201703L
#include <filesystem>
#endif

#include "logger.pc.h"
#include "util.pc.h"

Expand Down Expand Up @@ -180,8 +184,13 @@ bool LoadMessageWithPatch(google::protobuf::Message& msg, const std::string& pat
// patch path specified in PatchPaths, then use it instead of PatchDirs.
patch_paths = iter->second;
} else {
std::string filename = name + util::Format2Ext(fmt);
for (auto&& patch_dir : options->patch_dirs) {
patch_paths.emplace_back(patch_dir + name + util::Format2Ext(fmt));
#if __cplusplus >= 201703L
patch_paths.emplace_back((std::filesystem::path(patch_dir) / filename).make_preferred().string());
#else
patch_paths.emplace_back(patch_dir + kPathSeperator + filename);
#endif
}
}

Expand Down Expand Up @@ -281,7 +290,12 @@ bool LoadMessage(google::protobuf::Message& msg, const std::string& dir, Format
}
}
if (path.empty()) {
path = dir + name + util::Format2Ext(fmt);
std::string filename = name + util::Format2Ext(fmt);
#if __cplusplus >= 201703L
path = (std::filesystem::path(dir) / filename).make_preferred().string();
#else
path = dir + kPathSeperator + filename;
#endif
}

const google::protobuf::Descriptor* descriptor = msg.GetDescriptor();
Expand Down
4 changes: 1 addition & 3 deletions test/cpp-tableau-loader/src/protoconf/messager.pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once
#include <google/protobuf/message.h>

#include <chrono>
#include <functional>
#include <string>

Expand All @@ -19,9 +20,6 @@ class Messager {
public:
struct Stats {
std::chrono::microseconds duration; // total load time consuming.
// TODO: crc32 of config file to decide whether changed or not
// std::string crc32;
// int64_t last_modified_time = 0; // unix timestamp
};

public:
Expand Down
18 changes: 3 additions & 15 deletions test/cpp-tableau-loader/src/protoconf/util.pc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#if __cplusplus >= 201703L
#include <filesystem>
namespace fs = std::filesystem;
#else
#ifdef _WIN32
#include <direct.h>
Expand All @@ -31,9 +30,6 @@ namespace fs = std::filesystem;
namespace tableau {
#ifdef _WIN32
#define mkdir(path, mode) _mkdir(path)
static constexpr char kPathSeperator = '\\';
#else
static constexpr char kPathSeperator = '/';
#endif

static thread_local std::string g_err_msg;
Expand All @@ -49,7 +45,7 @@ namespace util {
int Mkdir(const std::string& path) {
#if __cplusplus >= 201703L
std::error_code ec;
if (!fs::create_directories(path, ec)) {
if (!std::filesystem::create_directories(path, ec)) {
if (ec) {
std::cerr << "system error: " << ec.message() << std::endl;
return -1;
Expand Down Expand Up @@ -77,7 +73,7 @@ int Mkdir(const std::string& path) {

std::string GetDir(const std::string& path) {
#if __cplusplus >= 201703L
return fs::path(path).parent_path().string();
return std::filesystem::path(path).parent_path().string();
#else
size_t pos = path.find_last_of(kPathSeperator);
if (pos != std::string::npos) {
Expand All @@ -89,7 +85,7 @@ std::string GetDir(const std::string& path) {

bool ExistsFile(const std::string& filename) {
#if __cplusplus >= 201703L
return fs::exists(filename);
return std::filesystem::exists(filename);
#else
std::ifstream file(filename);
// returns true if the file exists and is accessible
Expand Down Expand Up @@ -142,14 +138,6 @@ const std::string& Format2Ext(Format fmt) {
}
}

bool Message2JSON(const google::protobuf::Message& msg, std::string& json) {
google::protobuf::util::JsonPrintOptions options;
options.add_whitespace = true;
options.always_print_primitive_fields = true;
options.preserve_proto_field_names = true;
return google::protobuf::util::MessageToJsonString(msg, &json, options).ok();
}

bool JSON2Message(const std::string& json, google::protobuf::Message& msg, const LoadOptions* options /* = nullptr */) {
google::protobuf::util::Status status;
if (options != nullptr) {
Expand Down
10 changes: 9 additions & 1 deletion test/cpp-tableau-loader/src/protoconf/util.pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ namespace tableau {
const std::string& GetErrMsg();
void SetErrMsg(const std::string& msg);

#if __cplusplus < 201703L
// Platform-specific path separator
#ifdef _WIN32
constexpr char kPathSeperator = '\\';
#else
constexpr char kPathSeperator = '/';
#endif
#endif

enum class Format {
kUnknown,
kJSON,
Expand Down Expand Up @@ -78,7 +87,6 @@ Format Ext2Format(const std::string& ext);
// and the error message can be obtained by GetErrMsg().
const std::string& Format2Ext(Format fmt);

bool Message2JSON(const google::protobuf::Message& msg, std::string& json);
bool JSON2Message(const std::string& json, google::protobuf::Message& msg, const LoadOptions* options = nullptr);
bool Text2Message(const std::string& text, google::protobuf::Message& msg);
bool Bin2Message(const std::string& bin, google::protobuf::Message& msg);
Expand Down