Files
UnrealEngineUWP/Engine/Source/Runtime/Serialization/Public/Backends/JsonStructSerializerBackend.h
Max Preussner ee737c35e8 Serialization: Treating dictionaries as structs (for symmetry with, and simplified de-serialization)
#CodeReview: keli.hlodversson, justin.sargent

[CL 2685160 by Max Preussner in Main branch]
2015-09-09 15:08:41 -04:00

52 lines
1.5 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "IStructSerializerBackend.h"
#include "Json.h"
// forward declarations
class UProperty;
class UStruct;
/**
* Implements a writer for UStruct serialization using Json.
*
* Note: The underlying Json serializer is currently hard-coded to use UCS2CHAR and pretty-print.
* This is because the current JsonWriter API does not allow writers to be substituted since it's
* all based on templates. At some point we will refactor the low-level Json API to provide more
* flexibility for serialization.
*/
class SERIALIZATION_API FJsonStructSerializerBackend
: public IStructSerializerBackend
{
public:
/**
* Creates and initializes a new instance.
*
* @param Archive The archive to serialize into.
*/
FJsonStructSerializerBackend( FArchive& Archive )
: JsonWriter(TJsonWriter<UCS2CHAR>::Create(&Archive))
{ }
public:
// IStructSerializerBackend interface
virtual void BeginArray(const FStructSerializerState& State) override;
virtual void BeginStructure(const FStructSerializerState& State) override;
virtual void EndArray(const FStructSerializerState& State) override;
virtual void EndStructure(const FStructSerializerState& State) override;
virtual void WriteComment(const FString& Comment) override;
virtual void WriteProperty(const FStructSerializerState& State, int32 ArrayIndex = 0) override;
private:
/** Holds the Json writer used for the actual serialization. */
TSharedRef<TJsonWriter<UCS2CHAR>> JsonWriter;
};