From 77ab8a981b0cb53c2634e31e83910e2dc22b8bad Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Sun, 3 May 2020 13:28:17 -0400 Subject: [PATCH 01/20] Add version number to the init log --- Source/VaRest/Private/VaRest.cpp | 12 +++++++++++- Source/VaRest/Public/VaRest.h | 3 +++ Source/VaRest/VaRest.Build.cs | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 793b4986..1de6aee2 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -7,6 +7,8 @@ #include "Developer/Settings/Public/ISettingsModule.h" +#include "Interfaces/IPluginManager.h" + #define LOCTEXT_NAMESPACE "FVaRestModule" void FVaRestModule::StartupModule() @@ -23,7 +25,7 @@ void FVaRestModule::StartupModule() ModuleSettings); } - UE_LOG(LogVaRest, Log, TEXT("%s: VaRest module started"), *VA_FUNC_LINE); + UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *GetPluginVersion()); } void FVaRestModule::ShutdownModule() @@ -49,6 +51,14 @@ UVaRestSettings* FVaRestModule::GetSettings() const return ModuleSettings; } +FString FVaRestModule::GetPluginVersion() const +{ + IPluginManager& manager = IPluginManager::Get(); + TSharedPtr const plugin = manager.FindPlugin("VaRest"); + + return !plugin.IsValid() ? FString() : plugin->GetDescriptor().VersionName; +} + IMPLEMENT_MODULE(FVaRestModule, VaRest) DEFINE_LOG_CATEGORY(LogVaRest); diff --git a/Source/VaRest/Public/VaRest.h b/Source/VaRest/Public/VaRest.h index 86dade53..3b6959f5 100644 --- a/Source/VaRest/Public/VaRest.h +++ b/Source/VaRest/Public/VaRest.h @@ -37,6 +37,9 @@ class FVaRestModule : public IModuleInterface /** Getter for internal settings object to support runtime configuration changes */ UVaRestSettings* GetSettings() const; + /** Get the plugin version. */ + FString GetPluginVersion() const; + protected: /** Module settings */ UVaRestSettings* ModuleSettings; diff --git a/Source/VaRest/VaRest.Build.cs b/Source/VaRest/VaRest.Build.cs index 30d13a99..a6563463 100644 --- a/Source/VaRest/VaRest.Build.cs +++ b/Source/VaRest/VaRest.Build.cs @@ -23,7 +23,8 @@ public VaRest(ReadOnlyTargetRules Target) : base(Target) "CoreUObject", "Engine", "HTTP", - "Json" + "Json", + "Projects" // Required by IPluginManager etc (used to get plugin information) // ... add other public dependencies that you statically link with here ... }); } From e0c05ec4f1a06a72f7539904b415c9696838294b Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Sun, 3 May 2020 13:34:16 -0400 Subject: [PATCH 02/20] small fixes --- Source/VaRest/Private/VaRest.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 1de6aee2..d0188c04 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -53,10 +53,9 @@ UVaRestSettings* FVaRestModule::GetSettings() const FString FVaRestModule::GetPluginVersion() const { - IPluginManager& manager = IPluginManager::Get(); - TSharedPtr const plugin = manager.FindPlugin("VaRest"); + TSharedPtr const plugin = IPluginManager::Get().FindPlugin("VaRest"); - return !plugin.IsValid() ? FString() : plugin->GetDescriptor().VersionName; + return !plugin.IsValid() ? FString("Unable to get version number") : plugin->GetDescriptor().VersionName; } IMPLEMENT_MODULE(FVaRestModule, VaRest) From b0f931070b6b7072a187608a04fd043850bf9853 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Sat, 9 May 2020 14:45:10 -0400 Subject: [PATCH 03/20] fixes requested by ufna --- Source/VaRest/Private/VaRest.cpp | 12 ++---------- Source/VaRest/Private/VaRestLibrary.cpp | 8 ++++++++ Source/VaRest/Public/VaRest.h | 3 --- Source/VaRest/Public/VaRestLibrary.h | 6 +++++- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index d0188c04..0c0e3351 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -3,12 +3,11 @@ #include "VaRest.h" #include "VaRestDefines.h" +#include "VaRestLibrary.h" #include "VaRestSettings.h" #include "Developer/Settings/Public/ISettingsModule.h" -#include "Interfaces/IPluginManager.h" - #define LOCTEXT_NAMESPACE "FVaRestModule" void FVaRestModule::StartupModule() @@ -25,7 +24,7 @@ void FVaRestModule::StartupModule() ModuleSettings); } - UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *GetPluginVersion()); + UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *UVaRestLibrary::GetPluginVersion()); } void FVaRestModule::ShutdownModule() @@ -51,13 +50,6 @@ UVaRestSettings* FVaRestModule::GetSettings() const return ModuleSettings; } -FString FVaRestModule::GetPluginVersion() const -{ - TSharedPtr const plugin = IPluginManager::Get().FindPlugin("VaRest"); - - return !plugin.IsValid() ? FString("Unable to get version number") : plugin->GetDescriptor().VersionName; -} - IMPLEMENT_MODULE(FVaRestModule, VaRest) DEFINE_LOG_CATEGORY(LogVaRest); diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index 4b3be13a..c8bfe4ce 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -8,6 +8,7 @@ #include "VaRestRequestJSON.h" #include "VaRestSettings.h" +#include "Interfaces/IPluginManager.h" #include "Misc/Base64.h" UVaRestSettings* UVaRestLibrary::GetVaRestSettings() @@ -78,3 +79,10 @@ FString UVaRestLibrary::StringToSha1(const FString& StringToHash) return Sha1String; } + +FString UVaRestLibrary::GetPluginVersion() +{ + TSharedPtr const Plugin = IPluginManager::Get().FindPlugin("VaRest"); + + return !Plugin.IsValid() ? FString("Unable to get version number") : Plugin->GetDescriptor().VersionName; +} diff --git a/Source/VaRest/Public/VaRest.h b/Source/VaRest/Public/VaRest.h index 3b6959f5..86dade53 100644 --- a/Source/VaRest/Public/VaRest.h +++ b/Source/VaRest/Public/VaRest.h @@ -37,9 +37,6 @@ class FVaRestModule : public IModuleInterface /** Getter for internal settings object to support runtime configuration changes */ UVaRestSettings* GetSettings() const; - /** Get the plugin version. */ - FString GetPluginVersion() const; - protected: /** Module settings */ UVaRestSettings* ModuleSettings; diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 722a890e..e492217b 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -74,7 +74,7 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary /** * Helper to perform the very common case of hashing an ASCII string into a hex representation. - * + * * @param String Hex representation of the hash (32 lower-case hex digits) */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to MD5")) @@ -91,4 +91,8 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary */ UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "HTTP Status Int To Enum")) static FORCEINLINE EVaRestHttpStatusCode::Type HTTPStatusIntToEnum(int32 StatusCode) { return (EVaRestHttpStatusCode::Type)StatusCode; } + + /** Get the plugin's version. */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version")) + static FString GetPluginVersion(); }; From 7079ff4c12ed8731b0ca70121aa20c51e1872db2 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sat, 9 May 2020 21:53:20 +0300 Subject: [PATCH 04/20] Slightly rename functions to avoid possible issues with android linkage --- Source/VaRest/Private/VaRest.cpp | 2 +- Source/VaRest/Private/VaRestLibrary.cpp | 6 +++--- Source/VaRest/Public/VaRestLibrary.h | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 0c0e3351..1c505cda 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -24,7 +24,7 @@ void FVaRestModule::StartupModule() ModuleSettings); } - UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *UVaRestLibrary::GetPluginVersion()); + UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *UVaRestLibrary::GetVaRestVersion()); } void FVaRestModule::ShutdownModule() diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index c8bfe4ce..7f72c78c 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -80,9 +80,9 @@ FString UVaRestLibrary::StringToSha1(const FString& StringToHash) return Sha1String; } -FString UVaRestLibrary::GetPluginVersion() +FString UVaRestLibrary::GetVaRestVersion() { - TSharedPtr const Plugin = IPluginManager::Get().FindPlugin("VaRest"); + const auto PluginRef = IPluginManager::Get().FindPlugin("VaRest"); - return !Plugin.IsValid() ? FString("Unable to get version number") : Plugin->GetDescriptor().VersionName; + return !PluginRef.IsValid() ? FString("invalid") : PluginRef->GetDescriptor().VersionName; } diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index e492217b..e1538e31 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -92,7 +92,9 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "HTTP Status Int To Enum")) static FORCEINLINE EVaRestHttpStatusCode::Type HTTPStatusIntToEnum(int32 StatusCode) { return (EVaRestHttpStatusCode::Type)StatusCode; } - /** Get the plugin's version. */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version")) - static FString GetPluginVersion(); + /** + * Get the plugin's version + */ + UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version")) + static FString GetVaRestVersion(); }; From 8f760b9b5c817ead60bfabaa11e65df6329f8e0c Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 24 Sep 2020 22:21:48 +0300 Subject: [PATCH 05/20] Add GetWorldURL helper --- Source/VaRest/Private/VaRestLibrary.cpp | 13 ++++++ Source/VaRest/Public/VaRestLibrary.h | 10 ++++ Source/VaRest/Public/VaRestTypes.h | 62 +++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index 7f72c78c..5847e2f1 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -86,3 +86,16 @@ FString UVaRestLibrary::GetVaRestVersion() return !PluginRef.IsValid() ? FString("invalid") : PluginRef->GetDescriptor().VersionName; } + +FVaRestURL UVaRestLibrary::GetWorldURL(UObject* WorldContextObject) +{ + if (WorldContextObject) + { + if (UWorld* World = WorldContextObject->GetWorld()) + { + return FVaRestURL(World->URL); + } + } + + return FVaRestURL(); +} diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index e1538e31..52ea9ffb 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -97,4 +97,14 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary */ UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version")) static FString GetVaRestVersion(); + + ////////////////////////////////////////////////////////////////////////// + // Common Network Helpers + +public: + /** + * Get the URL that was used when loading this World + */ + UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject")) + static FVaRestURL GetWorldURL(UObject* WorldContextObject); }; diff --git a/Source/VaRest/Public/VaRestTypes.h b/Source/VaRest/Public/VaRestTypes.h index 1a5c0d7e..8a3388cc 100644 --- a/Source/VaRest/Public/VaRestTypes.h +++ b/Source/VaRest/Public/VaRestTypes.h @@ -2,6 +2,10 @@ #pragma once +#include "Engine/EngineBaseTypes.h" + +#include "VaRestTypes.generated.h" + /** Verb (GET, PUT, POST) used by the request */ UENUM(BlueprintType) enum class EVaRestRequestVerb : uint8 @@ -135,3 +139,61 @@ enum Type VersionNotSup = 505 UMETA(DisplayName = "VersionNotSup = 505") }; } // namespace EVaRestHttpStatusCode + +/** + * FURL structure wrapper for BP access + */ +USTRUCT(BlueprintType) +struct VAREST_API FVaRestURL +{ + GENERATED_BODY() + + /** Protocol, i.e. "unreal" or "http" */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString Protocol; + + /** Optional hostname, i.e. "204.157.115.40" or "unreal.epicgames.com", blank if local. */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString Host; + + /** Optional host port */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + int32 Port; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + int32 Valid; + + /** Map name, i.e. "SkyCity", default is "Entry" */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString Map; + + /** Optional place to download Map if client does not possess it */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString RedirectURL; + + /** Options */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + TArray Op; + + /** Portal to enter through, default is "" */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString Portal; + + FVaRestURL() + : Port(0) + , Valid(0) + { + } + + FVaRestURL(FURL& InUrl) + : Protocol(InUrl.Protocol) + , Host(InUrl.Host) + , Port(InUrl.Port) + , Valid(InUrl.Valid) + , Map(InUrl.Map) + , RedirectURL(InUrl.RedirectURL) + , Op(InUrl.Op) + , Portal(InUrl.Portal) + { + } +}; From ce2195ed7c21b87f5d72df10a2aa21a8f5fbff27 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Sep 2020 12:33:18 +0300 Subject: [PATCH 06/20] Update classes to support UE 4.26 --- Source/VaRest/Public/VaRestRequestJSON.h | 4 ++-- VaRest.uplugin | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index 57b090b7..06c06553 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -313,9 +313,9 @@ class VAREST_API UVaRestRequestJSON : public UObject FString CustomVerb; /** Request we're currently processing */ - TSharedRef HttpRequest = FHttpModule::Get().CreateRequest(); + TSharedRef HttpRequest = FHttpModule::Get().CreateRequest(); public: /** Returns reference to internal request object */ - TSharedRef GetHttpRequest() const { return HttpRequest; }; + TSharedRef GetHttpRequest() const { return HttpRequest; }; }; diff --git a/VaRest.uplugin b/VaRest.uplugin index 73fe1182..e18a41a4 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -6,7 +6,7 @@ "VersionName" : "1.1-r30", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://alyamkin.com", - "EngineVersion" : "4.25.0", + "EngineVersion" : "4.26.0", "Description" : "Plugin that makes REST (JSON) server communication easy to use", "Category" : "Network", "DocsURL": "https://bit.ly/VaRest-Docs", From bb4f16eebcc6abe0ded531c05779c054b7f83815 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Tue, 29 Sep 2020 15:52:58 +0300 Subject: [PATCH 07/20] Add category for vars to fix packaging --- Source/VaRest/Public/VaRestTypes.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/VaRest/Public/VaRestTypes.h b/Source/VaRest/Public/VaRestTypes.h index 8a3388cc..fbbf94ae 100644 --- a/Source/VaRest/Public/VaRestTypes.h +++ b/Source/VaRest/Public/VaRestTypes.h @@ -149,34 +149,34 @@ struct VAREST_API FVaRestURL GENERATED_BODY() /** Protocol, i.e. "unreal" or "http" */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString Protocol; /** Optional hostname, i.e. "204.157.115.40" or "unreal.epicgames.com", blank if local. */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString Host; /** Optional host port */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") int32 Port; - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") int32 Valid; /** Map name, i.e. "SkyCity", default is "Entry" */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString Map; /** Optional place to download Map if client does not possess it */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString RedirectURL; /** Options */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") TArray Op; /** Portal to enter through, default is "" */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString Portal; FVaRestURL() From 71b99c7aa86850e8a634f19bbb468b2692020640 Mon Sep 17 00:00:00 2001 From: Mirek Kaspar Date: Wed, 30 Sep 2020 10:52:18 +0200 Subject: [PATCH 08/20] Update VaRestLibrary.h Added category to the GetWorldURL node --- Source/VaRest/Public/VaRestLibrary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 52ea9ffb..baabcb40 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -105,6 +105,6 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary /** * Get the URL that was used when loading this World */ - UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject")) + UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (WorldContext = "WorldContextObject")) static FVaRestURL GetWorldURL(UObject* WorldContextObject); }; From 40f509d66fbfa927278325c87eab98dd4ba78d35 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 4 Dec 2020 22:20:16 +0300 Subject: [PATCH 09/20] Up plugin version --- README.md | 2 +- VaRest.uplugin | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ecd0d6a..c9199cf7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 30** (UE 4.25) +Current version: **1.1 R 31** (UE 4.26) ![SCREENSHOT](SCREENSHOT.jpg) diff --git a/VaRest.uplugin b/VaRest.uplugin index e18a41a4..710b23c5 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -2,8 +2,8 @@ "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 30, - "VersionName" : "1.1-r30", + "Version" : 31, + "VersionName" : "1.1-r31", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://alyamkin.com", "EngineVersion" : "4.26.0", From 3dd9c4d9d2caf68130d544a3fd5d4df37a1bdcc6 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sun, 20 Dec 2020 01:57:17 +0300 Subject: [PATCH 10/20] Fix headers --- Source/VaRest/Private/VaRest.cpp | 1 + Source/VaRest/Private/VaRestJsonParser.cpp | 1 - Source/VaRest/Private/VaRestLibrary.cpp | 4 ++-- Source/VaRest/Private/VaRestRequestJSON.cpp | 6 ++++-- Source/VaRest/Private/VaRestSubsystem.cpp | 1 - Source/VaRest/Public/VaRestDefines.h | 6 ------ Source/VaRest/Public/VaRestJsonValue.h | 2 -- Source/VaRest/Public/VaRestLibrary.h | 1 - Source/VaRest/Public/VaRestSubsystem.h | 2 -- Source/VaRestEditor/Private/VaRestEditor.cpp | 2 ++ Source/VaRestEditor/Public/VaRestEditor.h | 2 +- 11 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 1c505cda..f4829540 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -7,6 +7,7 @@ #include "VaRestSettings.h" #include "Developer/Settings/Public/ISettingsModule.h" +#include "UObject/Package.h" #define LOCTEXT_NAMESPACE "FVaRestModule" diff --git a/Source/VaRest/Private/VaRestJsonParser.cpp b/Source/VaRest/Private/VaRestJsonParser.cpp index ee629434..d7b6ba46 100644 --- a/Source/VaRest/Private/VaRestJsonParser.cpp +++ b/Source/VaRest/Private/VaRestJsonParser.cpp @@ -6,7 +6,6 @@ #include "Dom/JsonObject.h" #include "Dom/JsonValue.h" -#include "Logging/LogMacros.h" uint32 FUtf8Helper::CodepointFromUtf8(const ANSICHAR*& SourceString, const uint32 SourceLengthRemaining) { diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index 5847e2f1..df53acd2 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -4,10 +4,10 @@ #include "VaRest.h" #include "VaRestDefines.h" -#include "VaRestJsonObject.h" #include "VaRestRequestJSON.h" -#include "VaRestSettings.h" +#include "Engine/World.h" +#include "GenericPlatform/GenericPlatformHttp.h" #include "Interfaces/IPluginManager.h" #include "Misc/Base64.h" diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 5089fa5f..5b1eb6a3 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -7,9 +7,11 @@ #include "VaRestLibrary.h" #include "VaRestSettings.h" +#include "Engine/Engine.h" +#include "Engine/EngineTypes.h" +#include "Engine/LatentActionManager.h" +#include "Engine/World.h" #include "Json.h" -#include "Kismet/GameplayStatics.h" -#include "Misc/CoreMisc.h" #include "Runtime/Launch/Resources/Version.h" FString UVaRestRequestJSON::DeprecatedResponseString(TEXT("DEPRECATED: Please use GetResponseContentAsString() instead")); diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index f4bb788f..5aba7f7a 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -6,7 +6,6 @@ #include "VaRestJsonObject.h" #include "VaRestJsonValue.h" -#include "Developer/Settings/Public/ISettingsModule.h" #include "Misc/FileHelper.h" #include "Misc/Paths.h" #include "Subsystems/SubsystemBlueprintLibrary.h" diff --git a/Source/VaRest/Public/VaRestDefines.h b/Source/VaRest/Public/VaRestDefines.h index 6e2c698d..d0e0e1f2 100644 --- a/Source/VaRest/Public/VaRestDefines.h +++ b/Source/VaRest/Public/VaRestDefines.h @@ -6,23 +6,17 @@ #if ENGINE_MINOR_VERSION >= 15 #include "CoreMinimal.h" -#include "Engine/Engine.h" -#include "EngineDefines.h" -#include "UObject/Object.h" -#include "UObject/ScriptMacros.h" #else #include "CoreUObject.h" #include "Engine.h" #endif -#include "Delegates/DelegateCombinations.h" #include "Logging/LogCategory.h" #include "Logging/LogMacros.h" #include "Logging/LogVerbosity.h" // You should place include statements to your module's private header files here. You only need to // add includes for headers that are used in most of your module's source files though. -#include "Modules/ModuleManager.h" DECLARE_LOG_CATEGORY_EXTERN(LogVaRest, Log, All); diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index ef622b0b..9975a7bf 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -2,8 +2,6 @@ #pragma once -#include "VaRestDefines.h" - #include "VaRestJsonValue.generated.h" class UVaRestJsonObject; diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index baabcb40..11977073 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -4,7 +4,6 @@ #include "Kismet/BlueprintFunctionLibrary.h" -#include "VaRestDefines.h" #include "VaRestTypes.h" #include "VaRestLibrary.generated.h" diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 936c6e47..f4547975 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -5,9 +5,7 @@ #include "VaRestJsonValue.h" #include "VaRestRequestJSON.h" -#include "Delegates/DelegateCombinations.h" #include "Subsystems/EngineSubsystem.h" -#include "Subsystems/SubsystemCollection.h" #include "VaRestSubsystem.generated.h" diff --git a/Source/VaRestEditor/Private/VaRestEditor.cpp b/Source/VaRestEditor/Private/VaRestEditor.cpp index 82d0973e..c3bb7d07 100644 --- a/Source/VaRestEditor/Private/VaRestEditor.cpp +++ b/Source/VaRestEditor/Private/VaRestEditor.cpp @@ -2,6 +2,8 @@ #include "VaRestEditor.h" +#include "Modules/ModuleManager.h" + #define LOCTEXT_NAMESPACE "FVaRestEditorModule" void FVaRestEditorModule::StartupModule() diff --git a/Source/VaRestEditor/Public/VaRestEditor.h b/Source/VaRestEditor/Public/VaRestEditor.h index a51c92c9..a5e0a8ae 100644 --- a/Source/VaRestEditor/Public/VaRestEditor.h +++ b/Source/VaRestEditor/Public/VaRestEditor.h @@ -2,7 +2,7 @@ #pragma once -#include "Modules/ModuleManager.h" +#include "Modules/ModuleInterface.h" class FVaRestEditorModule : public IModuleInterface { From ca39db6d1c2880223f58d9a3cfe388c04699ce4f Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Mon, 4 Jan 2021 01:04:27 +0300 Subject: [PATCH 11/20] Minor code fixes --- Source/VaRest/Private/VaRestJsonObject.cpp | 36 ++++++++++----------- Source/VaRest/Private/VaRestRequestJSON.cpp | 1 + Source/VaRest/Public/VaRestJsonObject.h | 2 +- Source/VaRest/Public/VaRestRequestJSON.h | 3 ++ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index 0466789b..11c3f249 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -46,7 +46,7 @@ void UVaRestJsonObject::SetRootObject(const TSharedPtr& JsonObject) FString UVaRestJsonObject::EncodeJson() const { FString OutputString; - auto Writer = TJsonWriterFactory<>::Create(&OutputString); + const auto Writer = TJsonWriterFactory<>::Create(&OutputString); FJsonSerializer::Serialize(JsonObj, Writer); return OutputString; @@ -55,7 +55,7 @@ FString UVaRestJsonObject::EncodeJson() const FString UVaRestJsonObject::EncodeJsonToSingleString() const { FString OutputString; - auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString); + const auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString); FJsonSerializer::Serialize(JsonObj, Writer); return OutputString; @@ -65,7 +65,7 @@ bool UVaRestJsonObject::DecodeJson(const FString& JsonString, bool bUseIncrement { if (bUseIncrementalParser) { - int32 BytesRead = DeserializeFromTCHARBytes(JsonString.GetCharArray().GetData(), JsonString.Len()); + const int32 BytesRead = DeserializeFromTCHARBytes(JsonString.GetCharArray().GetData(), JsonString.Len()); // JsonObj is always valid, but read bytes is zero when something went wrong if (BytesRead > 0) @@ -75,7 +75,7 @@ bool UVaRestJsonObject::DecodeJson(const FString& JsonString, bool bUseIncrement } else { - TSharedRef> Reader = TJsonReaderFactory<>::Create(*JsonString); + const TSharedRef> Reader = TJsonReaderFactory<>::Create(*JsonString); TSharedPtr OutJsonObj; if (FJsonSerializer::Deserialize(Reader, OutJsonObj)) { @@ -277,7 +277,7 @@ void UVaRestJsonObject::SetArrayField(const FString& FieldName, const TArray JsonVal = InVal->GetRootValue(); + const TSharedPtr JsonVal = InVal->GetRootValue(); switch (InVal->GetType()) { @@ -344,7 +344,7 @@ UVaRestJsonObject* UVaRestJsonObject::GetObjectField(const FString& FieldName) c return nullptr; } - TSharedPtr JsonObjField = JsonObj->GetObjectField(FieldName); + const TSharedPtr JsonObjField = JsonObj->GetObjectField(FieldName); UVaRestJsonObject* OutRestJsonObj = NewObject(); OutRestJsonObj->SetRootObject(JsonObjField); @@ -402,10 +402,10 @@ TArray UVaRestJsonObject::GetNumberArrayField(const FString& FieldName) c return NumberArray; } - TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); + const TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); for (TArray>::TConstIterator It(JsonArrayValues); It; ++It) { - auto Value = (*It).Get(); + const auto Value = (*It).Get(); if (Value->Type != EJson::Number) { UE_LOG(LogVaRest, Error, TEXT("Not Number element in array with field name %s"), *FieldName); @@ -443,10 +443,10 @@ TArray UVaRestJsonObject::GetStringArrayField(const FString& FieldName) return StringArray; } - TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); + const TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); for (TArray>::TConstIterator It(JsonArrayValues); It; ++It) { - auto Value = (*It).Get(); + const auto Value = (*It).Get(); if (Value->Type != EJson::String) { UE_LOG(LogVaRest, Error, TEXT("Not String element in array with field name %s"), *FieldName); @@ -483,10 +483,10 @@ TArray UVaRestJsonObject::GetBoolArrayField(const FString& FieldName) cons return BoolArray; } - TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); + const TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); for (TArray>::TConstIterator It(JsonArrayValues); It; ++It) { - auto Value = (*It).Get(); + const auto Value = (*It).Get(); if (Value->Type != EJson::Boolean) { UE_LOG(LogVaRest, Error, TEXT("Not Boolean element in array with field name %s"), *FieldName); @@ -524,7 +524,7 @@ TArray UVaRestJsonObject::GetObjectArrayField(const FString& } TArray> ValArray = JsonObj->GetArrayField(FieldName); - for (auto Value : ValArray) + for (const auto Value : ValArray) { if (Value->Type != EJson::Object) { @@ -643,11 +643,11 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr& Reader) if (bIsIntelByteOrder) { - Char = CharCast((UCS2CHAR)((uint16)SymbolBytes[0] + (uint16)SymbolBytes[1] * 256)); + Char = CharCast(static_cast(static_cast(SymbolBytes[0]) + static_cast(SymbolBytes[1]) * 256)); } else { - Char = CharCast((UCS2CHAR)((uint16)SymbolBytes[1] + (uint16)SymbolBytes[0] * 256)); + Char = CharCast(static_cast(static_cast(SymbolBytes[1]) + static_cast(SymbolBytes[0]) * 256)); } if (!JsonReader.Read(Char)) @@ -667,7 +667,7 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr& Reader) ////////////////////////////////////////////////////////////////////////// // Serialize -bool UVaRestJsonObject::WriteToFile(const FString& Path) +bool UVaRestJsonObject::WriteToFile(const FString& Path) const { TUniquePtr FileWriter(IFileManager::Get().CreateFileWriter(*Path)); if (!FileWriter) @@ -723,8 +723,8 @@ bool UVaRestJsonObject::WriteToFilePath(const FString& Path, const bool bIsRelat bool UVaRestJsonObject::WriteStringToArchive(FArchive& Ar, const TCHAR* StrPtr, int64 Len) { - auto Src = StringCast(StrPtr, Len); - Ar.Serialize((UCS2CHAR*)Src.Get(), Src.Length() * sizeof(UCS2CHAR)); + const auto Src = StringCast(StrPtr, Len); + Ar.Serialize(const_cast(Src.Get()), Src.Length() * sizeof(UCS2CHAR)); return true; } diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 5b1eb6a3..534f4836 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -11,6 +11,7 @@ #include "Engine/EngineTypes.h" #include "Engine/LatentActionManager.h" #include "Engine/World.h" +#include "Interfaces/IHttpResponse.h" #include "Json.h" #include "Runtime/Launch/Resources/Version.h" diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index 4872f064..499fd779 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -218,7 +218,7 @@ class VAREST_API UVaRestJsonObject : public UObject public: /** Save json to file */ - bool WriteToFile(const FString& Path); + bool WriteToFile(const FString& Path) const; /** * Blueprint Save json to filepath diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index 06c06553..d74da2b3 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -4,12 +4,15 @@ #include "Engine/LatentActionManager.h" #include "Http.h" +#include "HttpModule.h" +#include "Interfaces/IHttpRequest.h" #include "LatentActions.h" #include "VaRestTypes.h" #include "VaRestRequestJSON.generated.h" +class UVaRestJsonObject; class UVaRestSettings; /** From b12efd01c617e431ec6417db534706a181a213dd Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Mon, 4 Jan 2021 01:54:10 +0300 Subject: [PATCH 12/20] In const we trust --- Source/VaRest/Private/VaRestJsonObject.cpp | 2 +- Source/VaRest/Private/VaRestJsonParser.cpp | 26 +++++++++---------- Source/VaRest/Private/VaRestJsonValue.cpp | 2 +- Source/VaRest/Private/VaRestLibrary.cpp | 6 ++--- Source/VaRest/Private/VaRestRequestJSON.cpp | 2 +- Source/VaRest/Private/VaRestSubsystem.cpp | 2 +- .../VaRestEditor/Private/VaRest_BreakJson.cpp | 10 +++---- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index 11c3f249..86bb28a4 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -524,7 +524,7 @@ TArray UVaRestJsonObject::GetObjectArrayField(const FString& } TArray> ValArray = JsonObj->GetArrayField(FieldName); - for (const auto Value : ValArray) + for (const auto& Value : ValArray) { if (Value->Type != EJson::Object) { diff --git a/Source/VaRest/Private/VaRestJsonParser.cpp b/Source/VaRest/Private/VaRestJsonParser.cpp index d7b6ba46..5a7a6ded 100644 --- a/Source/VaRest/Private/VaRestJsonParser.cpp +++ b/Source/VaRest/Private/VaRestJsonParser.cpp @@ -293,7 +293,7 @@ void FJSONState::PopObject() { if (Objects.Num() > 0) { - auto Object = Objects.Pop(false); + const auto Object = Objects.Pop(false); if (Object->Type == EJson::Object) { return; @@ -307,7 +307,7 @@ void FJSONState::PopArray() { if (Objects.Num() > 0) { - auto Object = Objects.Pop(false); + const auto Object = Objects.Pop(false); if (Object->Type == EJson::Array) { return; @@ -321,7 +321,7 @@ void FJSONState::PopValue(bool bCheckType) { if (Objects.Num() > 0) { - auto Value = Objects.Last(0); + const auto Value = Objects.Last(0); if (Value->Type == EJson::Object || Value->Type == EJson::Array) { if (bCheckType) @@ -338,7 +338,7 @@ void FJSONState::PopValue(bool bCheckType) { case EJson::Null: { - auto LowerCase = Data.ToLower(); + const auto LowerCase = Data.ToLower(); if (LowerCase != TEXT("null")) { bError = true; @@ -355,7 +355,7 @@ void FJSONState::PopValue(bool bCheckType) } case EJson::Number: { - FString LowerCase = Data.ToLower(); + const FString LowerCase = Data.ToLower(); int32 ePosition = INDEX_NONE; LowerCase.FindChar('e', ePosition); if (ePosition == INDEX_NONE) @@ -371,8 +371,8 @@ void FJSONState::PopValue(bool bCheckType) } else if (LowerCase.Len() > ePosition + 2) { - FString Left = LowerCase.Left(ePosition); - FString Rigth = LowerCase.Right(LowerCase.Len() - ePosition - 1); + const FString Left = LowerCase.Left(ePosition); + const FString Rigth = LowerCase.Right(LowerCase.Len() - ePosition - 1); if (Left.IsNumeric() && Rigth.IsNumeric()) { ((FJsonValueNonConstNumber*)Value.Get())->AsNonConstNumber() = FCString::Atod(*Left) * FMath::Pow(10.f, FCString::Atoi(*Rigth)); @@ -390,7 +390,7 @@ void FJSONState::PopValue(bool bCheckType) } case EJson::Boolean: { - auto LowerCase = Data.ToLower(); + const auto LowerCase = Data.ToLower(); if (LowerCase == TEXT("true")) { ((FJsonValueNonConstBoolean*)Value.Get())->AsNonConstBool() = true; @@ -414,7 +414,7 @@ void FJSONState::PopValue(bool bCheckType) ClearData(); - auto Container = Objects.Last(0); + const auto Container = Objects.Last(0); if (Container->Type == EJson::Object) { if (Key.Len() > 0) @@ -501,7 +501,7 @@ TSharedPtr FJSONState::PushObject(TSharedPtr Obje TSharedPtr FJSONState::PushArray() { - TArray> Empty; + const TArray> Empty; TSharedPtr Result(new FJsonValueNonConstArray(Empty)); Objects.Add(Result); Size += sizeof(TSharedPtr) + sizeof(FJsonValueNonConstArray); @@ -626,7 +626,7 @@ void FJSONReader::UpdateNotation() if (State.Key.Len() > 0) { State.Notation = EJSONNotation::OBJECT; - auto Value = State.GetObject(); + const auto Value = State.GetObject(); if (Value != nullptr) { Value->AsObject()->SetField(State.Key, State.PushObject()); @@ -708,7 +708,7 @@ void FJSONReader::UpdateNotation() State.Notation = EJSONNotation::ARRAY; if (State.Key.Len() > 0) { - auto Value = State.GetObject(); + const auto Value = State.GetObject(); if (Value != nullptr) { Value->AsObject()->SetField(State.Key, State.PushArray()); @@ -1099,7 +1099,7 @@ void FJSONWriter::Write(TSharedPtr JsonValue, FArchive* Writer, bool } default: { - FString Value = JsonValue->AsString(); + const FString Value = JsonValue->AsString(); const TCHAR* BufferPtr = *Value; for (int i = 0; i < Value.Len(); ++i) diff --git a/Source/VaRest/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp index 8b45a107..74018ded 100644 --- a/Source/VaRest/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -166,7 +166,7 @@ UVaRestJsonObject* UVaRestJsonValue::AsObject() return nullptr; } - TSharedPtr NewObj = JsonVal->AsObject(); + const TSharedPtr NewObj = JsonVal->AsObject(); UVaRestJsonObject* JsonObj = NewObject(); JsonObj->SetRootObject(NewObj); diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index df53acd2..9c6f16f8 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -24,7 +24,7 @@ FString UVaRestLibrary::PercentEncode(const FString& Source) FString UVaRestLibrary::Base64Encode(const FString& Source) { TArray ByteArray; - FTCHARToUTF8 StringSrc = FTCHARToUTF8(Source.GetCharArray().GetData()); + const FTCHARToUTF8 StringSrc = FTCHARToUTF8(Source.GetCharArray().GetData()); ByteArray.Append((uint8*)StringSrc.Get(), StringSrc.Length()); return FBase64::Encode(ByteArray); @@ -33,9 +33,9 @@ FString UVaRestLibrary::Base64Encode(const FString& Source) bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest) { TArray ByteArray; - bool Success = FBase64::Decode(Source, ByteArray); + const bool Success = FBase64::Decode(Source, ByteArray); - FUTF8ToTCHAR StringSrc = FUTF8ToTCHAR((const ANSICHAR*)ByteArray.GetData(), ByteArray.Num()); + const FUTF8ToTCHAR StringSrc = FUTF8ToTCHAR((const ANSICHAR*)ByteArray.GetData(), ByteArray.Num()); Dest = FString(); Dest.AppendChars(StringSrc.Get(), StringSrc.Length()); diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 534f4836..bf0e303d 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -499,7 +499,7 @@ void UVaRestRequestJSON::OnProcessRequestComplete(FHttpRequestPtr Request, FHttp else { // Use default unreal one - TSharedRef> Reader = TJsonReaderFactory<>::Create(*Response->GetContentAsString()); + const TSharedRef> Reader = TJsonReaderFactory<>::Create(*Response->GetContentAsString()); TSharedPtr OutJsonObj; if (FJsonSerializer::Deserialize(Reader, OutJsonObj)) { diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index 5aba7f7a..8527b8dd 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -62,7 +62,7 @@ void UVaRestSubsystem::OnCallComplete(UVaRestRequestJSON* Request) return; } - auto Response = RequestMap.Find(Request); + const auto Response = RequestMap.Find(Request); Request->OnStaticRequestComplete.Remove(Response->CompleteDelegateHandle); Request->OnStaticRequestFail.Remove(Response->FailDelegateHandle); diff --git a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp index 2e97727d..9ac7c144 100644 --- a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -86,7 +86,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); FName FunctionName; - bool bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array; + const bool bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array; if (FieldType == CompilerContext.GetSchema()->PC_Boolean) { FunctionName = bIsArray ? TEXT("GetBoolArrayField") : TEXT("GetBoolField"); @@ -213,7 +213,7 @@ FLinearColor UVaRest_BreakJson::GetNodeTitleColor() const void UVaRest_BreakJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; + const FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_BreakJson, Outputs) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || @@ -339,7 +339,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor { UClass* SubsystemClass = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestSubsystem'"))); - FName FunctionName = TEXT("StaticConstructVaRestJsonObject"); + const FName FunctionName = TEXT("StaticConstructVaRestJsonObject"); UFunction* FunctionPtr = SubsystemClass->FindFunctionByName(FunctionName); FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); Statement.Type = KCST_CallFunction; @@ -388,7 +388,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); FName FunctionName; - bool bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array; + const bool bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array; if (FieldType == CompilerContext.GetSchema()->PC_Boolean) { FunctionName = bIsArray ? TEXT("SetBoolArrayField") : TEXT("SetBoolField"); @@ -505,7 +505,7 @@ FLinearColor UVaRest_MakeJson::GetNodeTitleColor() const void UVaRest_MakeJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; + const FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_MakeJson, Inputs) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || From 61b909b47af5b6ba2e1424406c372061ee894155 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Mon, 4 Jan 2021 02:13:27 +0300 Subject: [PATCH 13/20] Use nullptr instead of NULL --- .../VaRestEditor/Private/VaRest_BreakJson.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp index 9ac7c144..7e8fc586 100644 --- a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -26,7 +26,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor virtual void Compile(FKismetFunctionContext& Context, UEdGraphNode* Node) override { - UEdGraphPin* InputPin = NULL; + UEdGraphPin* InputPin = nullptr; for (int32 PinIndex = 0; PinIndex < Node->Pins.Num(); ++PinIndex) { @@ -39,7 +39,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor } UEdGraphPin* InNet = FEdGraphUtilities::GetNetFromPin(InputPin); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); FBPTerminal** SourceTerm = Context.NetMap.Find(InNet); if (SourceTerm == nullptr) @@ -122,7 +122,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor FBPTerminal* RegisterInputTerm(FKismetFunctionContext& Context, UVaRest_BreakJson* Node) { // Find input pin - UEdGraphPin* InputPin = NULL; + UEdGraphPin* InputPin = nullptr; for (int32 PinIndex = 0; PinIndex < Node->Pins.Num(); ++PinIndex) { UEdGraphPin* Pin = Node->Pins[PinIndex]; @@ -168,7 +168,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor for (int32 PinIndex = 0; PinIndex < Node->Pins.Num(); ++PinIndex) { UEdGraphPin* Pin = Node->Pins[PinIndex]; - if (NULL != Pin && EGPD_Output == Pin->Direction) + if (nullptr != Pin && EGPD_Output == Pin->Direction) { RegisterOutputTerm(Context, Pin, StructContextTerm); } @@ -194,7 +194,7 @@ void UVaRest_BreakJson::AllocateDefaultPins() { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); UEdGraphPin* Pin = CreatePin(EGPD_Input, K2Schema->PC_Object, TEXT(""), Class, TEXT("Target")); #if ENGINE_MINOR_VERSION >= 17 @@ -213,7 +213,7 @@ FLinearColor UVaRest_BreakJson::GetNodeTitleColor() const void UVaRest_BreakJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - const FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; + const FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None; if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_BreakJson, Outputs) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || @@ -262,7 +262,7 @@ FText UVaRest_BreakJson::GetMenuCategory() const void UVaRest_BreakJson::CreateProjectionPins(UEdGraphPin* Source) { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); for (TArray::TIterator it(Outputs); it; ++it) { @@ -316,7 +316,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor virtual void Compile(FKismetFunctionContext& Context, UEdGraphNode* Node) override { - UEdGraphPin* OutputPin = NULL; + UEdGraphPin* OutputPin = nullptr; for (int32 PinIndex = 0; PinIndex < Node->Pins.Num(); ++PinIndex) { @@ -328,7 +328,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor } } - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); FBPTerminal** TargetTerm = Context.NetMap.Find(OutputPin); if (TargetTerm == nullptr) @@ -337,7 +337,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor } { - UClass* SubsystemClass = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestSubsystem'"))); + UClass* SubsystemClass = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestSubsystem'"))); const FName FunctionName = TEXT("StaticConstructVaRestJsonObject"); UFunction* FunctionPtr = SubsystemClass->FindFunctionByName(FunctionName); @@ -486,7 +486,7 @@ void UVaRest_MakeJson::AllocateDefaultPins() { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); UEdGraphPin* Pin = CreatePin(EGPD_Output, K2Schema->PC_Object, TEXT(""), Class, TEXT("Target")); #if ENGINE_MINOR_VERSION >= 17 @@ -505,7 +505,7 @@ FLinearColor UVaRest_MakeJson::GetNodeTitleColor() const void UVaRest_MakeJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - const FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; + const FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None; if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_MakeJson, Inputs) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || @@ -554,7 +554,7 @@ FText UVaRest_MakeJson::GetMenuCategory() const void UVaRest_MakeJson::CreateProjectionPins(UEdGraphPin* Source) { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); for (TArray::TIterator it(Inputs); it; ++it) { From df1ce54ede357aca506b273908409579858ab410 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 01:20:17 +0300 Subject: [PATCH 14/20] Int64 support --- Source/VaRest/Private/VaRestJsonObject.cpp | 21 +++++++++++++++++++ Source/VaRest/Private/VaRestJsonValue.cpp | 24 +++++++++++++++++++++- Source/VaRest/Public/VaRestJsonObject.h | 8 ++++++++ Source/VaRest/Public/VaRestJsonValue.h | 10 ++++++++- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index 86bb28a4..a99930c6 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -197,6 +197,27 @@ void UVaRestJsonObject::SetIntegerField(const FString& FieldName, int32 Number) JsonObj->SetNumberField(FieldName, Number); } +int64 UVaRestJsonObject::GetInt64Field(const FString& FieldName) const +{ + if (!JsonObj->HasTypedField(FieldName)) + { + UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Number"), *FieldName); + return 0; + } + + return static_cast(JsonObj->GetNumberField(FieldName)); +} + +void UVaRestJsonObject::SetInt64Field(const FString& FieldName, int64 Number) +{ + if (FieldName.IsEmpty()) + { + return; + } + + JsonObj->SetNumberField(FieldName, Number); +} + FString UVaRestJsonObject::GetStringField(const FString& FieldName) const { if (!JsonObj->HasTypedField(FieldName)) diff --git a/Source/VaRest/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp index 74018ded..f68b1754 100644 --- a/Source/VaRest/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -111,7 +111,29 @@ float UVaRestJsonValue::AsNumber() const return 0.f; } - return JsonVal->AsNumber(); + return static_cast(JsonVal->AsNumber()); +} + +int32 UVaRestJsonValue::AsInt32() const +{ + if (!JsonVal.IsValid()) + { + ErrorMessage(TEXT("Number")); + return 0.f; + } + + return static_cast(JsonVal->AsNumber()); +} + +int32 UVaRestJsonValue::AsInt64() const +{ + if (!JsonVal.IsValid()) + { + ErrorMessage(TEXT("Number")); + return 0.f; + } + + return static_cast(JsonVal->AsNumber()); } FString UVaRestJsonValue::AsString() const diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index 499fd779..d2c115f3 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -99,6 +99,14 @@ class VAREST_API UVaRestJsonObject : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Json") void SetIntegerField(const FString& FieldName, int32 Number); + /** Get the field named FieldName as an Int64. Ensures that the field is present and is of type Json number. */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + int64 GetInt64Field(const FString& FieldName) const; + + /** Add a field named FieldName with Int64 as value. */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void SetInt64Field(const FString& FieldName, int64 Number); + /** Get the field named FieldName as a string. */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") FString GetStringField(const FString& FieldName) const; diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index 9975a7bf..62c9d719 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -56,7 +56,15 @@ class VAREST_API UVaRestJsonValue : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Json") float AsNumber() const; - /** Returns this value as a number, throwing an error if this is not an Json String */ + /** Returns this value as a int32, throwing an error if this is not an Json Number */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + int32 AsInt32() const; + + /** Returns this value as a int64, throwing an error if this is not an Json Number */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + int32 AsInt64() const; + + /** Returns this value as a string, throwing an error if this is not an Json String */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") FString AsString() const; From ecc336aa3853a10155b077b49bfa300dbf6c38b7 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 17:35:35 +0300 Subject: [PATCH 15/20] Make getters pure --- Source/VaRest/Public/VaRestJsonValue.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index 62c9d719..ad2bb0e3 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -40,36 +40,36 @@ class VAREST_API UVaRestJsonValue : public UObject // FJsonValue API /** Get type of Json value (Enum) */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") EVaJson GetType() const; /** Get type of Json value (String) */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") FString GetTypeString() const; /** Returns true if this value is a 'null' */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") bool IsNull() const; /** Returns this value as a double, throwing an error if this is not an Json Number * Attn.!! float used instead of double to make the function blueprintable! */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") float AsNumber() const; /** Returns this value as a int32, throwing an error if this is not an Json Number */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") int32 AsInt32() const; /** Returns this value as a int64, throwing an error if this is not an Json Number */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") int32 AsInt64() const; /** Returns this value as a string, throwing an error if this is not an Json String */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") FString AsString() const; /** Returns this value as a boolean, throwing an error if this is not an Json Bool */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") bool AsBool() const; /** Returns this value as an array, throwing an error if this is not an Json Array */ From 67331cfb392472630cb81f7edd89d6d936559991 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 17:37:16 +0300 Subject: [PATCH 16/20] Up dev version --- VaRest.uplugin | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VaRest.uplugin b/VaRest.uplugin index 710b23c5..17387246 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -2,10 +2,10 @@ "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 31, - "VersionName" : "1.1-r31", + "Version" : 32, + "VersionName" : "1.1-r32", "CreatedBy" : "Vladimir Alyamkin", - "CreatedByURL" : "https://alyamkin.com", + "CreatedByURL" : "https://ufna.dev", "EngineVersion" : "4.26.0", "Description" : "Plugin that makes REST (JSON) server communication easy to use", "Category" : "Network", From aae0e2c84df969b5894caa3ca066232150e4294a Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 19:44:13 +0300 Subject: [PATCH 17/20] Add support for top-level arrays. Close #77. Close #116. --- Source/VaRest/Private/VaRestJsonValue.cpp | 5 ++++ Source/VaRest/Private/VaRestRequestJSON.cpp | 27 ++++++++++++++++++--- Source/VaRest/Private/VaRestSubsystem.cpp | 14 +++++++++++ Source/VaRest/Public/VaRestJsonValue.h | 5 ++++ Source/VaRest/Public/VaRestRequestJSON.h | 9 +++++++ Source/VaRest/Public/VaRestSubsystem.h | 8 ++++++ 6 files changed, 65 insertions(+), 3 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp index f68b1754..5d1ad085 100644 --- a/Source/VaRest/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -10,6 +10,11 @@ UVaRestJsonValue::UVaRestJsonValue(const FObjectInitializer& ObjectInitializer) { } +void UVaRestJsonValue::Reset() +{ + JsonVal = nullptr; +} + TSharedPtr& UVaRestJsonValue::GetRootValue() { return JsonVal; diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index bf0e303d..f6a2f124 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -4,6 +4,7 @@ #include "VaRestDefines.h" #include "VaRestJsonObject.h" +#include "VaRestJsonValue.h" #include "VaRestLibrary.h" #include "VaRestSettings.h" @@ -112,6 +113,15 @@ void UVaRestRequestJSON::ResetResponseData() ResponseJsonObj = NewObject(); } + if (ResponseJsonValue != nullptr) + { + ResponseJsonValue->Reset(); + } + else + { + ResponseJsonValue = NewObject(); + } + ResponseHeaders.Empty(); ResponseCode = -1; ResponseSize = 0; @@ -166,6 +176,12 @@ void UVaRestRequestJSON::SetResponseObject(UVaRestJsonObject* JsonObject) ResponseJsonObj = JsonObject; } +UVaRestJsonValue* UVaRestRequestJSON::GetResponseValue() const +{ + check(ResponseJsonValue); + return ResponseJsonValue; +} + /////////////////////////////////////////////////////////////////////////// // Response data access @@ -500,11 +516,16 @@ void UVaRestRequestJSON::OnProcessRequestComplete(FHttpRequestPtr Request, FHttp { // Use default unreal one const TSharedRef> Reader = TJsonReaderFactory<>::Create(*Response->GetContentAsString()); - TSharedPtr OutJsonObj; - if (FJsonSerializer::Deserialize(Reader, OutJsonObj)) + TSharedPtr OutJsonValue; + if (FJsonSerializer::Deserialize(Reader, OutJsonValue)) { - ResponseJsonObj->SetRootObject(OutJsonObj.ToSharedRef()); + ResponseJsonValue->SetRootValue(OutJsonValue); ResponseSize = Response->GetContentLength(); + + if (ResponseJsonValue->GetType() == EVaJson::Object) + { + ResponseJsonObj->SetRootObject(ResponseJsonValue->GetRootValue()->AsObject()); + } } } diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index 8527b8dd..e79653cc 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -8,6 +8,8 @@ #include "Misc/FileHelper.h" #include "Misc/Paths.h" +#include "Serialization/JsonReader.h" +#include "Serialization/JsonSerializer.h" #include "Subsystems/SubsystemBlueprintLibrary.h" UVaRestSubsystem::UVaRestSubsystem() @@ -164,6 +166,18 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValue(const TSharedPtr> Reader = TJsonReaderFactory<>::Create(*JsonString); + TSharedPtr OutJsonValue; + if (FJsonSerializer::Deserialize(Reader, OutJsonValue)) + { + return ConstructJsonValue(OutJsonValue); + } + + return nullptr; +} + class UVaRestJsonObject* UVaRestSubsystem::LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir) { auto* Json = ConstructVaRestJsonObject(); diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index ad2bb0e3..c5e5305c 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -30,6 +30,11 @@ class VAREST_API UVaRestJsonValue : public UObject { GENERATED_UCLASS_BODY() +public: + /** Reset all internal data */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void Reset(); + /** Get the root Json value */ TSharedPtr& GetRootValue(); diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index d74da2b3..8f39c06e 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -12,6 +12,7 @@ #include "VaRestRequestJSON.generated.h" +class UVaRestJsonValue; class UVaRestJsonObject; class UVaRestSettings; @@ -157,6 +158,10 @@ class VAREST_API UVaRestRequestJSON : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Response") void SetResponseObject(UVaRestJsonObject* JsonObject); + /** Get the Response Json value */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Response") + UVaRestJsonValue* GetResponseValue() const; + /////////////////////////////////////////////////////////////////////////// // Request/response data access @@ -297,6 +302,10 @@ class VAREST_API UVaRestRequestJSON : public UObject UPROPERTY() UVaRestJsonObject* ResponseJsonObj; + /** Response data stored as JSON value */ + UPROPERTY() + UVaRestJsonValue* ResponseJsonValue; + /** Verb for making request (GET,POST,etc) */ EVaRestRequestVerb RequestVerb; diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index f4547975..9773e34f 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -103,6 +103,14 @@ class VAREST_API UVaRestSubsystem : public UEngineSubsystem /** Create new Json value from FJsonValue (to be used from VaRestJsonObject) */ UVaRestJsonValue* ConstructJsonValue(const TSharedPtr& InValue); + ////////////////////////////////////////////////////////////////////////// + // Serialization + +public: + /** Construct Json value from string */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem") + UVaRestJsonValue* DecodeJson(const FString& JsonString); + ////////////////////////////////////////////////////////////////////////// // File system integration From 94f8c293eeb7189af5e4cfdef44a004ebc39e017 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 19:53:03 +0300 Subject: [PATCH 18/20] Decode json should be global and accept a string. Close #115 --- Source/VaRest/Private/VaRestSubsystem.cpp | 16 +++++++++++++++- Source/VaRest/Public/VaRestSubsystem.h | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index e79653cc..97daab65 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -166,7 +166,7 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValue(const TSharedPtr> Reader = TJsonReaderFactory<>::Create(*JsonString); TSharedPtr OutJsonValue; @@ -178,6 +178,20 @@ UVaRestJsonValue* UVaRestSubsystem::DecodeJson(const FString& JsonString) return nullptr; } +UVaRestJsonObject* UVaRestSubsystem::DecodeJsonObject(const FString& JsonString) +{ + const TSharedRef> Reader = TJsonReaderFactory<>::Create(*JsonString); + TSharedPtr OutJsonObj; + if (FJsonSerializer::Deserialize(Reader, OutJsonObj)) + { + auto NewJsonObj = NewObject(this); + NewJsonObj->SetRootObject(OutJsonObj); + return NewJsonObj; + } + + return nullptr; +} + class UVaRestJsonObject* UVaRestSubsystem::LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir) { auto* Json = ConstructVaRestJsonObject(); diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 9773e34f..33225443 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -109,7 +109,11 @@ class VAREST_API UVaRestSubsystem : public UEngineSubsystem public: /** Construct Json value from string */ UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem") - UVaRestJsonValue* DecodeJson(const FString& JsonString); + UVaRestJsonValue* DecodeJsonValue(const FString& JsonString); + + /** Construct Json object from string */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem") + UVaRestJsonObject* DecodeJsonObject(const FString& JsonString); ////////////////////////////////////////////////////////////////////////// // File system integration From e466709e3ed5b1be4ef92534d165099ee49aed19 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sun, 17 Jan 2021 13:41:31 +0300 Subject: [PATCH 19/20] Use real build plugin plan for status icon --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9199cf7..d2cbf656 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![statusIcon](https://teamcity.ufna.dev/app/rest/builds/buildType:(id:UfnaDev_VaRest_ClangFormatCheck)/statusIcon.svg)](https://teamcity.ufna.dev/viewType.html?buildTypeId=UfnaDev_VaRest_ClangFormatCheck&guest=1) +[![statusIcon](https://teamcity.ufna.dev/app/rest/builds/buildType:(id:UfnaDev_VaRest_BuildPlugin)/statusIcon.svg)](https://teamcity.ufna.dev/viewType.html?buildTypeId=UfnaDev_VaRest_BuildPlugin&guest=1) ![GitHub](https://img.shields.io/github/license/ufna/VaRest) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/ufna/VaRest?include_prereleases) From ed4195f88ae4c76170490b327aedb8424afd0ec0 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sun, 17 Jan 2021 14:10:04 +0300 Subject: [PATCH 20/20] Update version and copyright info --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2cbf656..e876516b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 31** (UE 4.26) +Current version: **1.1 R 32** (UE 4.26) ![SCREENSHOT](SCREENSHOT.jpg) @@ -26,5 +26,5 @@ Legal info Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere. -Unreal® Engine, Copyright 1998 – 2018, Epic Games, Inc. All rights reserved. +Unreal® Engine, Copyright 1998 – 2021, Epic Games, Inc. All rights reserved.