Expose more net serializer stuff to content (#3476)

This commit is contained in:
Leon Friedrich
2022-12-31 06:07:33 +13:00
committed by GitHub
parent f3364a196c
commit 66577acd1f
14 changed files with 97 additions and 18 deletions

View File

@@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Reflection;
@@ -13,11 +12,10 @@ using Robust.Shared.Utility;
namespace Robust.Shared.Serialization
{
public sealed partial class RobustSerializer : IRobustSerializer
internal abstract partial class RobustSerializer : IRobustSerializer
{
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
[Dependency] private readonly IRobustMappedStringSerializer _mappedStringSerializer = default!;
[Dependency] protected readonly IRobustMappedStringSerializer MappedStringSerializer = default!;
[Dependency] private readonly ILogManager _logManager = default!;
private readonly Dictionary<Type, Dictionary<string, Type?>> _cachedSerialized = new();
@@ -78,11 +76,11 @@ namespace Robust.Shared.Serialization
LogSzr = _logManager.GetSawmill("szr");
types.AddRange(AlwaysNetSerializable);
_mappedStringSerializer.Initialize();
MappedStringSerializer.Initialize();
var settings = new Settings
{
CustomTypeSerializers = new[] {_mappedStringSerializer.TypeSerializer}
CustomTypeSerializers = new[] {MappedStringSerializer.TypeSerializer}
};
_serializer = new Serializer(types, settings);
_serializableTypes = new HashSet<Type>(_serializer.GetTypeMap().Keys);
@@ -95,6 +93,10 @@ namespace Robust.Shared.Serialization
*/
}
public byte[] GetSerializableTypesHash() => Convert.FromHexString(_serializer.GetSHA256());
public (byte[] Hash, byte[] Package) GetStringSerializerPackage() => MappedStringSerializer.GeneratePackage();
public void Serialize(Stream stream, object toSerialize)
{
var start = stream.Position;