From 2183ae18d680bd7e28475038023e19d7274e4e67 Mon Sep 17 00:00:00 2001 From: RealTimeChris <40668522+RealTimeChris@users.noreply.github.com> Date: Thu, 9 May 2024 23:56:42 -0400 Subject: [PATCH] DiscordCoreAPI Release 2.0.7 * Updated to keep in track with Jsonifier dependency. * Added a detect-cpu-architecture script. --- .../{CLANG_18-Ubuntu.yml => CLANG-Ubuntu.yml} | 38 ++-- .../{GCC_13-MacOS.yml => GCC-MacOS.yml} | 40 ++-- ...MSVC_2022-Windows.yml => MSVC-Windows.yml} | 5 +- CMake/BuildFeatureTester.bat | 2 + CMake/BuildFeatureTester.sh | 3 + CMake/CMakeLists.txt | 5 + CMake/DCADetectArchitecture.cmake | 182 ++++++++--------- CMake/main.cpp | 184 ++++++++++++++++++ CMakePresets.json | 118 +++++------ Include/discordcoreapi/DiscordCoreClient.hpp | 4 +- Include/discordcoreapi/FoundationEntities.hpp | 85 ++++---- Include/discordcoreapi/Index.hpp | 5 - .../discordcoreapi/JsonSpecializations.hpp | 38 ++-- Include/discordcoreapi/Utilities/Base.hpp | 30 ++- Include/discordcoreapi/Utilities/Etf.hpp | 24 +-- Include/discordcoreapi/Utilities/Hash.hpp | 6 - .../discordcoreapi/Utilities/HttpsClient.hpp | 2 +- Include/discordcoreapi/Utilities/ISA/AVX.hpp | 2 +- Include/discordcoreapi/Utilities/ISA/AVX2.hpp | 2 +- .../discordcoreapi/Utilities/ISA/AVX512.hpp | 2 +- .../discordcoreapi/Utilities/ISA/Fallback.hpp | 2 +- Include/discordcoreapi/Utilities/ISA/Neon.hpp | 103 ++++++++++ .../discordcoreapi/Utilities/ISADetection.hpp | 3 +- .../discordcoreapi/Utilities/RingBuffer.hpp | 18 +- .../Utilities/UnboundedMessageBlock.hpp | 4 +- .../discordcoreapi/Utilities/UnicodeEmoji.hpp | 31 ++- .../discordcoreapi/Utilities/UnorderedSet.hpp | 4 +- Include/discordcoreapi/VoiceConnection.hpp | 19 +- Include/discordcoreapi/YouTubeAPI.hpp | 16 +- ReadMe.md | 2 +- Source/DiscordCoreClient.cpp | 5 +- Source/EventManager.cpp | 120 ++++++------ Source/FoundationEntities.cpp | 66 +++---- Source/SoundCloudAPI.cpp | 4 +- Source/VoiceConnection.cpp | 18 +- Source/WebSocketClient.cpp | 7 +- Source/YouTubeAPI.cpp | 36 ++-- Vcpkg/ports/discordcoreapi/portfile.cmake | 3 +- Vcpkg/ports/discordcoreapi/vcpkg.json | 2 +- Vcpkg/versions/d-/discordcoreapi.json | 5 + 40 files changed, 796 insertions(+), 449 deletions(-) rename .github/workflows/{CLANG_18-Ubuntu.yml => CLANG-Ubuntu.yml} (54%) rename .github/workflows/{GCC_13-MacOS.yml => GCC-MacOS.yml} (50%) rename .github/workflows/{MSVC_2022-Windows.yml => MSVC-Windows.yml} (95%) create mode 100644 CMake/BuildFeatureTester.bat create mode 100644 CMake/BuildFeatureTester.sh create mode 100644 CMake/CMakeLists.txt create mode 100644 CMake/main.cpp create mode 100644 Include/discordcoreapi/Utilities/ISA/Neon.hpp diff --git a/.github/workflows/CLANG_18-Ubuntu.yml b/.github/workflows/CLANG-Ubuntu.yml similarity index 54% rename from .github/workflows/CLANG_18-Ubuntu.yml rename to .github/workflows/CLANG-Ubuntu.yml index ab5899e24..83b37ce3a 100644 --- a/.github/workflows/CLANG_18-Ubuntu.yml +++ b/.github/workflows/CLANG-Ubuntu.yml @@ -1,6 +1,7 @@ name: Build-and-Test-CLANG-Ubuntu on: + workflow_dispatch: push: branches: - main @@ -13,41 +14,42 @@ jobs: strategy: fail-fast: false matrix: - clang: [18] + clang: [19] build_type: [Debug, Release] std: [20] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install the latest Clang compiler. - working-directory: ./ + working-directory: Tests run: | + sudo apt update && sudo apt upgrade wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 18 + chmod u+x llvm.sh + sudo ./llvm.sh 19 - name: Update Vcpkg and install other dependencies. - run: | - sudo apt-get update --fix-missing - sudo apt-get upgrade --fix-missing + run: | + sudo apt-get update + sudo apt-get upgrade sudo apt-get install nasm - cd /usr/local/share/vcpkg - ./bootstrap-vcpkg.sh - git stash - git pull - vcpkg update + /usr/local/share/vcpkg/vcpkg update + + - name: Set TERM environment variable + run: echo "export TERM=xterm" >> $GITHUB_ENV - name: Install the dependencies. + working-directory: ./ run: | - vcpkg install opus:x64-linux - vcpkg install libsodium:x64-linux - vcpkg install openssl:x64-linux + /usr/local/share/vcpkg/vcpkg install opus:x64-linux + /usr/local/share/vcpkg/vcpkg install libsodium:x64-linux + /usr/local/share/vcpkg/vcpkg install openssl:x64-linux - name: Configure CMake working-directory: ./ run: | - cmake -S . -B ./Build -DCMAKE_CXX_COMPILER=/usr/bin/clang++-18 -DDEV=true -DDISCORDCOREAPI_TEST=true -DVCPKG_ROOT_DIR=/usr/local/share/vcpkg + cmake -S . -B ./Build -DCMAKE_CXX_COMPILER=/usr/bin/clang++-19 -DDEV=true -DDISCORDCOREAPI_TEST=true -DVCPKG_ROOT_DIR="/usr/local/share/vcpkg/" - name: Build the Test working-directory: ./Build @@ -57,6 +59,6 @@ jobs: - name: Run the Test working-directory: ./Build/Tests run: | - chmod u+x ./DiscordCoreAPITest + sudo chmod u+x ./DiscordCoreAPITest ./DiscordCoreAPITest continue-on-error: true \ No newline at end of file diff --git a/.github/workflows/GCC_13-MacOS.yml b/.github/workflows/GCC-MacOS.yml similarity index 50% rename from .github/workflows/GCC_13-MacOS.yml rename to .github/workflows/GCC-MacOS.yml index 4dace0c4c..f8d28557d 100644 --- a/.github/workflows/GCC_13-MacOS.yml +++ b/.github/workflows/GCC-MacOS.yml @@ -1,6 +1,7 @@ name: Build-and-Test-GCC-MacOS on: + workflow_dispatch: push: branches: - main @@ -13,26 +14,26 @@ jobs: strategy: fail-fast: false matrix: - gcc: [13] + gnucxx: [14] build_type: [Debug, Release] std: [20] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Install the latest g++ compiler. + - name: Install the latest GnuCXX compiler. run: | - brew install gcc + brew install gcc --force-bottle - name: Update Vcpkg and install other dependencies. - run: | - brew update + run: | + brew update brew upgrade brew install nasm brew install nano brew install autoconf brew install automake - brew install glibtoolize + brew install libtool which autoconf export PATH="/opt/homebrew/bin/autoconf:$PATH" git clone https://github.com/Microsoft/Vcpkg ./vcpkg2 @@ -42,25 +43,28 @@ jobs: git pull ./vcpkg update - - name: Set TERM environment variable - run: echo "export TERM=xterm" >> $GITHUB_ENV - - name: Install the dependencies. - working-directory: /Users/runner/work/DiscordCoreAPI/DiscordCoreAPI/vcpkg2/ run: | - /Users/runner/work/DiscordCoreAPI/DiscordCoreAPI/vcpkg2/vcpkg install opus:x64-osx - /Users/runner/work/DiscordCoreAPI/DiscordCoreAPI/vcpkg2/vcpkg install libsodium:x64-osx - /Users/runner/work/DiscordCoreAPI/DiscordCoreAPI/vcpkg2/vcpkg install openssl:x64-osx + which g++ + ./vcpkg2/vcpkg install opus:x64-osx + ./vcpkg2/vcpkg install libsodium:x64-osx + ./vcpkg2/vcpkg install openssl:x64-osx - - name: Print failure log on failure - if: ${{ failure() }} - run: cat /Users/runner/work/DiscordCoreAPI/DiscordCoreAPI/vcpkg2/buildtrees/libsodium/autoconf-x64-osx-err.log + - name: Check if file exists (for debugging) + if: failure() + run: | + if [ -f /Users/runner/work/DiscordCoreAPI/DiscordCoreAPI/vcpkg2/buildtrees/libsodium/autoconf-x64-osx-err.log ]; then echo "File exists"; else echo "File does not exist"; fi + - name: Print file contents upon failure + if: failure() + run: | + echo "Command failed. Printing /Users/runner/work/DiscordCoreAPI/DiscordCoreAPI/vcpkg2/buildtrees/libsodium/autoconf-x64-osx-err.log contents:" + cat /Users/runner/work/DiscordCoreAPI/DiscordCoreAPI/vcpkg2/buildtrees/libsodium/autoconf-x64-osx-err.log || echo "File not found or empty" - name: Configure CMake working-directory: ./ run: | - cmake -S . -B ./Build -DCMAKE_CXX_COMPILER=/usr/local/opt/gcc@13/bin/g++-13 -DDEV=true -DDISCORDCOREAPI_TEST=true -DVCPKG_ROOT_DIR=./vcpkg2 + cmake -S . -B ./Build -DCMAKE_CXX_COMPILER=/usr/bin/g++-14 -DDEV=true -DDISCORDCOREAPI_TEST=true -DVCPKG_ROOT_DIR=/usr/local/share/vcpkg - name: Build the Test working-directory: ./Build diff --git a/.github/workflows/MSVC_2022-Windows.yml b/.github/workflows/MSVC-Windows.yml similarity index 95% rename from .github/workflows/MSVC_2022-Windows.yml rename to .github/workflows/MSVC-Windows.yml index 36b098405..e427a7477 100644 --- a/.github/workflows/MSVC_2022-Windows.yml +++ b/.github/workflows/MSVC-Windows.yml @@ -1,6 +1,7 @@ name: Build-and-Test-MSVC-Windows on: + workflow_dispatch: push: branches: - main @@ -18,8 +19,8 @@ jobs: std: [20] steps: - - uses: actions/checkout@v3 - + - uses: actions/checkout@v4 + - name: Update Vcpkg and install other dependencies. run: | cd C:/vcpkg diff --git a/CMake/BuildFeatureTester.bat b/CMake/BuildFeatureTester.bat new file mode 100644 index 000000000..62c7a1dd1 --- /dev/null +++ b/CMake/BuildFeatureTester.bat @@ -0,0 +1,2 @@ +"C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release +"C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" --build ./Build --config=Release \ No newline at end of file diff --git a/CMake/BuildFeatureTester.sh b/CMake/BuildFeatureTester.sh new file mode 100644 index 000000000..4cd8e7aed --- /dev/null +++ b/CMake/BuildFeatureTester.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cmake -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release +cmake --build ./Build --config=Release diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt new file mode 100644 index 000000000..d0d2561e7 --- /dev/null +++ b/CMake/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.10) +project(FeatureDetection LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) +# Add your source file(s) +add_executable(feature_detector main.cpp) diff --git a/CMake/DCADetectArchitecture.cmake b/CMake/DCADetectArchitecture.cmake index cf5355767..0a94a1ad6 100644 --- a/CMake/DCADetectArchitecture.cmake +++ b/CMake/DCADetectArchitecture.cmake @@ -1,120 +1,104 @@ -# MIT License -# -# Copyright (c) 2023 RealTimeChris -# -# 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. -# DCADetectArchitecture.cmake - Script for detecting the CPU architecture. -# Sept 18, 2023 +# JsonifierDetectArchitecture.cmake - Script for detecting the CPU architecture. +# MIT License +# Copyright (c) 2023 RealTimeChris # https://discordcoreapi.com -include(CheckCXXSourceRuns) -function(jsonifier_check_instruction_set INSTRUCTION_SET_NAME INSTRUCTION_SET_IN_FLAG INSTRUCTION_SET_OUT_FLAG INSTRUCTION_SET_INTRINSIC) - set(INSTRUCTION_SET_CODE " - #include - #include - - int32_t main() - { - ${INSTRUCTION_SET_INTRINSIC}; - return 0; - }") - - set(CMAKE_REQUIRED_FLAGS "${INSTRUCTION_SET_IN_FLAG}") - set(CHECK_RESULT_VAR "${INSTRUCTION_SET_NAME}") - CHECK_CXX_SOURCE_RUNS("${INSTRUCTION_SET_CODE}" "DiscordCoreAPI-${CHECK_RESULT_VAR}") - if(DiscordCoreAPI-${CHECK_RESULT_VAR}) - set(${INSTRUCTION_SET_NAME} "${INSTRUCTION_SET_OUT_FLAG}" PARENT_SCOPE) - list(APPEND JSONIFIER_CPU_INSTRUCTIONS "${INSTRUCTION_SET_NAME}") - string(REPLACE ";" "," JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS}") - set(JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS}" PARENT_SCOPE) - else() - message(STATUS "Instruction set ${INSTRUCTION_SET_NAME} not supported.") - return() +if (UNIX OR APPLE) + file(WRITE "${CMAKE_SOURCE_DIR}/CMake/BuildFeatureTester.sh" "#!/bin/bash +\"${CMAKE_COMMAND}\" -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} +\"${CMAKE_COMMAND}\" --build ./Build --config=Release") + execute_process( + COMMAND chmod +x "${CMAKE_SOURCE_DIR}/CMake/BuildFeatureTester.sh" + RESULT_VARIABLE CHMOD_RESULT + ) + if(NOT ${CHMOD_RESULT} EQUAL 0) + message(FATAL_ERROR "Failed to set executable permissions for BuildFeatureTester.sh") endif() -endfunction() - -set(INSTRUCTION_SET_NAMES "POPCNT" "LZCNT" "BMI" "BMI2" "AVX" "AVX2" "AVX512") -set(INSTRUCTION_SET_CODE - "auto result = _mm_popcnt_u64(uint64_t{})" - "auto result = _lzcnt_u64(int64_t{})" - "auto result = _blsr_u64(uint64_t{}).result = _tzcnt_u32(uint16_t{})" - "auto result = _pdep_u64(uint64_t{}, uint64_t{})" - "auto result = _mm_castsi128_pd(__m128i{}).auto result01 = _mm_setzero_si128()" - "auto result = _mm256_add_epi32(__m256i{}, __m256i{})" - "auto result = _mm_abs_epi64 (__m128i{}).auto result01 = _mm512_abs_epi16(__m512i{})" -) - -set(INDEX_SET "0" "1" "2" "3" "4" "5" "6") - -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - set(INSTRUCTION_SET_IN_FLAGS "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX2" "/arch:AVX512") - set(INSTRUCTION_SET_OUT_FLAGS "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX2" "/arch:AVX512") -else() - set(INSTRUCTION_SET_IN_FLAGS "-march=native" "-march=native" "-march=native" "-march=native" "-march=native" "-march=native" "-march=native") - set(INSTRUCTION_SET_OUT_FLAGS "-mpopcnt" "-mlzcnt" "-mbmi" "-mbmi2" "-mavx.-mpclmul" "-mavx2.-mpclmul" "-mavx512f.-mavx512bw.-mavx512vl.-mpclmul") + execute_process( + COMMAND "${CMAKE_SOURCE_DIR}/CMake/BuildFeatureTester.sh" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/CMake/" + ) + set(FEATURE_TESTER_FILE "${CMAKE_SOURCE_DIR}/CMake/Build/feature_detector") +elseif(WIN32) + file(WRITE "${CMAKE_SOURCE_DIR}/CMake/BuildFeatureTester.bat" "\"${CMAKE_COMMAND}\" -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release +\"${CMAKE_COMMAND}\" --build ./Build --config=Release") + execute_process( + COMMAND "${CMAKE_SOURCE_DIR}/CMake/BuildFeatureTester.bat" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/CMake/" + ) + set(FEATURE_TESTER_FILE "${CMAKE_SOURCE_DIR}/CMake/Build/Release/feature_detector.exe") endif() -set(CMAKE_REQUIRED_FLAGS_SAVE "${CMAKE_REQUIRED_FLAGS}") +execute_process( + COMMAND "${FEATURE_TESTER_FILE}" + RESULT_VARIABLE DCA_CPU_INSTRUCTIONS_NEW +) -if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386") OR ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")) +set(AVX_FLAG "") - foreach(CURRENT_INDEX IN LISTS INDEX_SET) - list(GET INSTRUCTION_SET_NAMES "${CURRENT_INDEX}" INSTRUCTION_SET_NAME) - list(GET INSTRUCTION_SET_CODE "${CURRENT_INDEX}" INSTRUCTION_SET_INTRINSIC) - list(GET INSTRUCTION_SET_IN_FLAGS "${CURRENT_INDEX}" INSTRUCTION_SET_IN_FLAG) - list(GET INSTRUCTION_SET_OUT_FLAGS "${CURRENT_INDEX}" INSTRUCTION_SET_OUT_FLAG) - string(REPLACE "." ";" INSTRUCTION_SET_OUT_FLAG "${INSTRUCTION_SET_OUT_FLAG}") - string(REPLACE "." ";" INSTRUCTION_SET_INTRINSIC "${INSTRUCTION_SET_INTRINSIC}") - jsonifier_check_instruction_set("${INSTRUCTION_SET_NAME}" "${INSTRUCTION_SET_IN_FLAG}" "${INSTRUCTION_SET_OUT_FLAG}" "${INSTRUCTION_SET_INTRINSIC}") - endforeach() +math(EXPR DCA_CPU_INSTRUCTIONS_NUMERIC "${DCA_CPU_INSTRUCTIONS_NEW}") +math(EXPR JSONIFIER_CPU_INSTRUCTIONS 0) - message(STATUS "Detected CPU Architecture: ${JSONIFIER_CPU_INSTRUCTIONS}") -else() - message(STATUS "SSE not supported by architecture ${CMAKE_SYSTEM_PROCESSOR}") -endif() - -set(AVX_FLAG) -set(JSONIFIER_CPU_INSTRUCTIONS 0) +function(check_instruction_set INSTRUCTION_SET_NAME INSTRUCTION_SET_FLAG INSTRUCTION_SET_NUMERIC_VALUE) + math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & ${INSTRUCTION_SET_NUMERIC_VALUE} )") + if(INSTRUCTION_PRESENT) + message(STATUS "Instruction Set Found: ${INSTRUCTION_SET_NAME}") + math(EXPR JSONIFIER_CPU_INSTRUCTIONS "( ${JSONIFIER_CPU_INSTRUCTIONS} | ${INSTRUCTION_SET_NUMERIC_VALUE} )") + set(AVX_FLAG "${AVX_FLAG};${INSTRUCTION_SET_FLAG}" PARENT_SCOPE) + endif() +endfunction() -if(NOT "${POPCNT}" STREQUAL "") - list(APPEND AVX_FLAG "${POPCNT}") +math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x1 )") +if(INSTRUCTION_PRESENT) math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 0" OUTPUT_FORMAT DECIMAL) endif() -if(NOT "${LZCNT}" STREQUAL "") - list(APPEND AVX_FLAG "${LZCNT}") +math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x2 )") +if(INSTRUCTION_PRESENT) math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 1" OUTPUT_FORMAT DECIMAL) endif() -if(NOT "${BMI}" STREQUAL "") - list(APPEND AVX_FLAG "${BMI}") +math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x4 )") +if(INSTRUCTION_PRESENT) math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 2" OUTPUT_FORMAT DECIMAL) endif() -if(NOT "${BMI2}" STREQUAL "") - list(APPEND AVX_FLAG "${BMI2}") +math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x8 )") +if(INSTRUCTION_PRESENT) math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 3" OUTPUT_FORMAT DECIMAL) endif() -if(NOT "${AVX512}" STREQUAL "") - list(APPEND AVX_FLAG "${AVX512}") + +math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x10 )") +if(INSTRUCTION_PRESENT) + math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 4" OUTPUT_FORMAT DECIMAL) +endif() +math(EXPR INSTRUCTION_PRESENT128 "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x20 )") +math(EXPR INSTRUCTION_PRESENT256 "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x40 )") +math(EXPR INSTRUCTION_PRESENT512 "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x80 )") +if(INSTRUCTION_PRESENT512) + math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 7" OUTPUT_FORMAT DECIMAL) +elseif(INSTRUCTION_PRESENT256) math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 6" OUTPUT_FORMAT DECIMAL) -elseif(NOT "${AVX2}" STREQUAL "") - list(APPEND AVX_FLAG "${AVX2}") +elseif(INSTRUCTION_PRESENT128) math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 5" OUTPUT_FORMAT DECIMAL) -elseif(NOT "${AVX}" STREQUAL "") - list(APPEND AVX_FLAG "${AVX}") - math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 4" OUTPUT_FORMAT DECIMAL) +endif() + +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + check_instruction_set("LzCnt" "" 0x1) + check_instruction_set("PopCnt" "" 0x2) + check_instruction_set("Bmi" "" 0x4) + check_instruction_set("Bmi2" "" 0x8) + check_instruction_set("Neon" "" 0x10) + check_instruction_set("Avx" "/arch:AVX" 0x20) + check_instruction_set("Avx2" "/arch:AVX2" 0x40) + check_instruction_set("Avx512" "/arch:AVX512" 0x80) +else() + check_instruction_set("LzCnt" "-mlzcnt" 0x1) + check_instruction_set("PopCnt" "-mpopcnt" 0x2) + check_instruction_set("Bmi" "-mbmi" 0x4) + check_instruction_set("Bmi2" "-mbmi2" 0x8) + check_instruction_set("Neon" "" 0x10) + check_instruction_set("Avx" "-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x20) + check_instruction_set("Avx2" "-mavx2;-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x40) + check_instruction_set("Avx512" "-mavx512f;-mavx2;-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x80) endif() -set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_SAVE}") \ No newline at end of file +set(AVX_FLAG "${AVX_FLAG}" CACHE STRING "AVX flags" FORCE) +set(JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS}" CACHE STRING "CPU Instruction Sets" FORCE) diff --git a/CMake/main.cpp b/CMake/main.cpp new file mode 100644 index 000000000..1943a5f86 --- /dev/null +++ b/CMake/main.cpp @@ -0,0 +1,184 @@ +#include +#include +#include +#include + +#if defined(_MSC_VER) + #include +#elif defined(HAVE_GCC_GET_CPUID) && defined(USE_GCC_GET_CPUID) + #include +#endif + +enum instruction_set { + DEFAULT = 0x0, + LZCNT = 0x1, + POPCNT = 0x2, + BMI1 = 0x4, + BMI2 = 0x8, + NEON = 0x10, + AVX = 0x20, + AVX2 = 0x40, + AVX512F = 0x80, +}; + +namespace { + constexpr uint32_t cpuidAvx2Bit = 1ul << 5; + constexpr uint32_t cpuidBmi1Bit = 1ul << 3; + constexpr uint32_t cpuidBmi2Bit = 1ul << 8; + constexpr uint32_t cpuidAvx512Bit = 1ul << 16; + constexpr uint64_t cpuidAvx256Saved = 1ull << 2; + constexpr uint64_t cpuidAvx512Saved = 7ull << 5; + constexpr uint32_t cpuidOsxSave = (1ul << 26) | (1ul << 27); + constexpr uint32_t cpuidLzcntBit = 1ul << 5; + constexpr uint32_t cpuidPopcntBit = 1ul << 23; +} + +#if defined(__x86_64__) || defined(_M_AMD64) +static inline void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx); +inline static uint64_t xgetbv(); +#endif + +static void getCPUBrandString(char* brand) { +#if defined(__x86_64__) || defined(_M_AMD64) + uint32_t regs[12]; + regs[0] = 0x80000000; + cpuid(regs, regs + 1, regs + 2, regs + 3); + if (regs[0] < 0x80000004) + return; + regs[0] = 0x80000002; + cpuid(regs, regs + 1, regs + 2, regs + 3); + regs[4] = 0x80000003; + cpuid(regs + 4, regs + 5, regs + 6, regs + 7); + regs[8] = 0x80000004; + cpuid(regs + 8, regs + 9, regs + 10, regs + 11); + + memcpy(brand, regs, sizeof(regs)); +#endif +} + +void printCPUInfo(uint32_t supportedISA) { +#if defined(__x86_64__) || defined(_M_AMD64) + char brand[49] = { 0 }; + getCPUBrandString(brand); + std::cout << "CPU Brand: " << brand << "\n"; +#endif +} + +#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) + +inline static uint32_t detectSupportedArchitectures() { + return instruction_set::NEON; +} + +#elif defined(__x86_64__) || defined(_M_AMD64) + +static inline void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) { + #if defined(_MSC_VER) + int32_t cpuInfo[4]; + __cpuidex(cpuInfo, *eax, *ecx); + *eax = cpuInfo[0]; + *ebx = cpuInfo[1]; + *ecx = cpuInfo[2]; + *edx = cpuInfo[3]; + #elif defined(HAVE_GCC_GET_CPUID) && defined(USE_GCC_GET_CPUID) + uint32_t level = *eax; + __get_cpuid(level, eax, ebx, ecx, edx); + #else + uint32_t a = *eax, b, c = *ecx, d; + asm volatile("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "a"(a), "c"(c)); + *eax = a; + *ebx = b; + *ecx = c; + *edx = d; + #endif +} + +inline static uint64_t xgetbv() { + #if defined(_MSC_VER) + return _xgetbv(0); + #else + uint32_t eax, edx; + asm volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0)); + return (( uint64_t )edx << 32) | eax; + #endif +} + +inline static uint32_t detectSupportedArchitectures() { + std::uint32_t eax = 0; + std::uint32_t ebx = 0; + std::uint32_t ecx = 0; + std::uint32_t edx = 0; + std::uint32_t hostIsa = 0x0; + + eax = 0x1; + ecx = 0x0; + cpuid(&eax, &ebx, &ecx, &edx); + + if (ecx & cpuidLzcntBit) { + hostIsa |= instruction_set::LZCNT; + } + + if (ecx & cpuidPopcntBit) { + hostIsa |= instruction_set::POPCNT; + } + + if ((ecx & cpuidOsxSave) != cpuidOsxSave) { + return hostIsa; + } + + uint64_t xcr0 = xgetbv(); + + if ((xcr0 & cpuidAvx256Saved) == 0) { + return hostIsa; + } + + if (ecx & cpuidAvx256Saved) { + hostIsa |= instruction_set::AVX; + } + + eax = 0x7; + ecx = 0x0; + cpuid(&eax, &ebx, &ecx, &edx); + + if (ebx & cpuidAvx2Bit) { + hostIsa |= instruction_set::AVX2; + } + + if (ebx & cpuidBmi1Bit) { + hostIsa |= instruction_set::BMI1; + } + + if (ebx & cpuidBmi2Bit) { + hostIsa |= instruction_set::BMI2; + } + + if (!((xcr0 & cpuidAvx512Saved) == cpuidAvx512Saved)) { + return hostIsa; + } + + if (ebx & cpuidAvx512Bit) { + hostIsa |= instruction_set::AVX512F; + } + + return hostIsa; +} + +#elif defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) + +inline static uint32_t detectSupportedArchitectures() { + return instruction_set::NEON; +} + +#else + +inline static uint32_t detectSupportedArchitectures() { + return instruction_set::DEFAULT; +} + +#endif + +int32_t main() { + const auto supportedISA = detectSupportedArchitectures(); + printCPUInfo(supportedISA); + return supportedISA; +} \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 8e73c977e..d6fc0a4b2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,61 +1,63 @@ { "version": 3, - "configurePresets": [ - { - "name": "windows-base", - "hidden": true, - "generator": "Visual Studio 17 2022", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "installDir": "${sourceDir}/out/install/${presetName}", - "cacheVariables": { - "CMAKE_C_COMPILER": "cl.exe", - "CMAKE_CXX_COMPILER": "cl.exe" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - }, - { - "name": "x64-debug", - "displayName": "x64 Debug", - "inherits": "windows-base", - "architecture": { - "value": "x64", - "strategy": "external" - }, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "x64-release", - "displayName": "x64 Release", - "inherits": "x64-debug", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - }, - { - "name": "x86-debug", - "displayName": "x86 Debug", - "inherits": "windows-base", - "architecture": { - "value": "x86", - "strategy": "external" - }, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "x86-release", - "displayName": "x86 Release", - "inherits": "x86-debug", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - } - ] + "configurePresets": [ + { + "name": "windows-base", + "hidden": true, + "generator": "Visual Studio 17 2022", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "x64-debug", + "displayName": "x64 Debug", + "inherits": "windows-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x64-release", + "displayName": "x64 Release", + "inherits": "x64-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "x64-debug-dev", + "displayName": "x64 Debug Dev", + "inherits": "windows-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "DEV": true + } + }, + { + "name": "x64-release-dev", + "displayName": "x64 Release Dev", + "inherits": "x64-debug-dev", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "DEV": true + } + } + ] } diff --git a/Include/discordcoreapi/DiscordCoreClient.hpp b/Include/discordcoreapi/DiscordCoreClient.hpp index 6cc140cc2..2ae395e78 100644 --- a/Include/discordcoreapi/DiscordCoreClient.hpp +++ b/Include/discordcoreapi/DiscordCoreClient.hpp @@ -171,8 +171,8 @@ namespace discord_core_api { /// @param commandData a create_application_command_data structure describing the current function. /// @param alwaysRegister whether or not it gets registered every time the bot boots up, or only when it's missing from the bot's list of /// registered commands. - void registerFunction(const jsonifier::vector& functionNames, unique_ptr baseFunction, create_application_command_data commandData, - bool alwaysRegister = false); + void registerFunction(const jsonifier::vector& functionNames, unique_ptr&& baseFunction, + const create_application_command_data& commandData, bool alwaysRegister = false); /// @brief For collecting a reference to the command_controller. /// @return command_controller& a reference to the command_controller. diff --git a/Include/discordcoreapi/FoundationEntities.hpp b/Include/discordcoreapi/FoundationEntities.hpp index 07ba6791e..ce54f4108 100644 --- a/Include/discordcoreapi/FoundationEntities.hpp +++ b/Include/discordcoreapi/FoundationEntities.hpp @@ -50,14 +50,14 @@ namespace discord_core_api { }; struct connect_properties { - static constexpr jsonifier::string_view browser{ "DiscordCoreAPI" }; - static constexpr jsonifier::string_view device{ "DiscordCoreAPI" }; + jsonifier::string_view browser{ "DiscordCoreAPI" }; + jsonifier::string_view device{ "DiscordCoreAPI" }; #if defined _WIN32 - static constexpr jsonifier::string_view os{ "Windows" }; + jsonifier::string_view os{ "Windows" }; #elif __linux__ - static constexpr jsonifier::string_view os{ "Linux" }; + jsonifier::string_view os{ "Linux" }; #else - static constexpr jsonifier::string_view os{ "MacOs" }; + jsonifier::string_view os{ "MacOs" }; #endif }; @@ -79,8 +79,8 @@ namespace discord_core_api { }; struct voice_socket_protocol_payload_data { - static constexpr jsonifier::string_view protocol{ "udp" }; voice_socket_protocol_payload_data_data data{}; + jsonifier::string_view protocol{ "udp" }; }; struct voice_identify_data { @@ -435,7 +435,7 @@ namespace discord_core_api { template class get_user_image_url { public: - template DCA_INLINE jsonifier::string getUserImageUrl() const { + template DCA_INLINE jsonifier::string getUserImageUrl() const { jsonifier::string baseUrl{ "https://cdn.discordapp.com/" }; switch (type) { case user_image_types::Banner: { @@ -661,50 +661,50 @@ namespace discord_core_api { /// @param authorName the author's name. /// @param authorAvatarUrl the url to their avatar. /// @return embed_data& A reference to this embed_data instance. - embed_data& setAuthor(jsonifier::string_view authorName, jsonifier::string_view authorAvatarUrl = ""); + embed_data& setAuthor(const jsonifier::string& authorName, const jsonifier::string& authorAvatarUrl = ""); /// @brief Sets the footer's values for the embed. /// @param footerText the footer's text. /// @param footerIconUrlText url to the footer's icon. /// @return embed_data& A reference to this embed_data instance. - embed_data& setFooter(jsonifier::string_view footerText, jsonifier::string_view footerIconUrlText = ""); + embed_data& setFooter(const jsonifier::string& footerText, const jsonifier::string& footerIconUrlText = ""); /// @brief Sets the timeStamp on the embed. /// @param timeStamp the timeStamp to be set. /// @return embed_data& A reference to this embed_data instance. - embed_data& setTimeStamp(jsonifier::string_view timeStamp); + embed_data& setTimeStamp(const jsonifier::string& timeStamp); /// @brief Adds a field to the embed. /// @param name the title of the embed field. /// @param value the contents of the embed field. /// @param Inline is it DCA_INLINE with the rest of the fields on the embed? /// @return embed_data& A reference to this embed_data instance. - embed_data& addField(jsonifier::string_view name, jsonifier::string_view value, bool Inline = true); + embed_data& addField(const jsonifier::string& name, const jsonifier::string& value, bool Inline = true); /// @brief Sets the description (the main contents) of the embed. /// @param descriptionNew the contents of the description to set. /// @return embed_data& A reference to this embed_data instance. - embed_data& setDescription(jsonifier::string_view descriptionNew); + embed_data& setDescription(const jsonifier::string& descriptionNew); /// @brief Sets the color of the embed, by applying a hex-color value. /// @param hexColorValueNew a string containing a hex-number value (between 0x00 0xFFFFFF). /// @return embed_data& A reference to this embed_data instance. - embed_data& setColor(jsonifier::string_view hexColorValueNew); + embed_data& setColor(const jsonifier::string& hexColorValueNew); /// @brief Sets the thumbnail of the embed. /// @param thumbnailUrl the url to the thumbnail to be used. /// @return embed_data& A reference to this embed_data instance. - embed_data& setThumbnail(jsonifier::string_view thumbnailUrl); + embed_data& setThumbnail(const jsonifier::string& thumbnailUrl); /// @brief Sets the title of the embed. /// @param titleNew a string containing the desired title. /// @return embed_data& A reference to this embed_data instance. - embed_data& setTitle(jsonifier::string_view titleNew); + embed_data& setTitle(const jsonifier::string& titleNew); /// @brief Sets the image of the embed. /// @param imageUrl the url of the image to be set on the embed. /// @return embed_data& A reference to this embed_data instance. - embed_data& setImage(jsonifier::string_view imageUrl); + embed_data& setImage(const jsonifier::string& imageUrl); }; /// @brief Message reference data. @@ -2728,8 +2728,8 @@ namespace discord_core_api { friend struct delete_follow_up_message_data; friend struct interaction_response_data; - friend DiscordCoreAPI_Dll move_through_message_pages_data moveThroughMessagePages(jsonifier::string_view userID, input_event_data originalEvent, uint32_t currentPageIndex, - const jsonifier::vector& messageEmbeds, bool deleteAfter, uint32_t waitForMaxMs, bool returnResult); + friend DiscordCoreAPI_Dll move_through_message_pages_data moveThroughMessagePages(const jsonifier::string& userID, input_event_data originalEvent, + uint32_t currentPageIndex, const jsonifier::vector& messageEmbeds, bool deleteAfter, uint32_t waitForMaxMs, bool returnResult); friend class create_ephemeral_interaction_response_data; friend class create_deferred_interaction_response_data; @@ -2764,8 +2764,8 @@ namespace discord_core_api { /// @param emojiId an emoji id, if desired. /// @param url a url, if applicable. /// @return respond_to_input_event_data& a reference to this data structure. - respond_to_input_event_data& addButton(bool disabled, jsonifier::string_view customIdNew, jsonifier::string_view buttonLabel, button_style buttonStyle, - jsonifier::string_view emojiName = "", snowflake emojiId = snowflake{}, jsonifier::string_view url = ""); + respond_to_input_event_data& addButton(bool disabled, const jsonifier::string& customIdNew, const jsonifier::string& buttonLabel, button_style buttonStyle, + const jsonifier::string& emojiName = "", snowflake emojiId = snowflake{}, const jsonifier::string& url = ""); /// @brief Adds a select-menu to the response message_data. /// @param disabled whether the select-menu is active or not. @@ -2777,8 +2777,8 @@ namespace discord_core_api { /// @param type the type of select-menu that this is. /// @param channelTypes types of channels that can be accepted if this is of the type channel_type. /// @return respond_to_input_event_data& a reference to this data structure. - respond_to_input_event_data& addSelectMenu(bool disabled, jsonifier::string_view customIdNew, const jsonifier::vector& options, - jsonifier::string_view placeholder, uint64_t maxValues, uint64_t minValues, select_menu_type type, + respond_to_input_event_data& addSelectMenu(bool disabled, const jsonifier::string& customIdNew, const jsonifier::vector& options, + const jsonifier::string& placeholder, uint64_t maxValues, uint64_t minValues, select_menu_type type, jsonifier::vector channelTypes = jsonifier::vector{}); /// @brief Adds a modal to the response message_data. @@ -2793,9 +2793,9 @@ namespace discord_core_api { /// @param label a label for the modal. /// @param placeholder a placeholder for the modal. /// @return respond_to_input_event_data& a reference to this data structure. - respond_to_input_event_data& addModal(jsonifier::string_view topTitleNew, jsonifier::string_view topCustomIdNew, jsonifier::string_view titleNew, - jsonifier::string_view customIdNew, bool required, uint64_t minLength, uint64_t maxLength, text_input_style inputStyle, jsonifier::string_view label = "", - jsonifier::string_view placeholder = ""); + respond_to_input_event_data& addModal(const jsonifier::string& topTitleNew, const jsonifier::string& topCustomIdNew, const jsonifier::string& titleNew, + const jsonifier::string& customIdNew, bool required, uint64_t minLength, uint64_t maxLength, text_input_style inputStyle, const jsonifier::string& label = "", + const jsonifier::string& placeholder = ""); /// @brief Adds a file to the current collection of files for this message response. /// @param theFile the file to be added. @@ -2805,7 +2805,7 @@ namespace discord_core_api { /// @brief For setting the allowable mentions in a response. /// @param dataPackage an allowed_mentions_data structure. /// @return respond_to_input_event_data& a reference to this data structure. - respond_to_input_event_data& addAllowedMentions(const allowed_mentions_data dataPackage); + respond_to_input_event_data& addAllowedMentions(const allowed_mentions_data& dataPackage); /// @brief For setting the type of response to make. /// @param typeNew an input_event_response_type. @@ -2815,7 +2815,7 @@ namespace discord_core_api { /// @brief For setting the components in a response. /// @param dataPackage an action_row_data structure. /// @return respond_to_input_event_data& a reference to this data structure. - respond_to_input_event_data& addComponentRow(const action_row_data dataPackage); + respond_to_input_event_data& addComponentRow(const action_row_data& dataPackage); /// @brief For setting the embeds in a response. /// @param dataPackage an embed_data structure. @@ -2825,7 +2825,7 @@ namespace discord_core_api { /// @brief For setting the message content in a response. /// @param dataPackage a string, containing the content. /// @return respond_to_input_event_data& a reference to this data structure. - respond_to_input_event_data& addContent(jsonifier::string_view dataPackage); + respond_to_input_event_data& addContent(const jsonifier::string& dataPackage); /// @brief For setting the tts status of a response. /// @param enabledTTs a bool. @@ -2837,8 +2837,8 @@ namespace discord_core_api { /// @param theName a string for the name of the choice. /// @param theNameLocalizations a unordered_map for the name localizations. /// @return respond_to_input_event_data& a reference to this data structure. - respond_to_input_event_data& setAutoCompleteChoice(discord_core_internal::etf_serializer value, jsonifier::string_view theName, - unordered_map theNameLocalizations); + respond_to_input_event_data& setAutoCompleteChoice(discord_core_internal::etf_serializer value, const jsonifier::string& theName, + const unordered_map& theNameLocalizations); /// @brief For setting the direct-message_data user target of a response. /// @param targetUserIdNew a string, containing the target user_data's id. @@ -2879,8 +2879,8 @@ namespace discord_core_api { /// @param emojiId an emoji id, if desired. /// @param url a url, if applicable. /// @return message_response_base& a reference to this data structure. - message_response_base& addButton(bool disabled, jsonifier::string_view customIdNew, jsonifier::string_view buttonLabel, button_style buttonStyle, - jsonifier::string_view emojiName = "", snowflake emojiId = snowflake{}, jsonifier::string_view url = ""); + message_response_base& addButton(bool disabled, const jsonifier::string& customIdNew, const jsonifier::string& buttonLabel, button_style buttonStyle, + const jsonifier::string& emojiName = "", snowflake emojiId = snowflake{}, const jsonifier::string& url = ""); /// @brief Adds a select-menu to the response message_data. /// @param disabled whether the select-menu is active or not. @@ -2892,8 +2892,9 @@ namespace discord_core_api { /// @param type the type of select-menu that this is. /// @param channelTypes types of channels that can be accepted if this is of the type channel_type. /// @return respond_to_input_event_data& a reference to this data structure. - message_response_base& addSelectMenu(bool disabled, jsonifier::string_view customIdNew, jsonifier::vector options, jsonifier::string_view placeholder, - uint64_t maxValues, uint64_t minValues, select_menu_type type, jsonifier::vector channelTypes = jsonifier::vector{}); + message_response_base& addSelectMenu(bool disabled, const jsonifier::string& customIdNew, const jsonifier::vector& options, + const jsonifier::string& placeholder, uint64_t maxValues, uint64_t minValues, select_menu_type type, + jsonifier::vector channelTypes = jsonifier::vector{}); /// @brief Adds a modal to the response message_data. /// @param topTitleNew a title for the modal. @@ -2907,34 +2908,34 @@ namespace discord_core_api { /// @param label a label for the modal. /// @param placeholder a placeholder for the modal. /// @return message_response_base& a reference to this data structure. - message_response_base& addModal(jsonifier::string_view topTitleNew, jsonifier::string_view topCustomIdNew, jsonifier::string_view titleNew, - jsonifier::string_view customIdNew, bool required, uint64_t minLength, uint64_t maxLength, text_input_style inputStyle, jsonifier::string_view label = "", - jsonifier::string_view placeholder = ""); + message_response_base& addModal(const jsonifier::string& topTitleNew, const jsonifier::string& topCustomIdNew, const jsonifier::string& titleNew, + const jsonifier::string& customIdNew, bool required, uint64_t minLength, uint64_t maxLength, text_input_style inputStyle, const jsonifier::string& label = "", + const jsonifier::string& placeholder = ""); /// @brief Adds a file to the current collection of files for this message response. /// @param theFile the file to be added. /// @return message_response_base& a reference to this data structure. - message_response_base& addFile(file theFile); + message_response_base& addFile(const file& theFile); /// @brief For setting the allowable mentions in a response. /// @param dataPackage an allowed_mentions_data structure. /// @return message_response_base& a reference to this data structure. - message_response_base& addAllowedMentions(const allowed_mentions_data dataPackage); + message_response_base& addAllowedMentions(const allowed_mentions_data& dataPackage); /// @brief For setting the components in a response. /// @param dataPackage an action_row_data structure. /// @return message_response_base& a reference to this data structure. - message_response_base& addComponentRow(const action_row_data dataPackage); + message_response_base& addComponentRow(const action_row_data& dataPackage); /// @brief For setting the embeds in a response. /// @param dataPackage an embed_data structure. /// @return message_response_base& a reference to this data structure. - message_response_base& addMessageEmbed(const embed_data dataPackage); + message_response_base& addMessageEmbed(const embed_data& dataPackage); /// @brief For setting the message content in a response. /// @param dataPackage a string, containing the content. /// @return message_response_base& a reference to this data structure. - message_response_base& addContent(jsonifier::string_view dataPackage); + message_response_base& addContent(const jsonifier::string& dataPackage); /// @brief For setting the tts status of a response. /// @param enabledTTs a bool. diff --git a/Include/discordcoreapi/Index.hpp b/Include/discordcoreapi/Index.hpp index 50bbc9601..aa7723cfc 100644 --- a/Include/discordcoreapi/Index.hpp +++ b/Include/discordcoreapi/Index.hpp @@ -29,10 +29,5 @@ /// \file Index.hpp #pragma once -#if defined(JSONIFIER_CPU_INSTRUCTIONS) - #undef JSONIFIER_CPU_INSTRUCTIONS - #define JSONIFIER_CPU_INSTRUCTIONS 0 -#endif - #include #include diff --git a/Include/discordcoreapi/JsonSpecializations.hpp b/Include/discordcoreapi/JsonSpecializations.hpp index a0a31eb7a..9aafd603b 100644 --- a/Include/discordcoreapi/JsonSpecializations.hpp +++ b/Include/discordcoreapi/JsonSpecializations.hpp @@ -65,47 +65,53 @@ namespace discord_core_api { namespace jsonifier_internal { template - concept snowflake_t = std::same_as>; + concept snowflake_t = std::same_as>; - template struct serialize_impl { - template DCA_INLINE static void impl(value_type&& value, iterator_type&& iter, uint64_t& index) { + template + struct serialize_impl { + template + DCA_INLINE static void impl(value_type&& value, buffer_type&& buffer, index_type&& index) { jsonifier::string newString{ static_cast(value) }; - serializer::impl(newString, iter, index); + serialize_impl::impl(newString, buffer, index); } }; - template struct parse_impl { - template DCA_INLINE static void impl(value_type&& value, iterator&& iter) { + template struct parse_impl { + template + DCA_INLINE static void impl(value_type&& value, iterator& iter, iterator& end) { jsonifier::raw_json_data newString{}; - parser::impl(newString, iter); + parse_impl::impl(newString, iter, end); if (newString.getType() == jsonifier::json_type::String) { value = newString.operator jsonifier::string(); } else { value = newString.operator uint64_t(); } - }; + } }; template - concept time_stamp_t = std::same_as>; + concept time_stamp_t = std::same_as>; - template struct serialize_impl { - template DCA_INLINE static void impl(value_type&& value, iterator_type&& iter, uint64_t& index) { + template + struct serialize_impl { + template + DCA_INLINE static void impl(value_type&& value, buffer_type&& buffer, index_type&& index) { jsonifier::string newString{ static_cast(value) }; - serializer::impl(newString, iter, index); + serialize_impl::impl(newString, buffer, index); } }; - template struct parse_impl { - template DCA_INLINE static void impl(value_type&& value, iterator_type&& iter) { + template struct parse_impl { + template + DCA_INLINE static void impl(value_type&& value, iterator& iter, iterator& end) { jsonifier::raw_json_data newString{}; - parser::impl(newString, iter); + parse_impl::impl(newString, iter, end); if (newString.getType() == jsonifier::json_type::String) { value = newString.operator jsonifier::string(); } else { value = newString.operator uint64_t(); } - }; + } }; } diff --git a/Include/discordcoreapi/Utilities/Base.hpp b/Include/discordcoreapi/Utilities/Base.hpp index 478501964..42d15ce1d 100644 --- a/Include/discordcoreapi/Utilities/Base.hpp +++ b/Include/discordcoreapi/Utilities/Base.hpp @@ -52,6 +52,31 @@ #define DCA_INLINE inline #endif +#if !defined(DCA_CPU_INSTRUCTIONS) + #define DCA_CPU_INSTRUCTIONS 0 +#endif + +#if !defined(DCA_CHECK_FOR_INSTRUCTION) + #define DCA_CHECK_FOR_INSTRUCTION(x) (DCA_CPU_INSTRUCTIONS & x) +#endif + +#if !defined(DCA_CHECK_FOR_AVX) + #define DCA_CHECK_FOR_AVX(x) (DCA_CPU_INSTRUCTIONS >= x) +#endif + +#if !defined(DCA_NEON) + #define DCA_NEON (1 << 4) +#endif +#if !defined(DCA_AVX) + #define DCA_AVX (1 << 5) +#endif +#if !defined(DCA_AVX2) + #define DCA_AVX2 (1 << 6) +#endif +#if !defined(DCA_AVX512) + #define DCA_AVX512 (1 << 7) +#endif + #if defined _WIN32 #if !defined DiscordCoreAPI_EXPORTS_NOPE #if defined DiscordCoreAPI_EXPORTS @@ -414,9 +439,8 @@ namespace discord_core_api { /// @return true if the specified time has elapsed, otherwise false. DCA_INLINE bool hasTimeElapsed(int64_t days, int64_t hours, int64_t minutes) const { int64_t startTimeRaw{ static_cast(convertTimeStampToTimeUnits(static_cast(*static_cast(this)))) }; - startTimeRaw = - std::chrono::current_zone()->to_sys(std::chrono::local_time(std::chrono::milliseconds{ startTimeRaw })).time_since_epoch().count(); - auto currentTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + startTimeRaw = std::chrono::local_time(std::chrono::milliseconds{ startTimeRaw }).time_since_epoch().count(); + auto currentTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); auto targetElapsedTime = ((static_cast(days) * secondsPerDay) + ((static_cast(hours)) * secondsPerHour) + (static_cast(minutes) * secondsPerMinute)) * 1000LL; auto actualElapsedTime = currentTime - startTimeRaw; diff --git a/Include/discordcoreapi/Utilities/Etf.hpp b/Include/discordcoreapi/Utilities/Etf.hpp index f1ea2fafb..6540805e1 100644 --- a/Include/discordcoreapi/Utilities/Etf.hpp +++ b/Include/discordcoreapi/Utilities/Etf.hpp @@ -208,7 +208,7 @@ namespace discord_core_api { writeCharacters("null"); return; } else if (length == 4 && stringNew[0] == 't' && stringNew[1] == 'r' && stringNew[2] == 'u' && stringNew[3] == 'e') { - writeCharacters("True"); + writeCharacters("true"); return; } else if (length == 5 && stringNew[0] == 'f' && stringNew[1] == 'a' && stringNew[2] == 'l' && stringNew[3] == 's' && stringNew[4] == 'e') { writeCharacters("false"); @@ -454,8 +454,8 @@ namespace discord_core_api { /// @brief Concept for array types excluding etf_serializer. template - concept array_t = jsonifier::concepts::range && jsonifier::concepts::has_resize> && - jsonifier::concepts::has_emplace_back> && jsonifier::concepts::vector_subscriptable> && + concept array_t = jsonifier::concepts::range && jsonifier::concepts::has_resize> && + jsonifier::concepts::has_emplace_back> && jsonifier::concepts::vector_subscriptable> && requires(value_type&& data) { typename value_type::value_type; }; /// @brief Concept for object (associative container) types excluding etf_serializer. @@ -609,12 +609,12 @@ namespace discord_core_api { *this = str; } - template DCA_INLINE etf_serializer& operator=(value_type&& data) { + template DCA_INLINE etf_serializer& operator=(value_type&& data) { setValue(std::forward(data)); return *this; } - template DCA_INLINE etf_serializer(value_type&& data) { + template DCA_INLINE etf_serializer(value_type&& data) { *this = std::forward(data); } @@ -1083,49 +1083,49 @@ namespace discord_core_api { case json_type::object_t: { allocator alloc{}; alloc.destroy(objectValue); - alloc.deallocate(static_cast(objectValue), 1); + alloc.deallocate(static_cast(objectValue)); objectValue = nullptr; break; } case json_type::array_t: { allocator alloc{}; alloc.destroy(arrayValue); - alloc.deallocate(static_cast(arrayValue), 1); + alloc.deallocate(static_cast(arrayValue)); arrayValue = nullptr; break; } case json_type::string_t: { allocator alloc{}; alloc.destroy(stringValue); - alloc.deallocate(static_cast(stringValue), 1); + alloc.deallocate(static_cast(stringValue)); stringValue = nullptr; break; } case json_type::float_t: { allocator alloc{}; alloc.destroy(floatValue); - alloc.deallocate(static_cast(floatValue), 1); + alloc.deallocate(static_cast(floatValue)); floatValue = nullptr; break; } case json_type::uint_t: { allocator alloc{}; alloc.destroy(uintValue); - alloc.deallocate(static_cast(uintValue), 1); + alloc.deallocate(static_cast(uintValue)); uintValue = nullptr; break; } case json_type::int_t: { allocator alloc{}; alloc.destroy(intValue); - alloc.deallocate(static_cast(intValue), 1); + alloc.deallocate(static_cast(intValue)); intValue = nullptr; break; } case json_type::bool_t: { allocator alloc{}; alloc.destroy(boolValue); - alloc.deallocate(static_cast(boolValue), 1); + alloc.deallocate(static_cast(boolValue)); boolValue = nullptr; break; } diff --git a/Include/discordcoreapi/Utilities/Hash.hpp b/Include/discordcoreapi/Utilities/Hash.hpp index 90b05366c..108b074da 100644 --- a/Include/discordcoreapi/Utilities/Hash.hpp +++ b/Include/discordcoreapi/Utilities/Hash.hpp @@ -167,12 +167,6 @@ namespace discord_core_api { template struct key_accessor; - template struct key_accessor { - DCA_INLINE static uint64_t getHashKey(const value_type& other) { - return key_hasher::getHashKey(other); - } - }; - template struct key_accessor { DCA_INLINE static uint64_t getHashKey(const value_type& other) { return key_hasher::getHashKey(other); diff --git a/Include/discordcoreapi/Utilities/HttpsClient.hpp b/Include/discordcoreapi/Utilities/HttpsClient.hpp index 9a4049d8f..9366c97ae 100644 --- a/Include/discordcoreapi/Utilities/HttpsClient.hpp +++ b/Include/discordcoreapi/Utilities/HttpsClient.hpp @@ -251,7 +251,7 @@ namespace discord_core_api { https_client(jsonifier::string_view botTokenNew); template void getParseErrors(jsonifier::jsonifier_core& parser, value_type& value, string_type& stringNew) { - parser.parseJson(value, parser.minify(parser.prettify(stringNew))); + parser.parseJson(value, parser.minifyJson(parser.prettifyJson(stringNew))); if (auto result = parser.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); diff --git a/Include/discordcoreapi/Utilities/ISA/AVX.hpp b/Include/discordcoreapi/Utilities/ISA/AVX.hpp index b1970071f..0fccf4187 100644 --- a/Include/discordcoreapi/Utilities/ISA/AVX.hpp +++ b/Include/discordcoreapi/Utilities/ISA/AVX.hpp @@ -31,7 +31,7 @@ #include -#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX) && !JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX2) && !JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512) +#if DCA_CHECK_FOR_INSTRUCTION(DCA_AVX) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512) #include #include diff --git a/Include/discordcoreapi/Utilities/ISA/AVX2.hpp b/Include/discordcoreapi/Utilities/ISA/AVX2.hpp index b613694fe..24a68dd96 100644 --- a/Include/discordcoreapi/Utilities/ISA/AVX2.hpp +++ b/Include/discordcoreapi/Utilities/ISA/AVX2.hpp @@ -31,7 +31,7 @@ #include -#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX2) && !JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX) && !JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512) +#if DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512) #include #include diff --git a/Include/discordcoreapi/Utilities/ISA/AVX512.hpp b/Include/discordcoreapi/Utilities/ISA/AVX512.hpp index fac140cfa..487bce979 100644 --- a/Include/discordcoreapi/Utilities/ISA/AVX512.hpp +++ b/Include/discordcoreapi/Utilities/ISA/AVX512.hpp @@ -32,7 +32,7 @@ #include -#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512) && !JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX) && !JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX2) +#if DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2) #include #include diff --git a/Include/discordcoreapi/Utilities/ISA/Fallback.hpp b/Include/discordcoreapi/Utilities/ISA/Fallback.hpp index fda5dfc28..73113acb8 100644 --- a/Include/discordcoreapi/Utilities/ISA/Fallback.hpp +++ b/Include/discordcoreapi/Utilities/ISA/Fallback.hpp @@ -31,7 +31,7 @@ #include -#if (!JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX)) && (!JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX2)) && (!JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512)) +#if (!DCA_CHECK_FOR_INSTRUCTION(DCA_AVX)) && (!DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2)) && (!DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512)) #include #include diff --git a/Include/discordcoreapi/Utilities/ISA/Neon.hpp b/Include/discordcoreapi/Utilities/ISA/Neon.hpp new file mode 100644 index 000000000..34004bed1 --- /dev/null +++ b/Include/discordcoreapi/Utilities/ISA/Neon.hpp @@ -0,0 +1,103 @@ +/* + MIT License + + DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines. + + Copyright 2022, 2023 Chris M. (RealTimeChris) + + 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. +*/ +/// AVX.hpp - Header for the AVX instruction set. +/// Nov 8, 2021 +/// https://discordcoreapi.com +/// \file AVX.hpp +#pragma once + +#include + +#if DCA_CHECK_FOR_INSTRUCTION(DCA_NEON) + +#include + +namespace discord_core_api { + + namespace discord_core_internal { + + using neon_float = float32x4_t ; + + // @brief A class for audio mixing operations using ARM NEON instructions. + class audio_mixer { + public: + // @brief The number of 32-bit values per cpu register. + static constexpr int32_t byteBlocksPerRegister{ 4 }; + + // @brief Collect a single register worth of data from dataIn, apply gain and increment, and store the result in dataOut. This version uses NEON instructions. + // @param dataIn pointer to the input array of int32_t values. + // @param dataOut pointer to the output array of int16_t values. + // @param currentGain the gain to be applied to the elements. + // @param increment the increment value to be added to each element. + inline void collectSingleRegister(const int32_t* dataIn, int16_t* dataOut, const float currentGain, const float increment) { + neon_float currentSamples = + vmulq_f32(gatherValues(dataIn), vmlaq_f32(vdupq_n_f32(currentGain), vdupq_n_f32(increment), vcombine_f32(vcreate_f32(0x00000001), vcreate_f32(0x00000002)))); + + currentSamples = + vbslq_f32(vcgeq_f32(currentSamples, vdupq_n_f32(0.0f)), vminq_f32(currentSamples, vdupq_n_f32(static_cast(std::numeric_limits::max()))), + vmaxq_f32(currentSamples, vdupq_n_f32(static_cast(std::numeric_limits::min())))); + + storeValues(currentSamples, dataOut); + } + + // @brief Combine a register worth of elements from decodedData and store the result in upSampledVector. This version uses NEON instructions. + // @param upSampledVector pointer to the array of int32_t values. + // @param decodedData pointer to the array of int16_t values. + inline void combineSamples(const int16_t* decodedData, int32_t* upSampledVector) { + storeValues(vaddq_f32(gatherValues(upSampledVector), gatherValues(decodedData)), upSampledVector); + } + + protected: + alignas(16) float newArray[byteBlocksPerRegister]{}; + neon_float currentSamples{}; + + // @brief Stores values from a 128-bit NEON vector to a storage location. + // @tparam value_type the target value type for storage. + // @param valuesToStore the 128-bit NEON vector containing values to store. + // @param storageLocation pointer to the storage location. + template inline void storeValues(const float32x4_t& valuesToStore, value_type* storageLocation) { + vst1q_f32(newArray, valuesToStore); + for (int64_t x = 0; x < byteBlocksPerRegister; ++x) { + storageLocation[x] = static_cast(newArray[x]); + } + } + + // @brief Specialization for gathering non-float values into a NEON register. + // @tparam value_type the type of values being gathered. + // @return a NEON register containing gathered values. + template inline neon_float gatherValues(const value_type* values) { + for (uint64_t x = 0; x < byteBlocksPerRegister; ++x) { + newArray[x] = static_cast(values[x]); + } + return vld1q_f32(newArray); + } + }; + + + } +} + +#endif \ No newline at end of file diff --git a/Include/discordcoreapi/Utilities/ISADetection.hpp b/Include/discordcoreapi/Utilities/ISADetection.hpp index 59cd61489..5d4d613ce 100644 --- a/Include/discordcoreapi/Utilities/ISADetection.hpp +++ b/Include/discordcoreapi/Utilities/ISADetection.hpp @@ -29,9 +29,10 @@ /// \file ISADetection.hpp #pragma once -#include +#include #include #include #include +#include #include diff --git a/Include/discordcoreapi/Utilities/RingBuffer.hpp b/Include/discordcoreapi/Utilities/RingBuffer.hpp index c87596e91..a7134eba6 100644 --- a/Include/discordcoreapi/Utilities/RingBuffer.hpp +++ b/Include/discordcoreapi/Utilities/RingBuffer.hpp @@ -64,7 +64,7 @@ namespace discord_core_api { } DCA_INLINE ring_buffer_interface& operator=(ring_buffer_interface&&) noexcept = default; - DCA_INLINE ring_buffer_interface(ring_buffer_interface&&) noexcept = default; + DCA_INLINE ring_buffer_interface(ring_buffer_interface&&) noexcept = default; DCA_INLINE ring_buffer_interface& operator=(const ring_buffer_interface&) noexcept = default; DCA_INLINE ring_buffer_interface(const ring_buffer_interface&) noexcept = default; @@ -125,7 +125,7 @@ namespace discord_core_api { } protected: - jsonifier::vector> arrayValue{};///< The underlying data array. + jsonifier::vector> arrayValue{};///< The underlying data array. size_type tail{};///< The tail position in the buffer. size_type head{};///< The head position in the buffer. }; @@ -134,10 +134,10 @@ namespace discord_core_api { /// @tparam value_type the type of data stored in the buffer. /// @tparam slice_count the number of slices. template class ring_buffer - : public ring_buffer_interface, 1024 * 16>, slice_count> { + : public ring_buffer_interface, 1024 * 16>, slice_count> { public: - using base_type = ring_buffer_interface, 1024 * 16>, slice_count>; - using value_type = typename ring_buffer_interface, 1024 * 16>::value_type; + using base_type = ring_buffer_interface, 1024 * 16>, slice_count>; + using value_type = typename ring_buffer_interface, 1024 * 16>::value_type; using const_pointer = const value_type*; using pointer = value_type*; using size_type = uint64_t; @@ -154,7 +154,7 @@ namespace discord_core_api { /// @param data pointer to the data. /// @param sizeNew size of the data. template DCA_INLINE void writeData(value_type_newer* data, size_type sizeNew) { - if (base_type::isItFull() || base_type::isItFull()) { + if (base_type::isItFull()) { base_type::getCurrentTail()->clear(); base_type::modifyReadOrWritePosition(ring_buffer_access_type::read, 1); } @@ -166,10 +166,10 @@ namespace discord_core_api { /// @brief Read data from the buffer. /// @return a string view containing the read data. - DCA_INLINE jsonifier::string_view_base> readData() { - jsonifier::string_view_base> returnData{}; + DCA_INLINE jsonifier::string_view_base> readData() { + jsonifier::string_view_base> returnData{}; if (base_type::getCurrentTail()->getUsedSpace() > 0) { - returnData = jsonifier::string_view_base>{ base_type::getCurrentTail()->getCurrentTail(), + returnData = jsonifier::string_view_base>{ base_type::getCurrentTail()->getCurrentTail(), base_type::getCurrentTail()->getUsedSpace() }; base_type::getCurrentTail()->clear(); base_type::modifyReadOrWritePosition(ring_buffer_access_type::read, 1); diff --git a/Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp b/Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp index ca74e705d..d938b6670 100644 --- a/Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp +++ b/Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp @@ -34,7 +34,7 @@ namespace discord_core_api { template - concept copyable_or_movable = std::copyable> || std::movable>; + concept copyable_or_movable = std::copyable> || std::movable>; /// @brief A thread-safe messaging block for data-structures. /// @tparam value_type the type of object that will be sent over the message block. @@ -87,7 +87,7 @@ namespace discord_core_api { std::mutex accessMutex{}; }; - template DCA_INLINE bool waitForTimeToPass(unbounded_message_block>& outBuffer, value_type& argOne, uint64_t timeInMsNew) { + template DCA_INLINE bool waitForTimeToPass(unbounded_message_block>& outBuffer, value_type& argOne, uint64_t timeInMsNew) { stop_watch stopWatch{ milliseconds{ timeInMsNew } }; stopWatch.reset(); while (!outBuffer.tryReceive(argOne)) { diff --git a/Include/discordcoreapi/Utilities/UnicodeEmoji.hpp b/Include/discordcoreapi/Utilities/UnicodeEmoji.hpp index 688bbb92e..9c1ec0dc7 100644 --- a/Include/discordcoreapi/Utilities/UnicodeEmoji.hpp +++ b/Include/discordcoreapi/Utilities/UnicodeEmoji.hpp @@ -45,24 +45,37 @@ namespace discord_core_api { * ``` */ - template struct unicode_emoji { - constexpr unicode_emoji& operator=(const char (&str)[size]) { - std::copy(str, str + size - 1, stringUnicode); + template struct unicode_emoji { + static constexpr auto length{ sizeVal > 0 ? sizeVal - 1 : 0 }; + + constexpr unicode_emoji() noexcept = default; + + constexpr unicode_emoji& operator=(const char (&str)[sizeVal]) noexcept { + std::copy(str, str + sizeVal, values); return *this; } - constexpr unicode_emoji(const char (&str)[size]) { + constexpr unicode_emoji(const char (&str)[sizeVal]) noexcept { *this = str; } - constexpr operator jsonifier::string_view() const { - return stringUnicode; + constexpr uint64_t size() const noexcept { + return length; + } + + constexpr const char* data() const noexcept { + return values; } - constexpr const char* data() const { - return stringUnicode; + constexpr operator std::string() const noexcept { + return { values, length }; } - char stringUnicode[size - 1]{}; + + constexpr operator jsonifier::string_view() const noexcept { + return { values, length }; + } + + char values[sizeVal]{}; }; namespace unicode_emojis { diff --git a/Include/discordcoreapi/Utilities/UnorderedSet.hpp b/Include/discordcoreapi/Utilities/UnorderedSet.hpp index c5ca02159..bfa465513 100644 --- a/Include/discordcoreapi/Utilities/UnorderedSet.hpp +++ b/Include/discordcoreapi/Utilities/UnorderedSet.hpp @@ -36,7 +36,7 @@ namespace discord_core_api { template class unordered_set; template - concept set_container_iterator_t = std::same_as::iterator, jsonifier::concepts::unwrap_t>; + concept set_container_iterator_t = std::same_as::iterator, jsonifier_internal::unwrap_t>; template class unordered_set : protected hash_policy>, protected jsonifier_internal::alloc_wrapper, protected object_compare { @@ -309,7 +309,7 @@ namespace discord_core_api { } template DCA_INLINE uint64_t getKey(value_type_newer&& keyValue) const { - return key_accessor>::getHashKey(std::forward(keyValue)); + return key_accessor>::getHashKey(std::forward(keyValue)); } DCA_INLINE void resize(size_type capacityNew) { diff --git a/Include/discordcoreapi/VoiceConnection.hpp b/Include/discordcoreapi/VoiceConnection.hpp index 078f7bfbe..4f24f5adb 100644 --- a/Include/discordcoreapi/VoiceConnection.hpp +++ b/Include/discordcoreapi/VoiceConnection.hpp @@ -128,6 +128,12 @@ namespace discord_core_api { snowflake userId{}; }; + /// @brief The voice data for a given user, as raw PCM data, along with their Id. + struct voice_user_payload { + jsonifier::string_view_base voiceData{}; + snowflake userId{}; + }; + struct DiscordCoreAPI_Dll voice_user { voice_user() = default; @@ -153,10 +159,10 @@ namespace discord_core_api { snowflake userId{}; }; - struct DiscordCoreAPI_Dll rtppacket_encrypter { - rtppacket_encrypter() = default; + struct DiscordCoreAPI_Dll rtp_packet_encrypter { + rtp_packet_encrypter() = default; - rtppacket_encrypter(uint32_t ssrcNew, const jsonifier::string_base& keysNew); + rtp_packet_encrypter(uint32_t ssrcNew, const jsonifier::string_base& keysNew); jsonifier::string_view_base encryptPacket(discord_core_internal::encoder_return_data& audioData); @@ -243,6 +249,7 @@ namespace discord_core_api { std::array upSampledVector{}; jsonifier::vector resampleVector{}; moving_averager voiceUserCountAverage{ 25 }; + bool doWeKeepAudioData{ false }; snowflake guildId{}; float currentGain{}; float increment{}; @@ -292,6 +299,10 @@ namespace discord_core_api { /// @return snowflake a snowflake containing the channel_data's id. snowflake getChannelId(); + /// @brief Collects some voice data for a given user. + /// @return voice_user_payload The raw PCM audio data, along with that user's id. + voice_user_payload extractVoicePayload(); + /// @brief Connects to a currently held voice channel. /// @param initData a discord_coer_api::voice_connect_init_dat structure. void connect(const voice_connect_init_data& initData); @@ -313,7 +324,7 @@ namespace discord_core_api { jsonifier::string_base encryptionKey{}; voice_connect_init_data voiceConnectInitData{}; jsonifier::string audioEncryptionMode{}; - rtppacket_encrypter packetEncrypter{}; + rtp_packet_encrypter packetEncrypter{}; int64_t sampleRatePerSecond{ 48000 }; co_routine taskThread{}; voice_udpconnection udpConnection{}; diff --git a/Include/discordcoreapi/YouTubeAPI.hpp b/Include/discordcoreapi/YouTubeAPI.hpp index 4e2278505..ba15602c9 100644 --- a/Include/discordcoreapi/YouTubeAPI.hpp +++ b/Include/discordcoreapi/YouTubeAPI.hpp @@ -75,14 +75,14 @@ namespace discord_core_api { }; struct you_tube_request_client { - static constexpr jsonifier::string_view clientVersion{ "17.13.3" }; - static constexpr jsonifier::string_view androidSdkVersion{ "31" }; - static constexpr jsonifier::string_view clientName{ "android" }; - static constexpr jsonifier::string_view platform{ "mobile" }; - static constexpr jsonifier::string_view osName{ "android" }; - static constexpr jsonifier::string_view osVersion{ "12" }; - static constexpr jsonifier::string_view hl{ "en-gb" }; - static constexpr jsonifier::string_view gl{ "us" }; + jsonifier::string_view clientVersion{ "17.13.3" }; + jsonifier::string_view androidSdkVersion{ "31" }; + jsonifier::string_view clientName{ "android" }; + jsonifier::string_view platform{ "mobile" }; + jsonifier::string_view osName{ "android" }; + jsonifier::string_view osVersion{ "12" }; + jsonifier::string_view hl{ "en-gb" }; + jsonifier::string_view gl{ "us" }; }; struct request { diff --git a/ReadMe.md b/ReadMe.md index 4d72eaeb6..0f946bc58 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -2,7 +2,7 @@ [![Codacy Badge](https://img.shields.io/codacy/grade/1e5ae970aed34d0b96249cdfd02099cf?color=lightblue&label=Code%20Quality&style=plastic)](https://www.codacy.com/gh/RealTimeChris/DiscordCoreAPI/dashboard?utm_source=github.com&utm_medium=referral&utm_content=RealTimeChris/DiscordCoreAPI&utm_campaign=Badge_Grade) [![Discord](https://img.shields.io/discord/931640556814237706?color=red&label=Discord%20Server&style=plastic)](https://discord.gg/adgMqeBuhP) ![Commit Activity](https://img.shields.io/github/commit-activity/y/realtimechris/discordcoreapi?color=green&label=Commits&style=plastic) -![Lines of Code](https://tokei.rs/b1/github/RealTimeChris/DiscordCoreAPI?color=light-blue&label=Lines%20Of%20Code%20&style=plastic) +![Lines of Code](https://tokei.rs/b1/github/RealTimeChris/DiscordCoreAPI-Code-Only?color=light-blue&label=Lines%20Of%20Code%20&style=plastic) Hello, and welcome to DiscordCoreAPI! This is a Discord bot library, written in C++, that leverages custom asynchronous [CoRoutines](https://github.com/RealTimeChris/DiscordCoreAPI/blob/main/Include/discordcoreapi/CoRoutine.hpp), as well as a home-brew set of [Https](https://github.com/RealTimeChris/DiscordCoreAPI/blob/main/Include/discordcoreapi/Utilities/HttpsClient.hpp#L241), [WebSocket](https://github.com/RealTimeChris/DiscordCoreAPI/blob/main/Include/discordcoreapi/Utilities/WebSocketClient.hpp#L175), and [Datagram](https://github.com/RealTimeChris/DiscordCoreAPI/blob/main/Include/discordcoreapi/VoiceConnection.hpp#L272) socket clients - all to deliver the utmost performance and efficiency for your bot. It uses roughly 0.1% of an Intel i7 9750h CPU to stream audio in high quality (Opus @ 48Khz, 16-bit) to a single server. diff --git a/Source/DiscordCoreClient.cpp b/Source/DiscordCoreClient.cpp index a61ecd7b0..1a2b383ec 100644 --- a/Source/DiscordCoreClient.cpp +++ b/Source/DiscordCoreClient.cpp @@ -172,8 +172,9 @@ namespace discord_core_api { } } - void discord_core_client::registerFunction(const jsonifier::vector& functionNames, unique_ptr baseFunction, - create_application_command_data commandData, bool alwaysRegister) { + void discord_core_client::registerFunction(const jsonifier::vector& functionNames, unique_ptr&& baseFunction, + const create_application_command_data& commandDataNew, bool alwaysRegister) { + create_application_command_data commandData{ commandDataNew }; commandData.alwaysRegister = alwaysRegister; commandController.registerFunction(functionNames, std::move(baseFunction)); commandsToRegister.emplace_back(commandData); diff --git a/Source/EventManager.cpp b/Source/EventManager.cpp index e1eee9319..daf1d24cf 100644 --- a/Source/EventManager.cpp +++ b/Source/EventManager.cpp @@ -186,7 +186,7 @@ namespace discord_core_api { template<> unordered_map*> object_collector::objectsBuffersMap; on_input_event_creation_data::on_input_event_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -196,7 +196,7 @@ namespace discord_core_api { on_application_command_permissions_update_data::on_application_command_permissions_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -205,7 +205,7 @@ namespace discord_core_api { } on_auto_moderation_rule_creation_data::on_auto_moderation_rule_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -214,7 +214,7 @@ namespace discord_core_api { } on_auto_moderation_rule_update_data::on_auto_moderation_rule_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -223,7 +223,7 @@ namespace discord_core_api { } on_auto_moderation_rule_deletion_data::on_auto_moderation_rule_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -232,7 +232,7 @@ namespace discord_core_api { } on_auto_moderation_action_execution_data::on_auto_moderation_action_execution_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -241,7 +241,7 @@ namespace discord_core_api { } on_channel_creation_data::on_channel_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -258,7 +258,7 @@ namespace discord_core_api { } on_channel_update_data::on_channel_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (channels::doWeCacheChannels()) { oldValue = channels::getCachedChannel({ .channelId = value.id }); channels::insertChannel(static_cast(value)); @@ -266,7 +266,7 @@ namespace discord_core_api { } on_channel_deletion_data::on_channel_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -287,7 +287,7 @@ namespace discord_core_api { } on_channel_pins_update_data::on_channel_pins_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -296,7 +296,7 @@ namespace discord_core_api { } on_thread_creation_data::on_thread_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -305,7 +305,7 @@ namespace discord_core_api { } on_thread_update_data::on_thread_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -314,7 +314,7 @@ namespace discord_core_api { } on_thread_deletion_data::on_thread_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -323,7 +323,7 @@ namespace discord_core_api { } on_thread_list_sync_data::on_thread_list_sync_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -332,7 +332,7 @@ namespace discord_core_api { } on_thread_member_update_data::on_thread_member_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -341,7 +341,7 @@ namespace discord_core_api { } on_thread_members_update_data::on_thread_members_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -350,7 +350,7 @@ namespace discord_core_api { } on_guild_creation_data::on_guild_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -416,7 +416,7 @@ namespace discord_core_api { } on_guild_update_data::on_guild_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (guilds::doWeCacheGuilds()) { oldValue = guilds::getCachedGuild({ value.id }); guilds::insertGuild(static_cast(value)); @@ -424,7 +424,7 @@ namespace discord_core_api { } on_guild_deletion_data::on_guild_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -445,7 +445,7 @@ namespace discord_core_api { } on_guild_ban_add_data::on_guild_ban_add_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -462,7 +462,7 @@ namespace discord_core_api { } on_guild_ban_remove_data::on_guild_ban_remove_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -471,7 +471,7 @@ namespace discord_core_api { } on_guild_emojis_update_data::on_guild_emojis_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -486,7 +486,7 @@ namespace discord_core_api { } on_guild_stickers_update_data::on_guild_stickers_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -495,7 +495,7 @@ namespace discord_core_api { } on_guild_integrations_update_data::on_guild_integrations_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -504,7 +504,7 @@ namespace discord_core_api { } on_guild_member_add_data::on_guild_member_add_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -522,7 +522,7 @@ namespace discord_core_api { } on_guild_member_remove_data::on_guild_member_remove_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -545,7 +545,7 @@ namespace discord_core_api { } on_guild_member_update_data::on_guild_member_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (guild_members::doWeCacheGuildMembers()) { oldValue = guild_members::getCachedGuildMember({ .guildMemberId = value.user.id, .guildId = value.guildId }); guild_members::insertGuildMember(static_cast(value)); @@ -553,7 +553,7 @@ namespace discord_core_api { } on_guild_members_chunk_data::on_guild_members_chunk_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -562,7 +562,7 @@ namespace discord_core_api { } on_role_creation_data::on_role_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -579,7 +579,7 @@ namespace discord_core_api { } on_role_update_data::on_role_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (roles::doWeCacheRoles()) { oldValue = roles::getCachedRole({ .guildId = value.guildId, .roleId = value.role.id }); roles::insertRole(static_cast(value.role)); @@ -587,7 +587,7 @@ namespace discord_core_api { } on_role_deletion_data::on_role_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -609,7 +609,7 @@ namespace discord_core_api { on_voice_server_update_data::on_voice_server_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse, discord_core_internal::websocket_client* sslShard) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -633,7 +633,7 @@ namespace discord_core_api { }; on_guild_scheduled_event_creation_data::on_guild_scheduled_event_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -642,7 +642,7 @@ namespace discord_core_api { } on_guild_scheduled_event_update_data::on_guild_scheduled_event_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -651,7 +651,7 @@ namespace discord_core_api { } on_guild_scheduled_event_deletion_data::on_guild_scheduled_event_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -660,7 +660,7 @@ namespace discord_core_api { } on_guild_scheduled_event_user_add_data::on_guild_scheduled_event_user_add_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -669,7 +669,7 @@ namespace discord_core_api { } on_guild_scheduled_event_user_remove_data::on_guild_scheduled_event_user_remove_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -678,7 +678,7 @@ namespace discord_core_api { } on_integration_creation_data::on_integration_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -687,7 +687,7 @@ namespace discord_core_api { } on_integration_update_data::on_integration_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -696,7 +696,7 @@ namespace discord_core_api { } on_integration_deletion_data::on_integration_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -705,7 +705,7 @@ namespace discord_core_api { } on_interaction_creation_data::on_interaction_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -789,7 +789,7 @@ namespace discord_core_api { } on_invite_creation_data::on_invite_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -798,7 +798,7 @@ namespace discord_core_api { } on_invite_deletion_data::on_invite_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -807,7 +807,7 @@ namespace discord_core_api { } on_message_creation_data::on_message_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -819,7 +819,7 @@ namespace discord_core_api { } on_message_update_data::on_message_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -831,7 +831,7 @@ namespace discord_core_api { } on_message_deletion_data::on_message_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -840,7 +840,7 @@ namespace discord_core_api { } on_message_delete_bulk_data::on_message_delete_bulk_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -849,7 +849,7 @@ namespace discord_core_api { } on_reaction_add_data::on_reaction_add_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -861,7 +861,7 @@ namespace discord_core_api { } on_reaction_remove_data::on_reaction_remove_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -870,7 +870,7 @@ namespace discord_core_api { } on_reaction_remove_all_data::on_reaction_remove_all_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -879,7 +879,7 @@ namespace discord_core_api { } on_reaction_remove_emoji_data::on_reaction_remove_emoji_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -888,7 +888,7 @@ namespace discord_core_api { } on_presence_update_data::on_presence_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -897,7 +897,7 @@ namespace discord_core_api { } on_stage_instance_creation_data::on_stage_instance_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -906,7 +906,7 @@ namespace discord_core_api { } on_stage_instance_update_data::on_stage_instance_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -915,7 +915,7 @@ namespace discord_core_api { } on_stage_instance_deletion_data::on_stage_instance_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -924,7 +924,7 @@ namespace discord_core_api { } on_typing_start_data::on_typing_start_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -933,7 +933,7 @@ namespace discord_core_api { } on_user_update_data::on_user_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); oldValue = users::getCachedUser({ value.id }); if (users::doWeCacheUsers()) { users::insertUser(static_cast(value)); @@ -942,7 +942,7 @@ namespace discord_core_api { on_voice_state_update_data::on_voice_state_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse, discord_core_internal::websocket_client* sslShard) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -970,7 +970,7 @@ namespace discord_core_api { } on_webhook_update_data::on_webhook_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -979,7 +979,7 @@ namespace discord_core_api { } on_auto_complete_entry_data::on_auto_complete_entry_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); diff --git a/Source/FoundationEntities.cpp b/Source/FoundationEntities.cpp index 03e905381..bb07d8631 100644 --- a/Source/FoundationEntities.cpp +++ b/Source/FoundationEntities.cpp @@ -243,24 +243,24 @@ namespace discord_core_api { return true; } - embed_data& embed_data::setAuthor(jsonifier::string_view authorName, jsonifier::string_view authorAvatarUrl) { + embed_data& embed_data::setAuthor(const jsonifier::string& authorName, const jsonifier::string& authorAvatarUrl) { author.name = authorName; author.iconUrl = authorAvatarUrl; return *this; } - embed_data& embed_data::setFooter(jsonifier::string_view footerText, jsonifier::string_view footerIconUrlText) { + embed_data& embed_data::setFooter(const jsonifier::string& footerText, const jsonifier::string& footerIconUrlText) { footer.text = footerText; footer.iconUrl = footerIconUrlText; return *this; } - embed_data& embed_data::setTimeStamp(jsonifier::string_view timeStampNew) { + embed_data& embed_data::setTimeStamp(const jsonifier::string& timeStampNew) { timeStamp = static_cast(timeStampNew); return *this; } - embed_data& embed_data::addField(jsonifier::string_view name, jsonifier::string_view value, bool Inline) { + embed_data& embed_data::addField(const jsonifier::string& name, const jsonifier::string& value, bool Inline) { embed_field_data field{}; field.Inline = Inline; field.value = value; @@ -269,27 +269,27 @@ namespace discord_core_api { return *this; } - embed_data& embed_data::setDescription(jsonifier::string_view descriptionNew) { + embed_data& embed_data::setDescription(const jsonifier::string& descriptionNew) { description = descriptionNew; return *this; } - embed_data& embed_data::setColor(jsonifier::string_view hexColorValueNew) { + embed_data& embed_data::setColor(const jsonifier::string& hexColorValueNew) { hexColorValue = jsonifier::strToUint64<16>(static_cast(hexColorValueNew)); return *this; } - embed_data& embed_data::setThumbnail(jsonifier::string_view thumbnailUrl) { + embed_data& embed_data::setThumbnail(const jsonifier::string& thumbnailUrl) { thumbnail.url = thumbnailUrl; return *this; } - embed_data& embed_data::setTitle(jsonifier::string_view titleNew) { + embed_data& embed_data::setTitle(const jsonifier::string& titleNew) { title = titleNew; return *this; } - embed_data& embed_data::setImage(jsonifier::string_view imageUrl) { + embed_data& embed_data::setImage(const jsonifier::string& imageUrl) { image.url = imageUrl; return *this; } @@ -768,8 +768,8 @@ namespace discord_core_api { *this = dataPackage; } - respond_to_input_event_data& respond_to_input_event_data::addButton(bool disabled, jsonifier::string_view customIdNew, jsonifier::string_view buttonLabel, - button_style buttonStyle, jsonifier::string_view emojiName, snowflake emojiId, jsonifier::string_view url) { + respond_to_input_event_data& respond_to_input_event_data::addButton(bool disabled, const jsonifier::string& customIdNew, const jsonifier::string& buttonLabel, + button_style buttonStyle, const jsonifier::string& emojiName, snowflake emojiId, const jsonifier::string& url) { if (components.size() == 0) { action_row_data actionRowData; components.emplace_back(actionRowData); @@ -794,8 +794,8 @@ namespace discord_core_api { return *this; } - respond_to_input_event_data& respond_to_input_event_data::addSelectMenu(bool disabled, jsonifier::string_view customIdNew, const jsonifier::vector& options, - jsonifier::string_view placeholder, uint64_t maxValues, uint64_t minValues, select_menu_type typeNew, jsonifier::vector channelTypes) { + respond_to_input_event_data& respond_to_input_event_data::addSelectMenu(bool disabled, const jsonifier::string& customIdNew, const jsonifier::vector& options, + const jsonifier::string& placeholder, uint64_t maxValues, uint64_t minValues, select_menu_type typeNew, jsonifier::vector channelTypes) { if (components.size() == 0) { action_row_data actionRowData; components.emplace_back(actionRowData); @@ -820,9 +820,9 @@ namespace discord_core_api { return *this; } - respond_to_input_event_data& respond_to_input_event_data::addModal(jsonifier::string_view topTitleNew, jsonifier::string_view topCustomIdNew, jsonifier::string_view titleNew, - jsonifier::string_view customIdNew, bool required, uint64_t minLength, uint64_t maxLength, text_input_style inputStyle, jsonifier::string_view label, - jsonifier::string_view placeholder) { + respond_to_input_event_data& respond_to_input_event_data::addModal(const jsonifier::string& topTitleNew, const jsonifier::string& topCustomIdNew, const jsonifier::string& titleNew, + const jsonifier::string& customIdNew, bool required, uint64_t minLength, uint64_t maxLength, text_input_style inputStyle, const jsonifier::string& label, + const jsonifier::string& placeholder) { title = topTitleNew; customId = topCustomIdNew; if (components.size() == 0) { @@ -855,7 +855,7 @@ namespace discord_core_api { return *this; } - respond_to_input_event_data& respond_to_input_event_data::addAllowedMentions(const allowed_mentions_data dataPackage) { + respond_to_input_event_data& respond_to_input_event_data::addAllowedMentions(const allowed_mentions_data& dataPackage) { allowedMentions = dataPackage; return *this; } @@ -865,7 +865,7 @@ namespace discord_core_api { return *this; } - respond_to_input_event_data& respond_to_input_event_data::addComponentRow(const action_row_data dataPackage) { + respond_to_input_event_data& respond_to_input_event_data::addComponentRow(const action_row_data& dataPackage) { components.emplace_back(dataPackage); return *this; } @@ -875,7 +875,7 @@ namespace discord_core_api { return *this; } - respond_to_input_event_data& respond_to_input_event_data::addContent(jsonifier::string_view dataPackage) { + respond_to_input_event_data& respond_to_input_event_data::addContent(const jsonifier::string& dataPackage) { content = dataPackage; return *this; } @@ -885,8 +885,8 @@ namespace discord_core_api { return *this; } - respond_to_input_event_data& respond_to_input_event_data::setAutoCompleteChoice(discord_core_internal::etf_serializer value, jsonifier::string_view theName, - unordered_map theNameLocalizations) { + respond_to_input_event_data& respond_to_input_event_data::setAutoCompleteChoice(discord_core_internal::etf_serializer value, const jsonifier::string& theName, + const unordered_map& theNameLocalizations) { application_command_option_choice_data choiceData{}; choiceData.nameLocalizations = theNameLocalizations; choiceData.name = theName; @@ -900,8 +900,8 @@ namespace discord_core_api { return *this; } - message_response_base& message_response_base::addButton(bool disabled, jsonifier::string_view customIdNew, jsonifier::string_view buttonLabel, button_style buttonStyle, - jsonifier::string_view emojiName, snowflake emojiId, jsonifier::string_view url) { + message_response_base& message_response_base::addButton(bool disabled, const jsonifier::string& customIdNew, const jsonifier::string& buttonLabel, button_style buttonStyle, + const jsonifier::string& emojiName, snowflake emojiId, const jsonifier::string& url) { if (components.size() == 0) { action_row_data actionRowData; components.emplace_back(actionRowData); @@ -926,8 +926,8 @@ namespace discord_core_api { return *this; } - message_response_base& message_response_base::addSelectMenu(bool disabled, jsonifier::string_view customIdNew, jsonifier::vector options, - jsonifier::string_view placeholder, uint64_t maxValues, uint64_t minValues, select_menu_type type, jsonifier::vector channelTypes) { + message_response_base& message_response_base::addSelectMenu(bool disabled, const jsonifier::string& customIdNew, const jsonifier::vector& options, + const jsonifier::string& placeholder, uint64_t maxValues, uint64_t minValues, select_menu_type type, jsonifier::vector channelTypes) { if (components.size() == 0) { action_row_data actionRowData; components.emplace_back(actionRowData); @@ -952,9 +952,9 @@ namespace discord_core_api { return *this; } - message_response_base& message_response_base::addModal(jsonifier::string_view topTitleNew, jsonifier::string_view topCustomIdNew, jsonifier::string_view titleNew, - jsonifier::string_view customIdNew, bool required, uint64_t minLength, uint64_t maxLength, text_input_style inputStyle, jsonifier::string_view label, - jsonifier::string_view placeholder) { + message_response_base& message_response_base::addModal(const jsonifier::string& topTitleNew, const jsonifier::string& topCustomIdNew, const jsonifier::string& titleNew, + const jsonifier::string& customIdNew, bool required, uint64_t minLength, uint64_t maxLength, text_input_style inputStyle, const jsonifier::string& label, + const jsonifier::string& placeholder) { title = topTitleNew; customId = topCustomIdNew; if (components.size() == 0) { @@ -982,27 +982,27 @@ namespace discord_core_api { return *this; } - message_response_base& message_response_base::addFile(file theFile) { + message_response_base& message_response_base::addFile(const file& theFile) { files.emplace_back(theFile); return *this; } - message_response_base& message_response_base::addAllowedMentions(const allowed_mentions_data dataPackage) { + message_response_base& message_response_base::addAllowedMentions(const allowed_mentions_data& dataPackage) { allowedMentions = dataPackage; return *this; } - message_response_base& message_response_base::addComponentRow(const action_row_data dataPackage) { + message_response_base& message_response_base::addComponentRow(const action_row_data& dataPackage) { components.emplace_back(dataPackage); return *this; } - message_response_base& message_response_base::addMessageEmbed(const embed_data dataPackage) { + message_response_base& message_response_base::addMessageEmbed(const embed_data& dataPackage) { embeds.emplace_back(dataPackage); return *this; } - message_response_base& message_response_base::addContent(jsonifier::string_view dataPackage) { + message_response_base& message_response_base::addContent(const jsonifier::string& dataPackage) { content = dataPackage; return *this; } diff --git a/Source/SoundCloudAPI.cpp b/Source/SoundCloudAPI.cpp index 3e9602af0..bec68ad17 100644 --- a/Source/SoundCloudAPI.cpp +++ b/Source/SoundCloudAPI.cpp @@ -325,7 +325,7 @@ namespace discord_core_api { dataPackage.workloadClass = https_workload_class::Get; https_response_data returnData = submitWorkloadAndGetResult(std::move(dataPackage)); sound_cloud_search_results resultsNew{}; - parser.parseJson(resultsNew, returnData.responseData); + parser.parseJson(resultsNew, returnData.responseData); for (auto& value: resultsNew.collection) { song songNew{}; if (value.title == "") { @@ -396,7 +396,7 @@ namespace discord_core_api { https_response_data results = submitWorkloadAndGetResult(std::move(dataPackage01)); second_download_url downloadUrl{}; song newerSong{ songNew }; - parser.parseJson(downloadUrl, results.responseData); + parser.parseJson(downloadUrl, results.responseData); newerSong.secondDownloadUrl = downloadUrl.url; if (newerSong.secondDownloadUrl.find("/playlist") != jsonifier::string::npos) { https_workload_data dataPackage{ https_workload_type::SoundCloud_Get_Download_Links }; diff --git a/Source/VoiceConnection.cpp b/Source/VoiceConnection.cpp index b5918849a..569a48749 100644 --- a/Source/VoiceConnection.cpp +++ b/Source/VoiceConnection.cpp @@ -98,12 +98,12 @@ namespace discord_core_api { return userId; } - rtppacket_encrypter::rtppacket_encrypter(uint32_t ssrcNew, const jsonifier::string_base& keysNew) { + rtp_packet_encrypter::rtp_packet_encrypter(uint32_t ssrcNew, const jsonifier::string_base& keysNew) { keys = keysNew; ssrc = ssrcNew; } - jsonifier::string_view_base rtppacket_encrypter::encryptPacket(discord_core_internal::encoder_return_data& audioData) { + jsonifier::string_view_base rtp_packet_encrypter::encryptPacket(discord_core_internal::encoder_return_data& audioData) { if (keys.size() > 0) { ++sequence; timeStamp += static_cast(audioData.sampleCount); @@ -410,11 +410,11 @@ namespace discord_core_api { bool voice_connection::onMessageReceived(jsonifier::string_view_base data) { discord_core_internal::websocket_message message{}; message_printer::printSuccess("message received from voice websocket: " + jsonifier::string{ data }); - parser.parseJson(message, data); + parser.parseJson(message, data); switch (static_cast(message.op)) { case voice_socket_op_codes::Ready_Server: { discord_core_internal::websocket_message_data dataNew{}; - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); audioSSRC = dataNew.d.ssrc; voiceIp = dataNew.d.ip; port = dataNew.d.port; @@ -429,17 +429,17 @@ namespace discord_core_api { case voice_socket_op_codes::Session_Description: { discord_core_internal::websocket_message_data dataNew{}; encryptionKey.clear(); - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); for (auto& value: dataNew.d.secretKey) { encryptionKey.emplace_back(static_cast(value)); } - packetEncrypter = rtppacket_encrypter{ audioSSRC, encryptionKey }; + packetEncrypter = rtp_packet_encrypter{ audioSSRC, encryptionKey }; connectionState.store(voice_connection_state::Collecting_Init_Data, std::memory_order_release); break; } case voice_socket_op_codes::speaking: { discord_core_internal::websocket_message_data dataNew{}; - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); const uint32_t ssrc = dataNew.d.ssrc; auto userId = dataNew.d.userId; unique_ptr user{ makeUnique(userId) }; @@ -457,7 +457,7 @@ namespace discord_core_api { } case voice_socket_op_codes::hello: { discord_core_internal::websocket_message_data dataNew{}; - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); heartBeatStopWatch = stop_watch{ dataNew.d.heartBeatInterval }; heartBeatStopWatch.reset(); areWeHeartBeating = true; @@ -472,7 +472,7 @@ namespace discord_core_api { } case voice_socket_op_codes::Client_Disconnect: { discord_core_internal::websocket_message_data dataNew{}; - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); const auto userId = dataNew.d.userId; for (auto& [key, value]: voiceUsers) { if (userId == value->getUserId()) { diff --git a/Source/WebSocketClient.cpp b/Source/WebSocketClient.cpp index 93121d8ab..dfbb6cdaf 100644 --- a/Source/WebSocketClient.cpp +++ b/Source/WebSocketClient.cpp @@ -465,7 +465,7 @@ namespace discord_core_api { if (configManager->getTextFormat() == text_format::etf) { try { dataNew = etfParser.parseEtfToJson(dataNew); - parser.parseJson(message, parser.minify(parser.prettify(dataNew))); + parser.parseJson(message, dataNew); for (auto& valueNew: parser.getErrors()) { message_printer::printError(valueNew.reportError() + ", for data:" + dataNew); } @@ -476,7 +476,7 @@ namespace discord_core_api { return false; } } else { - parser.parseJson(message, parser.minify(parser.prettify(dataNew))); + parser.parseJson(message, dataNew); if (auto result = parser.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError() + ", for data:" + dataNew); @@ -1018,12 +1018,13 @@ namespace discord_core_api { } } dataNewer.op = 2; + jsonifier::string_base stringNew{}; jsonifier::string_base string{}; if (dataOpCode == websocket_op_code::Op_Binary) { auto serializer = dataNewer.operator etf_serializer(); string = serializer.operator jsonifier::string_base(); } else { - parser.serializeJson(dataNewer, string); + parser.serializeJson(dataNewer, stringNew); } createHeader(string, dataOpCode); currentState.store(websocket_state::Sending_Identify, std::memory_order_release); diff --git a/Source/YouTubeAPI.cpp b/Source/YouTubeAPI.cpp index 3b8dbf0d3..117fa80a7 100644 --- a/Source/YouTubeAPI.cpp +++ b/Source/YouTubeAPI.cpp @@ -51,9 +51,8 @@ namespace jsonifier { template<> struct core { using value_type = discord_core_api::discord_core_internal::you_tube_request_client; - static constexpr auto parseValue = - createValue("clientName", &value_type::clientName, "androidSdkVersion", &value_type::androidSdkVersion, "clientVersion", &value_type::clientVersion, "hl", - &value_type::hl, "gl", &value_type::gl, "osName", &value_type::osName, "osVersion", &value_type::osVersion, "platform", &value_type::platform); + static constexpr auto parseValue = createValue<&value_type::clientName, &value_type::androidSdkVersion, &value_type::clientVersion, &value_type::hl, &value_type::gl, + &value_type::osName, &value_type::osVersion, &value_type::platform>(); }; template<> struct core { @@ -145,7 +144,7 @@ namespace jsonifier { static constexpr auto parseValue = createValue("contents", &value_type::contents); }; } - + namespace discord_core_api { namespace discord_core_internal { @@ -197,12 +196,12 @@ namespace discord_core_api { jsonifier::string newString = returnData.responseData.substr(varInitFind + newString00.size()); jsonifier::string stringSequence = ";