2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-09-13 12:43:17 +00:00
This commit is contained in:
2025-08-31 06:06:30 +03:00
parent 89d395f83f
commit eee5c7c036
8 changed files with 138 additions and 86 deletions

View File

@@ -265,7 +265,7 @@ public static class Codec
return false;
}
public delegate (TransmissionTypeIdentifier, byte[]) Composer(object value, DistributedConnection connection);
public delegate (TransmissionTypeIdentifier, byte[]) Composer(object value, Warehouse warehouse, DistributedConnection connection);
public static Dictionary<Type, Composer> Composers = new Dictionary<Type, Composer>()
{
@@ -346,7 +346,7 @@ public static class Codec
/// <param name="connection">DistributedConnection is required to check locality.</param>
/// <param name="prependType">If True, prepend the DataType at the beginning of the output.</param>
/// <returns>Array of bytes in the network byte order.</returns>
public static byte[] Compose(object valueOrSource, DistributedConnection connection)//, bool prependType = true)
public static byte[] Compose(object valueOrSource, Warehouse warehouse, DistributedConnection connection)//, bool prependType = true)
{
@@ -389,30 +389,32 @@ public static class Codec
if (Composers.ContainsKey(type))
{
var (hdr, data) = Composers[type](valueOrSource, connection);
var (hdr, data) = Composers[type](valueOrSource, warehouse, connection);
return TransmissionType.Compose(hdr, data);
}
else
{
if (Codec.ImplementsInterface(type, typeof(IResource)))
{
var (hdr, data) = DataSerializer.ResourceComposer(valueOrSource, connection);
var (hdr, data) = DataSerializer.ResourceComposer(valueOrSource, warehouse, connection);
return TransmissionType.Compose(hdr, data);
}
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
{
var (hdr, data) = DataSerializer.RecordComposer(valueOrSource, connection);
var (hdr, data) = DataSerializer.RecordComposer(valueOrSource, warehouse, connection);
return TransmissionType.Compose(hdr, data);
}
else if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
if (genericType == typeof(List<>) || genericType == typeof(VarList<>))
if (genericType == typeof(List<>)
|| genericType == typeof(VarList<>)
|| genericType == typeof(IList<>))
{
var args = type.GetGenericArguments();
//if (Composers.ContainsKey(args[0]))
//{
var (hdr, data) = DataSerializer.TypedListComposer((IEnumerable)valueOrSource, args[0], connection);
var (hdr, data) = DataSerializer.TypedListComposer((IEnumerable)valueOrSource, args[0], warehouse, connection);
return TransmissionType.Compose(hdr, data);
//}
}
@@ -420,10 +422,19 @@ public static class Codec
{
var args = type.GetGenericArguments();
var (hdr, data) = DataSerializer.TypedMapComposer(valueOrSource, args[0], args[1], connection);
var (hdr, data) = DataSerializer.TypedMapComposer(valueOrSource, args[0], args[1], warehouse, connection);
return TransmissionType.Compose(hdr, data);
}
else if (genericType == typeof(Dictionary<,>))
{
var args = type.GetGenericArguments();
var (hdr, data) = DataSerializer.TypedDictionaryComposer(valueOrSource, args[0], args[1], warehouse, connection);
return TransmissionType.Compose(hdr, data);
}
else if (genericType == typeof(ValueTuple<,>)
|| genericType == typeof(ValueTuple<,,>)
|| genericType == typeof(ValueTuple<,,,>)
@@ -432,7 +443,7 @@ public static class Codec
|| genericType == typeof(ValueTuple<,,,,,,>)
)
{
var (hdr, data) = DataSerializer.TupleComposer(valueOrSource, connection);
var (hdr, data) = DataSerializer.TupleComposer(valueOrSource, warehouse, connection);
return TransmissionType.Compose(hdr, data);
}
}
@@ -442,14 +453,14 @@ public static class Codec
//if (Composers.ContainsKey(elementType))
//{
var (hdr, data) = DataSerializer.TypedListComposer((IEnumerable)valueOrSource, elementType, connection);
var (hdr, data) = DataSerializer.TypedListComposer((IEnumerable)valueOrSource, elementType, warehouse, connection);
return TransmissionType.Compose(hdr, data);
//}
}
else if (type.IsEnum)
{
var (hdr, data) = DataSerializer.EnumComposer(valueOrSource, connection);
var (hdr, data) = DataSerializer.EnumComposer(valueOrSource, warehouse, connection);
return TransmissionType.Compose(hdr, data);
}