summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/UriDecorator.cs
blob: 4150a60400dd292f49626f646f16ef8af08d46b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using ProtoBuf.Meta;

namespace ProtoBuf.Serializers
{
	internal sealed class UriDecorator : ProtoDecoratorBase
	{
		public override Type ExpectedType
		{
			get
			{
				return UriDecorator.expectedType;
			}
		}

		public override bool RequiresOldValue
		{
			get
			{
				return false;
			}
		}

		public override bool ReturnsValue
		{
			get
			{
				return true;
			}
		}

		private static readonly Type expectedType = typeof(Uri);

		public UriDecorator(TypeModel model, IProtoSerializer tail) : base(tail)
		{
		}

		public override void Write(object value, ProtoWriter dest)
		{
			this.Tail.Write(((Uri)value).AbsoluteUri, dest);
		}

		public override object Read(object value, ProtoReader source)
		{
			Helpers.DebugAssert(value == null);
			string text = (string)this.Tail.Read(null, source);
			return (text.Length == 0) ? null : new Uri(text);
		}
	}
}