Skip to content

Commit 3103604

Browse files
committed
merge
2 parents 078f333 + 512fa66 commit 3103604

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

SocketIOClient.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "2.8.3",
4+
"VersionName": "2.8.5",
55
"EngineVersion": "5.5",
66
"FriendlyName": "Socket.IO Client",
77
"Description": "Real-time WebSocket networking via Socket.IO protocol usable from blueprints and c++.",

Source/CoreUtility/Public/CUOpusCoder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include "CoreMinimal.h"
66

7-
#define WITH_OPUS (PLATFORM_WINDOWS || PLATFORM_UNIX || PLATFORM_ANDROID)
7+
#ifndef WITH_OPUS
8+
#define WITH_OPUS (PLATFORM_WINDOWS || PLATFORM_UNIX || PLATFORM_ANDROID)
9+
#endif
810

911
#if WITH_OPUS
1012
#include "ThirdParty/libOpus/opus-1.1/include/opus.h"

Source/SIOJson/Private/SIOJConvert.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -835,36 +835,52 @@ bool USIOJConvert::JsonObjectToUStruct(TSharedPtr<FJsonObject> JsonObject, UStru
835835
bool USIOJConvert::JsonFileToUStruct(const FString& FilePath, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct /*= false*/)
836836
{
837837
//Read bytes from file
838-
TArray<uint8> OutBytes;
839-
if (!FFileHelper::LoadFileToArray(OutBytes, *FilePath))
838+
TArray<uint8> ReadBytes;
839+
if (!FFileHelper::LoadFileToArray(ReadBytes, *FilePath))
840840
{
841841
return false;
842842
}
843843

844-
//Convert to json string
845-
FString JsonString;
846-
FFileHelper::BufferToString(JsonString, OutBytes.GetData(), OutBytes.Num());
847-
848-
//Read into struct
849-
return JsonObjectToUStruct(ToJsonObject(JsonString), Struct, StructPtr, IsBlueprintStruct);
844+
return BytesToStruct(ReadBytes, Struct, StructPtr, IsBlueprintStruct);
850845
}
851846

852847
bool USIOJConvert::ToJsonFile(const FString& FilePath, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct /*= false*/)
848+
{
849+
TArray<uint8> Bytes;
850+
StructToBytes(Struct, StructPtr, Bytes, IsBlueprintStruct);
851+
852+
//flush to disk
853+
return FFileHelper::SaveArrayToFile(Bytes, *FilePath);
854+
}
855+
856+
bool USIOJConvert::StructToBytes(UStruct* Struct, void* StructPtr, TArray<uint8>& OutBytes, bool IsBlueprintStruct)
853857
{
854858
//Get json object with trimmed values
855859
TSharedPtr<FJsonObject> JsonObject = ToJsonObject(Struct, StructPtr, IsBlueprintStruct);
856860
TSharedPtr<FJsonValue> TrimmedValue = MakeShareable(new FJsonValueObject(JsonObject));
857-
TrimValueKeyNames(TrimmedValue);
861+
862+
if (IsBlueprintStruct)
863+
{
864+
TrimValueKeyNames(TrimmedValue);
865+
}
858866

859867
//Convert to string
860868
FString JsonString = ToJsonString(TrimmedValue);
861869
FTCHARToUTF8 Utf8String(*JsonString);
862870

863-
TArray<uint8> Bytes;
864-
Bytes.Append((uint8*)Utf8String.Get(), Utf8String.Length());
871+
OutBytes.Append((uint8*)Utf8String.Get(), Utf8String.Length());
865872

866-
//flush to disk
867-
return FFileHelper::SaveArrayToFile(Bytes, *FilePath);
873+
return true;
874+
}
875+
876+
bool USIOJConvert::BytesToStruct(const TArray<uint8>& InBytes, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct)
877+
{
878+
//Convert to json string
879+
FString JsonString;
880+
FFileHelper::BufferToString(JsonString, InBytes.GetData(), InBytes.Num());
881+
882+
//Read into struct
883+
return JsonObjectToUStruct(ToJsonObject(JsonString), Struct, StructPtr, IsBlueprintStruct);
868884
}
869885

870886
void USIOJConvert::TrimValueKeyNames(const TSharedPtr<FJsonValue>& JsonValue)

Source/SIOJson/Public/SIOJConvert.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class SIOJSON_API USIOJConvert : public UObject
4848
static bool JsonFileToUStruct(const FString& FilePath, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false);
4949
static bool ToJsonFile(const FString& FilePath, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false);
5050

51+
static bool StructToBytes(UStruct* Struct, void* StructPtr, TArray<uint8>& OutBytes, bool IsBlueprintStruct = false);
52+
static bool BytesToStruct(const TArray<uint8>& InBytes, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false);
53+
5154
//typically from callbacks
5255
static class USIOJsonValue* ToSIOJsonValue(const TArray<TSharedPtr<FJsonValue>>& JsonValueArray);
5356

0 commit comments

Comments
 (0)