Skip to content

Commit a4b5913

Browse files
[Serialization] Added partial support for serializing types with Serializable attribute in staple assets;
1 parent be2ca4a commit a4b5913

File tree

5 files changed

+485
-135
lines changed

5 files changed

+485
-135
lines changed

Engine/Core/MessagePackGenerated/MessagePackGenerated.cs

Lines changed: 83 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal static class GeneratedResolverGetFormatterHelper
5050

5151
static GeneratedResolverGetFormatterHelper()
5252
{
53-
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(100)
53+
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(101)
5454
{
5555
{ typeof(global::System.Collections.Generic.Dictionary<global::Staple.AppPlatform, global::Staple.Internal.TextureMetadataOverride>), 0 },
5656
{ typeof(global::System.Collections.Generic.Dictionary<global::Staple.AppPlatform, global::System.Collections.Generic.List<global::Staple.RendererType>>), 1 },
@@ -137,21 +137,22 @@ static GeneratedResolverGetFormatterHelper()
137137
{ typeof(global::Staple.Internal.SerializableShader), 82 },
138138
{ typeof(global::Staple.Internal.SerializableShaderHeader), 83 },
139139
{ typeof(global::Staple.Internal.SerializableStapleAsset), 84 },
140-
{ typeof(global::Staple.Internal.SerializableStapleAssetHeader), 85 },
141-
{ typeof(global::Staple.Internal.SerializableStapleAssetParameter), 86 },
142-
{ typeof(global::Staple.Internal.SerializableTexture), 87 },
143-
{ typeof(global::Staple.Internal.SerializableTextureHeader), 88 },
144-
{ typeof(global::Staple.Internal.ShaderMetadata), 89 },
145-
{ typeof(global::Staple.Internal.ShaderUniform), 90 },
146-
{ typeof(global::Staple.Internal.TextureMetadata), 91 },
147-
{ typeof(global::Staple.Internal.TextureMetadataOverride), 92 },
148-
{ typeof(global::Staple.Internal.TextureSpriteInfo), 93 },
149-
{ typeof(global::Staple.Internal.Vector2Holder), 94 },
150-
{ typeof(global::Staple.Internal.Vector3Holder), 95 },
151-
{ typeof(global::Staple.Internal.Vector4Holder), 96 },
152-
{ typeof(global::Staple.Rect), 97 },
153-
{ typeof(global::Staple.RectFloat), 98 },
154-
{ typeof(global::Staple.Vector2Int), 99 },
140+
{ typeof(global::Staple.Internal.SerializableStapleAssetContainer), 85 },
141+
{ typeof(global::Staple.Internal.SerializableStapleAssetHeader), 86 },
142+
{ typeof(global::Staple.Internal.SerializableStapleAssetParameter), 87 },
143+
{ typeof(global::Staple.Internal.SerializableTexture), 88 },
144+
{ typeof(global::Staple.Internal.SerializableTextureHeader), 89 },
145+
{ typeof(global::Staple.Internal.ShaderMetadata), 90 },
146+
{ typeof(global::Staple.Internal.ShaderUniform), 91 },
147+
{ typeof(global::Staple.Internal.TextureMetadata), 92 },
148+
{ typeof(global::Staple.Internal.TextureMetadataOverride), 93 },
149+
{ typeof(global::Staple.Internal.TextureSpriteInfo), 94 },
150+
{ typeof(global::Staple.Internal.Vector2Holder), 95 },
151+
{ typeof(global::Staple.Internal.Vector3Holder), 96 },
152+
{ typeof(global::Staple.Internal.Vector4Holder), 97 },
153+
{ typeof(global::Staple.Rect), 98 },
154+
{ typeof(global::Staple.RectFloat), 99 },
155+
{ typeof(global::Staple.Vector2Int), 100 },
155156
};
156157
}
157158

@@ -250,21 +251,22 @@ internal static object GetFormatter(Type t)
250251
case 82: return new MessagePack.Formatters.Staple.Internal.SerializableShaderFormatter();
251252
case 83: return new MessagePack.Formatters.Staple.Internal.SerializableShaderHeaderFormatter();
252253
case 84: return new MessagePack.Formatters.Staple.Internal.SerializableStapleAssetFormatter();
253-
case 85: return new MessagePack.Formatters.Staple.Internal.SerializableStapleAssetHeaderFormatter();
254-
case 86: return new MessagePack.Formatters.Staple.Internal.SerializableStapleAssetParameterFormatter();
255-
case 87: return new MessagePack.Formatters.Staple.Internal.SerializableTextureFormatter();
256-
case 88: return new MessagePack.Formatters.Staple.Internal.SerializableTextureHeaderFormatter();
257-
case 89: return new MessagePack.Formatters.Staple.Internal.ShaderMetadataFormatter();
258-
case 90: return new MessagePack.Formatters.Staple.Internal.ShaderUniformFormatter();
259-
case 91: return new MessagePack.Formatters.Staple.Internal.TextureMetadataFormatter();
260-
case 92: return new MessagePack.Formatters.Staple.Internal.TextureMetadataOverrideFormatter();
261-
case 93: return new MessagePack.Formatters.Staple.Internal.TextureSpriteInfoFormatter();
262-
case 94: return new MessagePack.Formatters.Staple.Internal.Vector2HolderFormatter();
263-
case 95: return new MessagePack.Formatters.Staple.Internal.Vector3HolderFormatter();
264-
case 96: return new MessagePack.Formatters.Staple.Internal.Vector4HolderFormatter();
265-
case 97: return new MessagePack.Formatters.Staple.RectFormatter();
266-
case 98: return new MessagePack.Formatters.Staple.RectFloatFormatter();
267-
case 99: return new MessagePack.Formatters.Staple.Vector2IntFormatter();
254+
case 85: return new MessagePack.Formatters.Staple.Internal.SerializableStapleAssetContainerFormatter();
255+
case 86: return new MessagePack.Formatters.Staple.Internal.SerializableStapleAssetHeaderFormatter();
256+
case 87: return new MessagePack.Formatters.Staple.Internal.SerializableStapleAssetParameterFormatter();
257+
case 88: return new MessagePack.Formatters.Staple.Internal.SerializableTextureFormatter();
258+
case 89: return new MessagePack.Formatters.Staple.Internal.SerializableTextureHeaderFormatter();
259+
case 90: return new MessagePack.Formatters.Staple.Internal.ShaderMetadataFormatter();
260+
case 91: return new MessagePack.Formatters.Staple.Internal.ShaderUniformFormatter();
261+
case 92: return new MessagePack.Formatters.Staple.Internal.TextureMetadataFormatter();
262+
case 93: return new MessagePack.Formatters.Staple.Internal.TextureMetadataOverrideFormatter();
263+
case 94: return new MessagePack.Formatters.Staple.Internal.TextureSpriteInfoFormatter();
264+
case 95: return new MessagePack.Formatters.Staple.Internal.Vector2HolderFormatter();
265+
case 96: return new MessagePack.Formatters.Staple.Internal.Vector3HolderFormatter();
266+
case 97: return new MessagePack.Formatters.Staple.Internal.Vector4HolderFormatter();
267+
case 98: return new MessagePack.Formatters.Staple.RectFormatter();
268+
case 99: return new MessagePack.Formatters.Staple.RectFloatFormatter();
269+
case 100: return new MessagePack.Formatters.Staple.Vector2IntFormatter();
268270
default: return null;
269271
}
270272
}
@@ -3250,6 +3252,56 @@ public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::
32503252
}
32513253
}
32523254

3255+
public sealed class SerializableStapleAssetContainerFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::Staple.Internal.SerializableStapleAssetContainer>
3256+
{
3257+
3258+
public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::Staple.Internal.SerializableStapleAssetContainer value, global::MessagePack.MessagePackSerializerOptions options)
3259+
{
3260+
if (value == null)
3261+
{
3262+
writer.WriteNil();
3263+
return;
3264+
}
3265+
3266+
global::MessagePack.IFormatterResolver formatterResolver = options.Resolver;
3267+
writer.WriteArrayHeader(2);
3268+
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.typeName, options);
3269+
formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.Dictionary<string, global::Staple.Internal.SerializableStapleAssetParameter>>().Serialize(ref writer, value.parameters, options);
3270+
}
3271+
3272+
public global::Staple.Internal.SerializableStapleAssetContainer Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
3273+
{
3274+
if (reader.TryReadNil())
3275+
{
3276+
return null;
3277+
}
3278+
3279+
options.Security.DepthStep(ref reader);
3280+
global::MessagePack.IFormatterResolver formatterResolver = options.Resolver;
3281+
var length = reader.ReadArrayHeader();
3282+
var ____result = new global::Staple.Internal.SerializableStapleAssetContainer();
3283+
3284+
for (int i = 0; i < length; i++)
3285+
{
3286+
switch (i)
3287+
{
3288+
case 0:
3289+
____result.typeName = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
3290+
break;
3291+
case 1:
3292+
____result.parameters = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.Dictionary<string, global::Staple.Internal.SerializableStapleAssetParameter>>().Deserialize(ref reader, options);
3293+
break;
3294+
default:
3295+
reader.Skip();
3296+
break;
3297+
}
3298+
}
3299+
3300+
reader.Depth--;
3301+
return ____result;
3302+
}
3303+
}
3304+
32533305
public sealed class SerializableStapleAssetHeaderFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::Staple.Internal.SerializableStapleAssetHeader>
32543306
{
32553307

0 commit comments

Comments
 (0)