Skip to content

Commit

Permalink
Finish v1.1.33
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Sep 8, 2021
2 parents cbbe78f + 21217cc commit c8ae7b0
Show file tree
Hide file tree
Showing 24 changed files with 877 additions and 397 deletions.
16 changes: 13 additions & 3 deletions Config/BaseVaRest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
+ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestRequestJSON",NewName="/Script/VaRest.VaRestRequestJSON")
+StructRedirects=(OldName="/Script/VaRestPlugin.VaRestCallResponse",NewName="/Script/VaRest.VaRestCallResponse")
+EnumRedirects=(OldName="/Script/VaRestPlugin.EVaJson",NewName="/Script/VaRest.EVaJson")
+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestVerb",NewName="/Script/VaRest.ERequestVerb")
+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestContentType",NewName="/Script/VaRest.ERequestContentType")
+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestStatus",NewName="/Script/VaRest.ERequestStatus")
+EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb")
+EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType")
+EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus")
+EnumRedirects=(OldName="/Script/VaRest.ERequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb")
+EnumRedirects=(OldName="/Script/VaRest.ERequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType")
+EnumRedirects=(OldName="/Script/VaRest.ERequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus")
+EnumRedirects=(OldName="/Script/VaRest.EHttpStatusCode",NewName="/Script/VaRest.EVaRestHttpStatusCode")
+FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest")
+FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt")
+FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueNumber",NewName="VaRestSubsystem.ConstructJsonValueNumber")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueString",NewName="VaRestSubsystem.ConstructJsonValueString")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueBool",NewName="VaRestSubsystem.ConstructJsonValueBool")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueArray",NewName="VaRestSubsystem.ConstructJsonValueArray")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueObject",NewName="VaRestSubsystem.ConstructJsonValueObject")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValue",NewName="VaRestSubsystem.ConstructJsonValue")
16 changes: 13 additions & 3 deletions Config/DefaultVaRest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
+ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestRequestJSON",NewName="/Script/VaRest.VaRestRequestJSON")
+StructRedirects=(OldName="/Script/VaRestPlugin.VaRestCallResponse",NewName="/Script/VaRest.VaRestCallResponse")
+EnumRedirects=(OldName="/Script/VaRestPlugin.EVaJson",NewName="/Script/VaRest.EVaJson")
+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestVerb",NewName="/Script/VaRest.ERequestVerb")
+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestContentType",NewName="/Script/VaRest.ERequestContentType")
+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestStatus",NewName="/Script/VaRest.ERequestStatus")
+EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb")
+EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType")
+EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus")
+EnumRedirects=(OldName="/Script/VaRest.ERequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb")
+EnumRedirects=(OldName="/Script/VaRest.ERequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType")
+EnumRedirects=(OldName="/Script/VaRest.ERequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus")
+EnumRedirects=(OldName="/Script/VaRest.EHttpStatusCode",NewName="/Script/VaRest.EVaRestHttpStatusCode")
+FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest")
+FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt")
+FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueNumber",NewName="VaRestSubsystem.ConstructJsonValueNumber")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueString",NewName="VaRestSubsystem.ConstructJsonValueString")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueBool",NewName="VaRestSubsystem.ConstructJsonValueBool")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueArray",NewName="VaRestSubsystem.ConstructJsonValueArray")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueObject",NewName="VaRestSubsystem.ConstructJsonValueObject")
+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValue",NewName="VaRestSubsystem.ConstructJsonValue")
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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 26** (UE 4.19-4.23)
Current version: **1.1.33** (UE 4.27; please check the [5.0](https://github.com/ufna/VaRest/tree/5.0) branch for UE5 EA support).

![SCREENSHOT](SCREENSHOT.jpg)

Expand All @@ -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.

49 changes: 49 additions & 0 deletions Source/VaRest/Private/VaRest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,56 @@
#include "VaRest.h"

#include "VaRestDefines.h"
#include "VaRestLibrary.h"
#include "VaRestSettings.h"

#include "Developer/Settings/Public/ISettingsModule.h"
#include "UObject/Package.h"

#define LOCTEXT_NAMESPACE "FVaRestModule"

void FVaRestModule::StartupModule()
{
ModuleSettings = NewObject<UVaRestSettings>(GetTransientPackage(), "VaRestSettings", RF_Standalone);
ModuleSettings->AddToRoot();

// Register settings
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->RegisterSettings("Project", "Plugins", "VaRest",
LOCTEXT("RuntimeSettingsName", "VaRest"),
LOCTEXT("RuntimeSettingsDescription", "Configure VaRest plugin settings"),
ModuleSettings);
}

UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *UVaRestLibrary::GetVaRestVersion());
}

void FVaRestModule::ShutdownModule()
{
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->UnregisterSettings("Project", "Plugins", "VaRest");
}

if (!GExitPurge)
{
ModuleSettings->RemoveFromRoot();
}
else
{
ModuleSettings = nullptr;
}
}

UVaRestSettings* FVaRestModule::GetSettings() const
{
check(ModuleSettings);
return ModuleSettings;
}

IMPLEMENT_MODULE(FVaRestModule, VaRest)

DEFINE_LOG_CATEGORY(LogVaRest);

#undef LOCTEXT_NAMESPACE
117 changes: 72 additions & 45 deletions Source/VaRest/Private/VaRestJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,17 @@ void UVaRestJsonObject::SetRootObject(const TSharedPtr<FJsonObject>& JsonObject)
FString UVaRestJsonObject::EncodeJson() const
{
FString OutputString;
TSharedRef<FCondensedJsonStringWriter> Writer = FCondensedJsonStringWriterFactory::Create(&OutputString);
const auto Writer = TJsonWriterFactory<>::Create(&OutputString);
FJsonSerializer::Serialize(JsonObj, Writer);

return OutputString;
}

FString UVaRestJsonObject::EncodeJsonToSingleString() const
{
FString OutputString = EncodeJson();

// Remove line terminators
OutputString.Replace(LINE_TERMINATOR, TEXT(""));

// Remove tabs
OutputString.Replace(LINE_TERMINATOR, TEXT("\t"));
FString OutputString;
const auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString);
FJsonSerializer::Serialize(JsonObj, Writer);

return OutputString;
}
Expand All @@ -69,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)
Expand All @@ -79,7 +75,7 @@ bool UVaRestJsonObject::DecodeJson(const FString& JsonString, bool bUseIncrement
}
else
{
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(*JsonString);
const TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(*JsonString);
TSharedPtr<FJsonObject> OutJsonObj;
if (FJsonSerializer::Deserialize(Reader, OutJsonObj))
{
Expand Down Expand Up @@ -201,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<EJson::Number>(FieldName))
{
UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Number"), *FieldName);
return 0;
}

return static_cast<int64>(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<EJson::String>(FieldName))
Expand Down Expand Up @@ -281,7 +298,7 @@ void UVaRestJsonObject::SetArrayField(const FString& FieldName, const TArray<UVa
// Process input array and COPY original values
for (auto InVal : InArray)
{
TSharedPtr<FJsonValue> JsonVal = InVal->GetRootValue();
const TSharedPtr<FJsonValue> JsonVal = InVal->GetRootValue();

switch (InVal->GetType())
{
Expand Down Expand Up @@ -348,7 +365,7 @@ UVaRestJsonObject* UVaRestJsonObject::GetObjectField(const FString& FieldName) c
return nullptr;
}

TSharedPtr<FJsonObject> JsonObjField = JsonObj->GetObjectField(FieldName);
const TSharedPtr<FJsonObject> JsonObjField = JsonObj->GetObjectField(FieldName);

UVaRestJsonObject* OutRestJsonObj = NewObject<UVaRestJsonObject>();
OutRestJsonObj->SetRootObject(JsonObjField);
Expand All @@ -366,31 +383,45 @@ void UVaRestJsonObject::SetObjectField(const FString& FieldName, UVaRestJsonObje
JsonObj->SetObjectField(FieldName, JsonObject->GetRootObject());
}

//////////////////////////////////////////////////////////////////////////
// Array fields helpers (uniform arrays)

TArray<float> UVaRestJsonObject::GetNumberArrayField(const FString& FieldName) const
void UVaRestJsonObject::SetMapFields_string(const TMap<FString, FString>& Fields)
{
TArray<float> NumberArray;
if (!JsonObj->HasTypedField<EJson::Array>(FieldName) || FieldName.IsEmpty())
for (auto& field : Fields)
{
UE_LOG(LogVaRest, Warning, TEXT("%s: No field with name %s of type Array"), *VA_FUNC_LINE, *FieldName);
return NumberArray;
SetStringField(field.Key, field.Value);
}
}

TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
for (TArray<TSharedPtr<FJsonValue>>::TConstIterator It(JsonArrayValues); It; ++It)
{
auto Value = (*It).Get();
if (Value->Type != EJson::Number)
{
UE_LOG(LogVaRest, Error, TEXT("Not Number element in array with field name %s"), *FieldName);
}
void UVaRestJsonObject::SetMapFields_uint8(const TMap<FString, uint8>& Fields)
{
SetMapFields_Impl(Fields);
}

NumberArray.Add((*It)->AsNumber());
}
void UVaRestJsonObject::SetMapFields_int32(const TMap<FString, int32>& Fields)
{
SetMapFields_Impl(Fields);
}

void UVaRestJsonObject::SetMapFields_int64(const TMap<FString, int64>& Fields)
{
SetMapFields_Impl(Fields);
}

return NumberArray;
void UVaRestJsonObject::SetMapFields_bool(const TMap<FString, bool>& Fields)
{
SetMapFields_Impl(Fields);
}

//////////////////////////////////////////////////////////////////////////
// Array fields helpers (uniform arrays)

TArray<float> UVaRestJsonObject::GetNumberArrayField(const FString& FieldName) const
{
return GetTypeArrayField<float>(FieldName);
}

TArray<int32> UVaRestJsonObject::GetIntegerArrayField(const FString& FieldName) const
{
return GetTypeArrayField<int32>(FieldName);
}

void UVaRestJsonObject::SetNumberArrayField(const FString& FieldName, const TArray<float>& NumberArray)
Expand Down Expand Up @@ -419,10 +450,10 @@ TArray<FString> UVaRestJsonObject::GetStringArrayField(const FString& FieldName)
return StringArray;
}

TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
const TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
for (TArray<TSharedPtr<FJsonValue>>::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);
Expand Down Expand Up @@ -459,10 +490,10 @@ TArray<bool> UVaRestJsonObject::GetBoolArrayField(const FString& FieldName) cons
return BoolArray;
}

TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
const TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
for (TArray<TSharedPtr<FJsonValue>>::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);
Expand Down Expand Up @@ -500,7 +531,7 @@ TArray<UVaRestJsonObject*> UVaRestJsonObject::GetObjectArrayField(const FString&
}

TArray<TSharedPtr<FJsonValue>> ValArray = JsonObj->GetArrayField(FieldName);
for (auto Value : ValArray)
for (const auto& Value : ValArray)
{
if (Value->Type != EJson::Object)
{
Expand Down Expand Up @@ -544,11 +575,7 @@ int32 UVaRestJsonObject::DeserializeFromUTF8Bytes(const ANSICHAR* Bytes, int32 S
const ANSICHAR* EndByte = Bytes + Size;
while (Bytes < EndByte)
{
#if ENGINE_MINOR_VERSION >= 19
TCHAR Char = FUtf8Helper::CodepointFromUtf8(Bytes, EndByte - Bytes);
#else
TCHAR Char = FUTF8ToTCHAR_Convert::utf8codepoint(&Bytes);
#endif
if (Char > 0xFFFF)
{
Char = UNICODE_BOGUS_CHAR_CODEPOINT;
Expand Down Expand Up @@ -619,11 +646,11 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr<FArchive>& Reader)

if (bIsIntelByteOrder)
{
Char = CharCast<TCHAR>((UCS2CHAR)((uint16)SymbolBytes[0] + (uint16)SymbolBytes[1] * 256));
Char = CharCast<TCHAR>(static_cast<UCS2CHAR>(static_cast<uint16>(SymbolBytes[0]) + static_cast<uint16>(SymbolBytes[1]) * 256));
}
else
{
Char = CharCast<TCHAR>((UCS2CHAR)((uint16)SymbolBytes[1] + (uint16)SymbolBytes[0] * 256));
Char = CharCast<TCHAR>(static_cast<UCS2CHAR>(static_cast<uint16>(SymbolBytes[1]) + static_cast<uint16>(SymbolBytes[0]) * 256));
}

if (!JsonReader.Read(Char))
Expand All @@ -643,7 +670,7 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr<FArchive>& Reader)
//////////////////////////////////////////////////////////////////////////
// Serialize

bool UVaRestJsonObject::WriteToFile(const FString& Path)
bool UVaRestJsonObject::WriteToFile(const FString& Path) const
{
TUniquePtr<FArchive> FileWriter(IFileManager::Get().CreateFileWriter(*Path));
if (!FileWriter)
Expand Down Expand Up @@ -699,8 +726,8 @@ bool UVaRestJsonObject::WriteToFilePath(const FString& Path, const bool bIsRelat

bool UVaRestJsonObject::WriteStringToArchive(FArchive& Ar, const TCHAR* StrPtr, int64 Len)
{
auto Src = StringCast<UCS2CHAR>(StrPtr, Len);
Ar.Serialize((UCS2CHAR*)Src.Get(), Src.Length() * sizeof(UCS2CHAR));
const auto Src = StringCast<UCS2CHAR>(StrPtr, Len);
Ar.Serialize(const_cast<UCS2CHAR*>(Src.Get()), Src.Length() * sizeof(UCS2CHAR));

return true;
}
Loading

0 comments on commit c8ae7b0

Please sign in to comment.