Skip to content

custom formatters code source generator error #2005

@s-anzai

Description

@s-anzai

Thank you for your hard work.

I was using 2.5.172 originally, but when I upgraded to 3.0.134-beta,

the parts using custom formatters stopped working.

I thought it might be a problem with how I was using it, so I tried using the sample built-in formatters as shown below, but it doesn't seem to work either.

using MessagePack;
using MessagePack.Formatters;
using System;

namespace SP.Runtime
{
	[MessagePackObject]
	public partial class SampleObject
	{
		[Key(0)] public string  Name     { get; set; }
		[Key(1)] public int At { get; set; }

		[Key(2)] [MessagePackFormatter(typeof(ValueTupleFormatter<string>))]
        		private ValueTuple<string> TupleTest;
	}

	public sealed class ValueTupleFormatter<T1> : IMessagePackFormatter<ValueTuple<T1>>
	{
		public void Serialize(ref MessagePackWriter writer, ValueTuple<T1> value, MessagePackSerializerOptions options)
		{
			writer.WriteArrayHeader(1);

			IFormatterResolver resolver = options.Resolver;
			resolver.GetFormatterWithVerify<T1>().Serialize(ref writer, value.Item1, options);
		}

		public ValueTuple<T1> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
		{
			if (reader.IsNil)
			{
				throw new MessagePackSerializationException("Nil");
				//throw MessagePackSerializationException.ThrowUnexpectedNilWhileDeserializing<ValueTuple<T1>>();
			}
			else
			{
				var count = reader.ReadArrayHeader();
				if (count != 1)
				{
					throw new MessagePackSerializationException("Invalid ValueTuple count");
				}

				IFormatterResolver resolver = options.Resolver;
				options.Security.DepthStep(ref reader);
				try
				{
					T1 item1 = resolver.GetFormatterWithVerify<T1>().Deserialize(ref reader, options);

					return new ValueTuple<T1>(item1);
				}
				finally
				{
					reader.Depth--;
				}
			}
		}
	}
}

.g.cs

private readonly global::MessagePack.Formatters.TupleFormatter<string> __TupleTestCustomFormatter__ = new global::MessagePack.Formatters.TupleFormatter<T1>();

Unity 6000.0.10f1
Message Pack v3.0.134-beta

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions