-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringEventSerializerBase.cs
49 lines (35 loc) · 1.48 KB
/
StringEventSerializerBase.cs
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
using System;
namespace StreamStore.Serialization
{
public abstract class StringEventSerializerBase : EventSerializerBase
{
protected StringEventSerializerBase(ITypeRegistry registry, bool compression = false): base(registry, compression)
{
}
protected abstract string SerializeEventAsString(object value, Type type);
protected abstract object DeserializeEventFromString(string value, Type type);
protected abstract string SerializeEnvelope(EventEnvelope envelope);
protected abstract EventEnvelope DeserializeEnvelope(string value);
protected override byte[] SerializeEnvelope(string type, byte[] eventData)
{
var envelope = new EventEnvelope
{
Type = type,
Data = eventData
};
return System.Text.Encoding.UTF8.GetBytes(SerializeEnvelope(envelope));
}
protected override byte[] SerializeEvent(object value, Type type)
{
return System.Text.Encoding.UTF8.GetBytes(SerializeEventAsString(value, type));
}
protected override EventEnvelope DeserializeEnvelope(byte[] data)
{
return DeserializeEnvelope(System.Text.Encoding.UTF8.GetString(data));
}
protected override object DeserializeEvent(byte[] eventData, Type type)
{
return DeserializeEventFromString(System.Text.Encoding.UTF8.GetString(eventData), type);
}
}
}