Last active
July 24, 2025 18:26
-
-
Save zr0n/f6cb488c7c86e8d88e122a1e4d88b6db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UCXRuntimeMessageData* Event = NewObject<UCXRuntimeMessageData>(); | |
| Event->Name = TEXT("stutter_occurred"); | |
| Event->AddStringMetadata(TEXT("reason"), TEXT("Something happened with the video player")); | |
| Event->SendMessage(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include "CoreMinimal.h" | |
| #include "UObject/NoExportTypes.h" | |
| #include "Dom/JsonObject.h" | |
| #include "Dom/JsonValue.h" | |
| #include "CXRuntimeMessageData.generated.h" | |
| UCLASS(BlueprintType) | |
| class CXPRORUNTIMECORE_API UCXRuntimeMessageData : public UObject | |
| { | |
| GENERATED_BODY() | |
| public: | |
| UPROPERTY(BlueprintReadWrite, Category = "CXRuntime|Message") | |
| FString Name; | |
| UPROPERTY(BlueprintReadWrite, Category = "CXRuntime|Message") | |
| FDateTime Timestamp; | |
| UPROPERTY(BlueprintReadWrite, Category = "CXRuntime|Message") | |
| TArray<TSharedPtr<FJsonValue>> Metadata; | |
| UCXRuntimeMessageData(); | |
| UFUNCTION(BlueprintCallable, Category = "CXRuntime|Message|Metadata") | |
| void AddIntMetadata(const FString& MetaName, int32 Value); | |
| UFUNCTION(BlueprintCallable, Category = "CXRuntime|Message|Metadata") | |
| void AddFloatMetadata(const FString& MetaName, float Value); | |
| UFUNCTION(BlueprintCallable, Category = "CXRuntime|Message|Metadata") | |
| void AddStringMetadata(const FString& MetaName, const FString& Value); | |
| UFUNCTION(BlueprintCallable, Category = "CXRuntime|Message|Metadata") | |
| void AddBoolMetadata(const FString& MetaName, bool Value); | |
| UFUNCTION(BlueprintPure, Category = "CXRuntime|Message|Serialization") | |
| FString ToJsonString() const; | |
| UFUNCTION(BlueprintCallable, Category = "CXRuntime|GRPC") | |
| void SendMessage(); //@TODO | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "CXRuntimeMessageData.h" | |
| #include "Serialization/JsonWriter.h" | |
| #include "Serialization/JsonSerializer.h" | |
| UCXRuntimeMessageData::UCXRuntimeMessageData() | |
| { | |
| Timestamp = FDateTime::UtcNow(); | |
| } | |
| void UCXRuntimeMessageData::AddIntMetadata(const FString& MetaName, int32 Value) | |
| { | |
| TSharedPtr<FJsonObject> Obj = MakeShared<FJsonObject>(); | |
| Obj->SetStringField("name", MetaName); | |
| Obj->SetNumberField("value", Value); | |
| Metadata.Add(MakeShared<FJsonValueObject>(Obj)); | |
| } | |
| void UCXRuntimeMessageData::AddFloatMetadata(const FString& MetaName, float Value) | |
| { | |
| TSharedPtr<FJsonObject> Obj = MakeShared<FJsonObject>(); | |
| Obj->SetStringField("name", MetaName); | |
| Obj->SetNumberField("value", Value); | |
| Metadata.Add(MakeShared<FJsonValueObject>(Obj)); | |
| } | |
| void UCXRuntimeMessageData::AddStringMetadata(const FString& MetaName, const FString& Value) | |
| { | |
| TSharedPtr<FJsonObject> Obj = MakeShared<FJsonObject>(); | |
| Obj->SetStringField("name", MetaName); | |
| Obj->SetStringField("value", Value); | |
| Metadata.Add(MakeShared<FJsonValueObject>(Obj)); | |
| } | |
| void UCXRuntimeMessageData::AddBoolMetadata(const FString& MetaName, bool Value) | |
| { | |
| TSharedPtr<FJsonObject> Obj = MakeShared<FJsonObject>(); | |
| Obj->SetStringField("name", MetaName); | |
| Obj->SetBoolField("value", Value); | |
| Metadata.Add(MakeShared<FJsonValueObject>(Obj)); | |
| } | |
| FString UCXRuntimeMessageData::ToJsonString() const | |
| { | |
| TSharedRef<FJsonObject> Root = MakeShared<FJsonObject>(); | |
| Root->SetStringField("name", Name); | |
| Root->SetStringField("timestamp", Timestamp.ToIso8601()); | |
| Root->SetArrayField("metadata", Metadata); | |
| FString Output; | |
| TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&Output); | |
| FJsonSerializer::Serialize(Root, Writer); | |
| return Output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment