Skip to content

Commit

Permalink
chore: github import
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Serdyukov committed Nov 13, 2024
0 parents commit 267af81
Show file tree
Hide file tree
Showing 83 changed files with 17,320 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build/
.vscode/
.vs/
gen/
*.user
.cache
**__pycache__
Empty file added .gitmodules
Empty file.
111 changes: 111 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# This file is a part of RPCXX project

#[[
Copyright 2024 "NEOLANT Service", "NEOLANT Kalinigrad", Alexey Doronin, Anastasia Lugovets, Dmitriy Dyakonov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
]]


cmake_minimum_required(VERSION 3.16)

project(rpcxx VERSION 1.0 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)

option(BUILD_SHARED_LIBS "Build libs as shared" OFF)
option(RPCXX_WITH_CODEGEN "Compile Code Generator" ON)
option(RPCXX_TEST_SANITIZERS "Enable sanitizers" ON)
option(RPCXX_TEST_RPS "Build QT5 based RPS test" OFF)
option(RPCXX_WITH_TESTS "Build tests" OFF)

include(cmake/RPCXXCodegen.cmake)
include(cmake/CPM.cmake)

CPMAddPackage("gh:p-ranav/argparse@3.0")
CPMAddPackage("gh:fmtlib/fmt#11.0.2")
CPMAddPackage("gh:cyanidle/describe@1.0")

add_library(rpcxx-warnings INTERFACE)
add_library(rpcxx-options INTERFACE)
add_library(rpcxx-headers INTERFACE)
target_include_directories(rpcxx-headers INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

if(CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(rpcxx-warnings INTERFACE -Wall -Wextra)
endif()

add_library(rpcxx-future STATIC src/future.cpp)
target_link_libraries(rpcxx-future PRIVATE rpcxx-options rpcxx-warnings)
target_link_libraries(rpcxx-future PUBLIC rpcxx-headers)

file(GLOB JSON_VIEW_SOURCES CONFIGURE_DEPENDS src/json_view/*.cpp)
add_library(rpcxx-json STATIC ${JSON_VIEW_SOURCES})
target_link_libraries(rpcxx-json PRIVATE rpcxx-options rpcxx-warnings)
target_link_libraries(rpcxx-json PUBLIC rpcxx-headers describe)

file(GLOB RPCXX_SOURCES CONFIGURE_DEPENDS src/rpcxx/*.cpp)
add_library(rpcxx STATIC ${RPCXX_SOURCES})
add_library(rpcxx::rpcxx ALIAS rpcxx)

target_link_libraries(rpcxx PRIVATE rpcxx-options rpcxx-warnings)
target_link_libraries(rpcxx PUBLIC rpcxx-json rpcxx-headers rpcxx-future)

install(TARGETS rpcxx OPTIONAL)

# Do not clone submodules
cmake_policy(SET CMP0097 NEW)
CPMAddPackage(NAME rapidjson
GITHUB_REPOSITORY Tencent/rapidjson
VERSION 1.1.1
GIT_TAG 7c73dd7
GIT_SUBMODULES ""
DOWNLOAD_ONLY YES
)

target_include_directories(rpcxx-json PRIVATE ${rapidjson_SOURCE_DIR}/include)

if(RPCXX_WITH_TESTS)
CPMAddPackage("gh:doctest/doctest@2.4.11")
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
VERSION 1.8.3
OPTIONS "BENCHMARK_ENABLE_TESTING OFF"
GIT_SHALLOW YES
EXCLUDE_FROM_ALL YES
)
endif()

if(WIN32)
target_link_libraries(rpcxx-json PRIVATE ws2_32)
target_link_libraries(rpcxx PRIVATE ws2_32)
endif()

if(RPCXX_WITH_TESTS)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
if(RPCXX_WITH_CODEGEN)
add_subdirectory(codegen)
endif()
45 changes: 45 additions & 0 deletions LICENCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Copyright 2024 "NEOLANT Service", "NEOLANT Kalinigrad", Alexey Doronin, Anastasia Lugovets, Dmitriy Dyakonov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


Copyright 2024 "НЕОЛАНТ Сервис", "НЕОЛАНТ Калиниград", Алексей Доронин, Анастасия Луговец, Дмитрий Дьяконов

Данная лицензия разрешает лицам, получившим копию данного программного обеспечения и
сопутствующей документации (в дальнейшем именуемыми «Программное Обеспечение»),
безвозмездно использовать Программное Обеспечение без ограничений,
включая неограниченное право на использование,
копирование, изменение, добавление, публикацию, распространение,
сублицензирование и/или продажу копий Программного Обеспечения,
также как и лицам, которым предоставляется данное Программное Обеспечение,
при соблюдении следующих условий:

Указанное выше уведомление об авторском праве и данные условия
должны быть включены во все копии или значимые части данного Программного Обеспечения.

ДАННОЕ ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ ПРЕДОСТАВЛЯЕТСЯ «КАК ЕСТЬ»,
БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ, ЯВНО ВЫРАЖЕННЫХ ИЛИ ПОДРАЗУМЕВАЕМЫХ,
ВКЛЮЧАЯ, НО НЕ ОГРАНИЧИВАЯСЬ ГАРАНТИЯМИ ТОВАРНОЙ ПРИГОДНОСТИ,
СООТВЕТСТВИЯ ПО ЕГО КОНКРЕТНОМУ НАЗНАЧЕНИЮ И ОТСУТСТВИЯ НАРУШЕНИЙ ПРАВ.
НИ В КАКОМ СЛУЧАЕ АВТОРЫ ИЛИ ПРАВООБЛАДАТЕЛИ НЕ НЕСУТ
ОТВЕТСТВЕННОСТИ ПО ИСКАМ О ВОЗМЕЩЕНИИ УЩЕРБА, УБЫТКОВ ИЛИ ДРУГИХ ТРЕБОВАНИЙ
ПО ДЕЙСТВУЮЩИМ КОНТРАКТАМ, ДЕЛИКТАМ ИЛИ ИНОМУ, ВОЗНИКШИМ ИЗ,
ИМЕЮЩИМ ПРИЧИНОЙ ИЛИ СВЯЗАННЫМ С ПРОГРАММНЫМ ОБЕСПЕЧЕНИЕМ ИЛИ ИСПОЛЬЗОВАНИЕМ
ПРОГРАММНОГО ОБЕСПЕЧЕНИЯ ИЛИ ИНЫМИ ДЕЙСТВИЯМИ С ПРОГРАММНЫМ ОБЕСПЕЧЕНИЕМ.

100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# RPCXX - Transport-agnostic (JsonRPC 2.0) cpp library

```cpp
rpcxx::Server server;
rpcxx::Transport transport;

server->SetTransport(&transport);

transport.OnReply([](rpcxx::JsonView reply){
MySendString(reply.Dump());
});
OnMyRequest([&](string_view msg){
transport.Receive(rpcxx::Json::From(msg).View());
});

// params as array
server.Method("add", [](int a, int b){
return a + b;
});
// Receive params as object
server.Method("named_sub", [](size_t a, size_t b){
return a - b
}, rpcxx::NamesMap("a", "b"));

myEventLoop.run();
```
## JsonView
* Makes a structured View into the object to be serialized.
* Support great customizability with DESCRIBE attributes
* Uses Arenas for allocating the DOM - perfect memory model for RPC requests
* Arenas make freeing deep DOMs very fast
* Arenas make JsonViews trivially-copyable
* Arenas provide great cache-locality
```cpp
struct My {
string field;
};
DESCRIBE(My, &_::field)
My obj{"VeryLongString.............. etc."};
jv::DefaultArena alloc;
jv::JsonView::From(obj, alloc);
// No copies.
// 16 bytes bump-allocated for single JsonPair (Json object of size 1)
// jv::DefaultArena<N = 2048> has an extra size N stack buffer
```

## Codegen - Generate Server and Client stubs!

* Custom DSL for describing RPC and Structures.
* Based on LUA 5.4+.
* Supports: cpp, go(limited)
* Can be built and immedieately used in single CMAKE build.
* Can be used for generating Json config boilerplate

```lua
namespace "my"

config = include("config.lua")

CompressionAlgo = Alias(config.CompressionAlgo)

SessionResult = struct() {
id = string,
version = string,
}

Locale = enum() {
"ru_RU"
}

L10n = struct() {
errors = Locale("ru_RU"),
}

SessionFeatures = struct() {
rpc_compression = {
enabled = bool(false),
threshhold = u64(1024),
algo = CompressionAlgo(CompressionAlgo.gzip)
},
localization = Optional(L10n),
}

SessionParams = struct() {
reconnectId = Optional(string),
features = Optional(SessionFeatures)
}

CloseParams = struct() {
allow_reconnect = Optional(bool),
reason = Optional(string),
}

methods("Server_Name") {
initialize_session = async {#SessionParams} >> SessionResult,
close_session = {#CloseParams},
}
```
Loading

0 comments on commit 267af81

Please sign in to comment.