You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- Each tool can have a number of deployments which are rolled out over time. Clients can specify a "phase" value indicating where in the queue they want to take updates (ie. whether they want to be early- or late-adopters), and deployments can be paused and cancelled. - Tool channels are configured through the global configuration file. Tools can be marked "public", meaning that they do not require authentication against Horde for access. This can be useful for auto-update scenarios. - The most recent 5 deployments are kept in the tool at any time. The collection and controller implementation here is an experiment in reducing the amount of boilerplate currently adopted as a pattern in Horde. Notably: - Model and collection classes are concrete rather than interfaces (since we don't generally mock them anyway). - The same model class with annotations is used for response objects (paving the way to supporting patching and filtering using the same public model as the internal model). - The VersionedCollection class is used to handle automatic migration of documents across schema versions, and cache document values with Redis. - MongoDB property names are explicit and short, rather than just taking variable names. #preflight none [CL 19636699 by Ben Marsh in ue5-main branch]
211 lines
5.5 KiB
C#
211 lines
5.5 KiB
C#
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
using EpicGames.Core;
|
|
using System;
|
|
|
|
namespace EpicGames.Serialization
|
|
{
|
|
/// <summary>
|
|
/// Marks a class as supporting serialization to compact-binary, even if it does not have exposed fields. This suppresses errors
|
|
/// when base class objects are empty.
|
|
/// </summary>
|
|
[AttributeUsage(AttributeTargets.Class)]
|
|
public class CbObjectAttribute : Attribute
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attribute used to mark a property that should be serialized to compact binary
|
|
/// </summary>
|
|
[AttributeUsage(AttributeTargets.Property)]
|
|
public class CbFieldAttribute : Attribute
|
|
{
|
|
/// <summary>
|
|
/// Name of the serialized field
|
|
/// </summary>
|
|
public string? Name { get; set; }
|
|
|
|
/// <summary>
|
|
/// Default constructor
|
|
/// </summary>
|
|
public CbFieldAttribute()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
public CbFieldAttribute(string name)
|
|
{
|
|
Name = name;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attribute used to indicate that this object is the base for a class hierarchy. Each derived class must have a [CbDiscriminator] attribute.
|
|
/// </summary>
|
|
public class CbPolymorphicAttribute : Attribute
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the name used for discriminating between derived classes during serialization
|
|
/// </summary>
|
|
public class CbDiscriminatorAttribute : Attribute
|
|
{
|
|
/// <summary>
|
|
/// Name used to identify this class
|
|
/// </summary>
|
|
public string Name { get; }
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="name">Name used to identify this class</param>
|
|
public CbDiscriminatorAttribute(string name) => Name = name;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Exception thrown when serializing cb objects
|
|
/// </summary>
|
|
public class CbException : Exception
|
|
{
|
|
/// <inheritdoc cref="Exception(String?)"/>
|
|
public CbException(string message) : base(message)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc cref="Exception(String?, Exception)"/>
|
|
public CbException(string message, Exception inner) : base(message, inner)
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Exception indicating that a class does not have any fields to serialize
|
|
/// </summary>
|
|
public sealed class CbEmptyClassException : CbException
|
|
{
|
|
/// <summary>
|
|
/// Type with missing field annotations
|
|
/// </summary>
|
|
public Type Type { get; }
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
public CbEmptyClassException(Type type)
|
|
: base($"{type.Name} does not have any fields marked with a [CbField] attribute. If this is intended, explicitly mark the class with a [CbObject] attribute.")
|
|
{
|
|
Type = type;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attribute-driven compact binary serializer
|
|
/// </summary>
|
|
public static class CbSerializer
|
|
{
|
|
/// <summary>
|
|
/// Serialize an object
|
|
/// </summary>
|
|
/// <param name="type">Type of the object to serialize</param>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static CbObject Serialize(Type type, object value)
|
|
{
|
|
CbWriter writer = new CbWriter();
|
|
CbConverter.GetConverter(type).WriteObject(writer, value);
|
|
return writer.ToObject();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Serialize an object
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static CbObject Serialize<T>(T value)
|
|
{
|
|
CbWriter writer = new CbWriter();
|
|
CbConverter.GetConverter<T>().Write(writer, value);
|
|
return writer.ToObject();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Serialize an object
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static byte[] SerializeToByteArray<T>(T value)
|
|
{
|
|
CbWriter writer = new CbWriter();
|
|
CbConverter.GetConverter<T>().Write(writer, value);
|
|
return writer.ToByteArray();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Serialize a property to a given writer
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="writer"></param>
|
|
/// <param name="value"></param>
|
|
public static void Serialize<T>(CbWriter writer, T value)
|
|
{
|
|
CbConverter.GetConverter<T>().Write(writer, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Serialize a named property to the given writer
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="writer"></param>
|
|
/// <param name="name"></param>
|
|
/// <param name="value"></param>
|
|
public static void Serialize<T>(CbWriter writer, Utf8String name, T value)
|
|
{
|
|
CbConverter.GetConverter<T>().WriteNamed(writer, name, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deserialize an object from a <see cref="CbObject"/>
|
|
/// </summary>
|
|
/// <param name="field"></param>
|
|
/// <param name="type">Type of the object to read</param>
|
|
/// <returns></returns>
|
|
public static object? Deserialize(CbField field, Type type)
|
|
{
|
|
return CbConverter.GetConverter(type).ReadObject(field);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deserialize an object from a <see cref="CbField"/>
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="field"></param>
|
|
/// <returns></returns>
|
|
public static T Deserialize<T>(CbField field)
|
|
{
|
|
return CbConverter.GetConverter<T>().Read(field);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deserialize an object from a <see cref="CbObject"/>
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public static T Deserialize<T>(CbObject obj) => Deserialize<T>(obj.AsField());
|
|
|
|
/// <summary>
|
|
/// Deserialize an object from a block of memory
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public static T Deserialize<T>(ReadOnlyMemory<byte> data) => Deserialize<T>(new CbField(data));
|
|
}
|
|
}
|