mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-01-27 01:20:39 +00:00
stats
This commit is contained in:
@@ -95,6 +95,7 @@ public static class Codec
|
||||
DataDeserializer.ListParserAsync,
|
||||
DataDeserializer.ResourceListParserAsync,
|
||||
DataDeserializer.RecordListParserAsync,
|
||||
DataDeserializer.ResourceLinkParserAsync,
|
||||
};
|
||||
|
||||
static AsyncParser[] TypedAsyncParsers = new AsyncParser[]
|
||||
@@ -163,6 +164,8 @@ public static class Codec
|
||||
DataDeserializer.ListParser,
|
||||
DataDeserializer.ResourceListParser,
|
||||
DataDeserializer.RecordListParser,
|
||||
DataDeserializer.ResourceLinkParser,
|
||||
// @TODO: Map and MapList parsers to be added
|
||||
};
|
||||
|
||||
static SyncParser[] TypedParsers = new SyncParser[]
|
||||
@@ -343,6 +346,7 @@ public static class Codec
|
||||
[typeof(List<byte>)] = DataSerializer.RawDataComposerFromList,
|
||||
//[typeof(List<byte?>)] = DataSerializer.RawDataComposerFromList,
|
||||
[typeof(string)] = DataSerializer.StringComposer,
|
||||
[typeof(ResourceLink)] = DataSerializer.ResourceLinkComposer,
|
||||
[typeof(UUID)] = DataSerializer.UUIDComposer,
|
||||
// Special
|
||||
[typeof(object[])] = DataSerializer.ListComposer,
|
||||
|
||||
@@ -264,6 +264,25 @@ public static class DataDeserializer
|
||||
}
|
||||
|
||||
|
||||
public static object ResourceLinkParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var link = tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
|
||||
if (connection == null)
|
||||
{
|
||||
return new ResourceLink(link);
|
||||
}
|
||||
else
|
||||
{
|
||||
return connection.Instance.Warehouse.Get<IResource>(link);
|
||||
}
|
||||
}
|
||||
|
||||
public static object ResourceLinkParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
{
|
||||
var link = tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
|
||||
return new ResourceLink(link);
|
||||
}
|
||||
|
||||
public static unsafe object ResourceParser8Async(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
|
||||
{
|
||||
if (connection == null)
|
||||
|
||||
@@ -388,6 +388,14 @@ public static class DataSerializer
|
||||
return new TDU(TDUIdentifier.String, b, (uint)b.Length);
|
||||
}
|
||||
|
||||
public static TDU ResourceLinkComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var b = Encoding.UTF8.GetBytes((ResourceLink)value);
|
||||
|
||||
return new TDU(TDUIdentifier.ResourceLink, b, (uint)b.Length);
|
||||
}
|
||||
|
||||
|
||||
public static TDU EnumComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
|
||||
27
Esiur/Data/ResourceLink.cs
Normal file
27
Esiur/Data/ResourceLink.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Data
|
||||
{
|
||||
public class ResourceLink
|
||||
{
|
||||
readonly string value;
|
||||
|
||||
public ResourceLink(string value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
public static implicit operator string(ResourceLink d)
|
||||
{
|
||||
return d.value;
|
||||
}
|
||||
public static implicit operator ResourceLink(string d)
|
||||
{
|
||||
return new ResourceLink(d);
|
||||
}
|
||||
|
||||
public override string ToString() => value;
|
||||
|
||||
}
|
||||
}
|
||||
27
Esiur/Data/ResourceLinkGeneric.cs
Normal file
27
Esiur/Data/ResourceLinkGeneric.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Data
|
||||
{
|
||||
public class ResourceLink<T>
|
||||
{
|
||||
readonly string value;
|
||||
|
||||
public ResourceLink(string value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
public static implicit operator string(ResourceLink<T> d)
|
||||
{
|
||||
return d.value;
|
||||
}
|
||||
public static implicit operator ResourceLink<T>(string d)
|
||||
{
|
||||
return new ResourceLink<T>(d);
|
||||
}
|
||||
|
||||
public override string ToString() => value;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,9 @@ namespace Esiur.Data
|
||||
List = 0x42,
|
||||
ResourceList = 0x43,
|
||||
RecordList = 0x44,
|
||||
Map = 0x45,
|
||||
MapList = 0x46,
|
||||
ResourceLink = 0x47,
|
||||
ResourceLink = 0x45,
|
||||
Map = 0x46,
|
||||
MapList = 0x47,
|
||||
|
||||
Record = 0x80,
|
||||
TypedList = 0x81,
|
||||
|
||||
@@ -295,10 +295,14 @@ namespace Esiur.Data
|
||||
return new TRU(TRUIdentifier.Resource, nullable);
|
||||
}
|
||||
else if (type == typeof(IRecord) || type == typeof(Record))
|
||||
{
|
||||
return new TRU(TRUIdentifier.Record, nullable);
|
||||
}
|
||||
else if (type == typeof(Map<object, object>)
|
||||
|| type == typeof(Dictionary<object, object>))
|
||||
|| type == typeof(Dictionary<object, object>))
|
||||
{
|
||||
return new TRU(TRUIdentifier.Map, nullable);
|
||||
}
|
||||
else if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
{
|
||||
tru = new TRU(
|
||||
@@ -306,10 +310,6 @@ namespace Esiur.Data
|
||||
nullable,
|
||||
TypeTemplate.GetTypeUUID(type)
|
||||
);
|
||||
|
||||
//_cache.Add(type, tru);
|
||||
|
||||
//return tru;
|
||||
}
|
||||
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
|
||||
{
|
||||
@@ -318,14 +318,11 @@ namespace Esiur.Data
|
||||
nullable,
|
||||
TypeTemplate.GetTypeUUID(type)
|
||||
);
|
||||
|
||||
//_cache.Add(type, tru);
|
||||
|
||||
//return tru;
|
||||
}
|
||||
else if (type.IsGenericType)
|
||||
{
|
||||
var genericType = type.GetGenericTypeDefinition();
|
||||
|
||||
if (genericType == typeof(List<>)
|
||||
|| genericType == typeof(VarList<>)
|
||||
|| genericType == typeof(IList<>))
|
||||
@@ -365,11 +362,17 @@ namespace Esiur.Data
|
||||
if (subType2 == null)
|
||||
return null;
|
||||
|
||||
tru = new TRU(TRUIdentifier.TypedMap, nullable, null,
|
||||
new TRU[] { subType1, subType2 });
|
||||
tru = new TRU(TRUIdentifier.TypedMap, nullable, null,
|
||||
new TRU[] { subType1, subType2 });
|
||||
|
||||
}
|
||||
}
|
||||
else if (genericType == typeof(ResourceLink<>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
|
||||
return FromType(args[0]);
|
||||
}
|
||||
else if (genericType == typeof(ValueTuple<,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
@@ -518,6 +521,7 @@ namespace Esiur.Data
|
||||
_ when type == typeof(decimal) => new TRU(TRUIdentifier.Decimal, nullable),
|
||||
_ when type == typeof(string) => new TRU(TRUIdentifier.String, nullable),
|
||||
_ when type == typeof(DateTime) => new TRU(TRUIdentifier.DateTime, nullable),
|
||||
_ when type == typeof(ResourceLink) => new TRU(TRUIdentifier.Resource, nullable),
|
||||
_ => null
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user