mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-09-13 12:43:17 +00:00
bm
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ public static class DataSerializer
|
||||
{
|
||||
public delegate byte[] Serializer(object value);
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Int32Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Int32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (int)value;
|
||||
var rt = new byte[4];
|
||||
@@ -23,7 +23,7 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.Int32, rt);
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) UInt32Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) UInt32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (uint)value;
|
||||
var rt = new byte[4];
|
||||
@@ -32,7 +32,7 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.UInt32, rt);
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Int16Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Int16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (short)value;
|
||||
var rt = new byte[2];
|
||||
@@ -41,7 +41,7 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.Int16, rt);
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) UInt16Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) UInt16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (ushort)value;
|
||||
var rt = new byte[2];
|
||||
@@ -50,7 +50,7 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.UInt16, rt);
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Float32Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Float32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (float)value;
|
||||
var rt = new byte[4];
|
||||
@@ -59,7 +59,7 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.Float32, rt);
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Float64Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Float64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (double)value;
|
||||
var rt = new byte[8];
|
||||
@@ -68,7 +68,7 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.Float64, rt);
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Int64Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Int64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (long)value;
|
||||
var rt = new byte[8];
|
||||
@@ -77,7 +77,7 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.Int64, rt);
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) UIn64Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) UIn64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (ulong)value;
|
||||
var rt = new byte[8];
|
||||
@@ -87,7 +87,7 @@ public static class DataSerializer
|
||||
}
|
||||
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) DateTimeComposer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) DateTimeComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = ((DateTime)value).ToUniversalTime().Ticks;
|
||||
var rt = new byte[8];
|
||||
@@ -96,7 +96,7 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.DateTime, rt);
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Float128Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Float128Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var v = (decimal)value;
|
||||
var rt = new byte[16];
|
||||
@@ -107,19 +107,19 @@ public static class DataSerializer
|
||||
|
||||
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) StringComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) StringComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return (TransmissionTypeIdentifier.String, Encoding.UTF8.GetBytes((string)value));
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) EnumComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) EnumComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
|
||||
var warehouse = connection?.Instance?.Warehouse ?? connection?.Server?.Instance?.Warehouse;
|
||||
if (warehouse == null)
|
||||
throw new Exception("Warehouse not set.");
|
||||
//var warehouse = connection?.Instance?.Warehouse ?? connection?.Server?.Instance?.Warehouse;
|
||||
//if (warehouse == null)
|
||||
// throw new Exception("Warehouse not set.");
|
||||
|
||||
var template = warehouse.GetTemplateByType(value.GetType());
|
||||
|
||||
@@ -138,22 +138,22 @@ public static class DataSerializer
|
||||
return (TransmissionTypeIdentifier.TypedEnum, rt.ToArray());
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) UInt8Composer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) UInt8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return (TransmissionTypeIdentifier.UInt8, new byte[] { (byte)value });
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) Int8Composer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) Int8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return (TransmissionTypeIdentifier.Int8, new byte[] { (byte)(sbyte)value });
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Char8Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Char8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return (TransmissionTypeIdentifier.Char8, new byte[] { (byte)(char)value });
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Char16Composer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) Char16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
|
||||
var v = (char)value;
|
||||
@@ -164,23 +164,23 @@ public static class DataSerializer
|
||||
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) BoolComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) BoolComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return ((bool)value ? TransmissionTypeIdentifier.True : TransmissionTypeIdentifier.False, new byte[0]);
|
||||
}
|
||||
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) NotModifiedComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) NotModifiedComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return (TransmissionTypeIdentifier.NotModified, new byte[0]);
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) RawDataComposerFromArray(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) RawDataComposerFromArray(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return (TransmissionTypeIdentifier.RawData, (byte[])value);
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) RawDataComposerFromList(dynamic value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) RawDataComposerFromList(dynamic value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return (TransmissionTypeIdentifier.RawData, (value as List<byte>).ToArray());
|
||||
}
|
||||
@@ -196,10 +196,10 @@ public static class DataSerializer
|
||||
// return (TransmissionTypeIdentifier.List, rt.ToArray());
|
||||
//}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) ListComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) ListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
|
||||
var rt = ArrayComposer((IEnumerable)value, connection);
|
||||
var rt = ArrayComposer((IEnumerable)value, warehouse, connection);
|
||||
|
||||
if (rt == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
@@ -217,9 +217,9 @@ public static class DataSerializer
|
||||
}
|
||||
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) TypedListComposer(IEnumerable value, Type type, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) TypedListComposer(IEnumerable value, Type type, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var composed = ArrayComposer((IEnumerable)value, connection);
|
||||
var composed = ArrayComposer((IEnumerable)value, warehouse, connection);
|
||||
|
||||
if (composed == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
@@ -245,7 +245,7 @@ public static class DataSerializer
|
||||
// .ToArray();
|
||||
//}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) PropertyValueArrayComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) PropertyValueArrayComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
@@ -255,15 +255,15 @@ public static class DataSerializer
|
||||
|
||||
foreach (var pv in ar)
|
||||
{
|
||||
rt.AddRange(Codec.Compose(pv.Age, connection));
|
||||
rt.AddRange(Codec.Compose(pv.Date, connection));
|
||||
rt.AddRange(Codec.Compose(pv.Value, connection));
|
||||
rt.AddRange(Codec.Compose(pv.Age, warehouse, connection));
|
||||
rt.AddRange(Codec.Compose(pv.Date, warehouse, connection));
|
||||
rt.AddRange(Codec.Compose(pv.Value, warehouse, connection));
|
||||
}
|
||||
|
||||
return (TransmissionTypeIdentifier.RawData, rt.ToArray());
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) TypedMapComposer(object value, Type keyType, Type valueType, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) TypedMapComposer(object value, Type keyType, Type valueType, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
@@ -279,12 +279,41 @@ public static class DataSerializer
|
||||
var map = (IMap)value;
|
||||
|
||||
foreach (var el in map.Serialize())
|
||||
rt.AddRange(Codec.Compose(el, connection));
|
||||
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||
|
||||
|
||||
return (TransmissionTypeIdentifier.TypedMap, rt.ToArray());
|
||||
}
|
||||
public static (TransmissionTypeIdentifier, byte[]) TypedDictionaryComposer(object value, Type keyType, Type valueType, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
|
||||
var kt = RepresentationType.FromType(keyType).Compose();
|
||||
var vt = RepresentationType.FromType(valueType).Compose();
|
||||
|
||||
var rt = new List<byte>();
|
||||
|
||||
rt.AddRange(kt);
|
||||
rt.AddRange(vt);
|
||||
|
||||
var dic = (IDictionary)value;
|
||||
|
||||
var ar = new List<object>();
|
||||
foreach (var k in dic.Keys)
|
||||
{
|
||||
ar.Add(k);
|
||||
ar.Add(dic[k]);
|
||||
}
|
||||
|
||||
foreach (var el in ar)
|
||||
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||
|
||||
|
||||
return (TransmissionTypeIdentifier.TypedMap, rt.ToArray());
|
||||
}
|
||||
|
||||
public static byte[] ArrayComposer(IEnumerable value, DistributedConnection connection)
|
||||
public static byte[] ArrayComposer(IEnumerable value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
@@ -292,31 +321,31 @@ public static class DataSerializer
|
||||
var rt = new List<byte>();
|
||||
|
||||
foreach (var i in value)
|
||||
rt.AddRange(Codec.Compose(i, connection));
|
||||
rt.AddRange(Codec.Compose(i, warehouse, connection));
|
||||
|
||||
return rt.ToArray();
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) ResourceListComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) ResourceListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
|
||||
|
||||
return (TransmissionTypeIdentifier.ResourceList, ArrayComposer((IEnumerable)value, connection));
|
||||
return (TransmissionTypeIdentifier.ResourceList, ArrayComposer((IEnumerable)value, warehouse, connection));
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) RecordListComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) RecordListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
|
||||
|
||||
return (TransmissionTypeIdentifier.RecordList, ArrayComposer((IEnumerable)value, connection));
|
||||
return (TransmissionTypeIdentifier.RecordList, ArrayComposer((IEnumerable)value, warehouse, connection));
|
||||
}
|
||||
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) ResourceComposer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) ResourceComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var resource = (IResource)value;
|
||||
|
||||
@@ -375,7 +404,7 @@ public static class DataSerializer
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) MapComposer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) MapComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
@@ -384,23 +413,23 @@ public static class DataSerializer
|
||||
var map = (IMap)value;
|
||||
|
||||
foreach (var el in map.Serialize())
|
||||
rt.AddRange(Codec.Compose(el, connection));
|
||||
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||
|
||||
return (TransmissionTypeIdentifier.Map, rt.ToArray());
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) UUIDComposer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) UUIDComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
return (TransmissionTypeIdentifier.UUID, ((UUID)value).Data);
|
||||
|
||||
}
|
||||
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) RecordComposer(object value, DistributedConnection connection)
|
||||
public static unsafe (TransmissionTypeIdentifier, byte[]) RecordComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
var rt = new List<byte>();// BinaryList();
|
||||
var record = (IRecord)value;
|
||||
|
||||
var template = connection.Instance.Warehouse.GetTemplateByType(record.GetType());
|
||||
var template = warehouse.GetTemplateByType(record.GetType());
|
||||
|
||||
|
||||
rt.AddRange(template.ClassId.Data);
|
||||
@@ -408,12 +437,12 @@ public static class DataSerializer
|
||||
foreach (var pt in template.Properties)
|
||||
{
|
||||
var propValue = pt.PropertyInfo.GetValue(record, null);
|
||||
rt.AddRange(Codec.Compose(propValue, connection));
|
||||
rt.AddRange(Codec.Compose(propValue, warehouse, connection));
|
||||
}
|
||||
|
||||
return (TransmissionTypeIdentifier.Record, rt.ToArray());
|
||||
}
|
||||
public static byte[] HistoryComposer(KeyList<PropertyTemplate, PropertyValue[]> history,
|
||||
public static byte[] HistoryComposer(KeyList<PropertyTemplate, PropertyValue[]> history, Warehouse warehouse,
|
||||
DistributedConnection connection, bool prependLength = false)
|
||||
{
|
||||
//@TODO:Test
|
||||
@@ -421,7 +450,7 @@ public static class DataSerializer
|
||||
|
||||
for (var i = 0; i < history.Count; i++)
|
||||
rt.AddUInt8(history.Keys.ElementAt(i).Index)
|
||||
.AddUInt8Array(Codec.Compose(history.Values.ElementAt(i), connection));
|
||||
.AddUInt8Array(Codec.Compose(history.Values.ElementAt(i), warehouse, connection));
|
||||
|
||||
if (prependLength)
|
||||
rt.InsertInt32(0, rt.Length);
|
||||
@@ -429,7 +458,7 @@ public static class DataSerializer
|
||||
return rt.ToArray();
|
||||
}
|
||||
|
||||
public static (TransmissionTypeIdentifier, byte[]) TupleComposer(object value, DistributedConnection connection)
|
||||
public static (TransmissionTypeIdentifier, byte[]) TupleComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
@@ -445,7 +474,7 @@ public static class DataSerializer
|
||||
foreach (var t in types)
|
||||
rt.AddRange(t);
|
||||
|
||||
var composed = ArrayComposer(list, connection);
|
||||
var composed = ArrayComposer(list, warehouse, connection);
|
||||
|
||||
if (composed == null)
|
||||
return (TransmissionTypeIdentifier.Null, new byte[0]);
|
||||
|
@@ -127,6 +127,11 @@ public class Map<KT, VT> : IEnumerable<KeyValuePair<KT, VT>>, IMap
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static Map<KT, VT> FromDictionary(Dictionary<KT, VT> dictionary)
|
||||
=> new Map<KT, VT>() { dic = dictionary };
|
||||
|
||||
public Dictionary<KT, VT> ToDictionary() => dic;
|
||||
|
||||
public static Map<string,object> FromObject(object obj)
|
||||
{
|
||||
var type = obj.GetType();
|
||||
|
@@ -216,9 +216,8 @@ namespace Esiur.Data
|
||||
return new RepresentationType(RepresentationTypeIdentifier.Resource, nullable);
|
||||
else if (type == typeof(IRecord) || type == typeof(Record))
|
||||
return new RepresentationType(RepresentationTypeIdentifier.Record, nullable);
|
||||
else if (type.IsInterface)
|
||||
return null; // other interfaces are not supported
|
||||
else if (type == typeof(Map<object, object>))
|
||||
else if (type == typeof(Map<object, object>)
|
||||
|| type == typeof(Dictionary<object, object>))
|
||||
return new RepresentationType(RepresentationTypeIdentifier.Map, nullable);
|
||||
else if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
{
|
||||
@@ -239,7 +238,9 @@ namespace Esiur.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 (args[0] == typeof(object))
|
||||
@@ -257,7 +258,8 @@ namespace Esiur.Data
|
||||
|
||||
}
|
||||
}
|
||||
else if (genericType == typeof(Map<,>))
|
||||
else if (genericType == typeof(Map<,>)
|
||||
|| genericType == typeof(Dictionary<,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
if (args[0] == typeof(object) && args[1] == typeof(object))
|
||||
@@ -397,6 +399,11 @@ namespace Esiur.Data
|
||||
{
|
||||
return new RepresentationType(RepresentationTypeIdentifier.Enum, nullable, TypeTemplate.GetTypeUUID(type));
|
||||
}
|
||||
else if (type.IsInterface)
|
||||
{
|
||||
return null; // other interfaces are not supported
|
||||
}
|
||||
|
||||
//else if (typeof(Structure).IsAssignableFrom(t) || t == typeof(ExpandoObject) => RepresentationTypeIdentifier.Structure)
|
||||
//{
|
||||
|
||||
|
@@ -240,7 +240,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
&& session.RemoteMethod == AuthenticationMethod.None)
|
||||
{
|
||||
// change to Map<byte, object> for compatibility
|
||||
var headers = Codec.Compose(session.LocalHeaders.Select(x => new KeyValuePair<byte, object>((byte)x.Key, x.Value)), this);
|
||||
var headers = Codec.Compose(session.LocalHeaders.Select(x => new KeyValuePair<byte, object>((byte)x.Key, x.Value)), this.Instance.Warehouse, this);
|
||||
|
||||
// declare (Credentials -> No Auth, No Enctypt)
|
||||
SendParams()
|
||||
@@ -253,7 +253,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
&& session.RemoteMethod == AuthenticationMethod.None)
|
||||
{
|
||||
// change to Map<byte, object> for compatibility
|
||||
var headers = Codec.Compose(session.LocalHeaders.Select(x => new KeyValuePair<byte, object>((byte)x.Key, x.Value)), this);
|
||||
var headers = Codec.Compose(session.LocalHeaders.Select(x => new KeyValuePair<byte, object>((byte)x.Key, x.Value)), this.Instance.Warehouse, this);
|
||||
|
||||
SendParams()
|
||||
.AddUInt8((byte)IIPAuthPacketInitialize.TokenNoAuth)
|
||||
@@ -264,7 +264,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
&& session.RemoteMethod == AuthenticationMethod.None)
|
||||
{
|
||||
// change to Map<byte, object> for compatibility
|
||||
var headers = Codec.Compose(session.LocalHeaders.Select(x => new KeyValuePair<byte, object>((byte)x.Key, x.Value)), this);
|
||||
var headers = Codec.Compose(session.LocalHeaders.Select(x => new KeyValuePair<byte, object>((byte)x.Key, x.Value)), this.Instance.Warehouse, this);
|
||||
|
||||
// @REVIEW: MITM Attack can still occur
|
||||
SendParams()
|
||||
@@ -814,7 +814,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
SendParams()
|
||||
.AddUInt8((byte)IIPAuthPacketAction.IAuthPlain)
|
||||
.AddUInt32((uint)headers[IIPAuthPacketIAuthHeader.Reference])
|
||||
.AddUInt8Array(Codec.Compose(response, this))
|
||||
.AddUInt8Array(Codec.Compose(response, this.Instance.Warehouse, this))
|
||||
.Done();
|
||||
})
|
||||
.Timeout(iAuthRequest.Timeout * 1000,
|
||||
@@ -856,7 +856,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
var sha = SHA256.Create();
|
||||
var hash = sha.ComputeHash(new BinaryList()
|
||||
.AddUInt8Array((byte[])session.LocalHeaders[IIPAuthPacketHeader.Nonce])
|
||||
.AddUInt8Array(Codec.Compose(response, this))
|
||||
.AddUInt8Array(Codec.Compose(response, this.Instance.Warehouse, this))
|
||||
.AddUInt8Array((byte[])session.RemoteHeaders[IIPAuthPacketHeader.Nonce])
|
||||
.ToArray());
|
||||
|
||||
@@ -934,7 +934,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
|
||||
SendParams()
|
||||
.AddUInt8((byte)IIPAuthPacketAcknowledge.NoAuthCredentials)
|
||||
.AddUInt8Array(Codec.Compose(localHeaders, this))
|
||||
.AddUInt8Array(Codec.Compose(localHeaders, this.Instance.Warehouse, this))
|
||||
.Done();
|
||||
}
|
||||
else
|
||||
@@ -992,7 +992,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
|
||||
SendParams()
|
||||
.AddUInt8((byte)IIPAuthPacketAcknowledge.NoAuthToken)
|
||||
.AddUInt8Array(Codec.Compose(localHeaders, this))
|
||||
.AddUInt8Array(Codec.Compose(localHeaders, this.Instance.Warehouse, this))
|
||||
.Done();
|
||||
|
||||
}
|
||||
@@ -1038,7 +1038,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
|
||||
SendParams()
|
||||
.AddUInt8((byte)IIPAuthPacketAcknowledge.NoAuthNoAuth)
|
||||
.AddUInt8Array(Codec.Compose(localHeaders, this))
|
||||
.AddUInt8Array(Codec.Compose(localHeaders,this.Instance.Warehouse, this))
|
||||
.Done();
|
||||
}
|
||||
else
|
||||
@@ -1303,7 +1303,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
|
||||
SendParams()
|
||||
.AddUInt8((byte)IIPAuthPacketEvent.IAuthPlain)
|
||||
.AddUInt8Array(Codec.Compose(args, this))
|
||||
.AddUInt8Array(Codec.Compose(args, this.Instance.Warehouse, this))
|
||||
.Done();
|
||||
|
||||
}
|
||||
@@ -1321,7 +1321,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
|
||||
SendParams()
|
||||
.AddUInt8((byte)IIPAuthPacketEvent.IAuthHashed)
|
||||
.AddUInt8Array(Codec.Compose(args, this))
|
||||
.AddUInt8Array(Codec.Compose(args, this.Instance.Warehouse, this))
|
||||
.Done();
|
||||
|
||||
}
|
||||
@@ -1337,7 +1337,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
|
||||
SendParams()
|
||||
.AddUInt8((byte)IIPAuthPacketEvent.IAuthEncrypted)
|
||||
.AddUInt8Array(Codec.Compose(args, this))
|
||||
.AddUInt8Array(Codec.Compose(args, this.Instance.Warehouse, this))
|
||||
.Done();
|
||||
}
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ partial class DistributedConnection
|
||||
var bl = new BinaryList();
|
||||
bl.AddUInt8((byte)(0x60 | (byte)action))
|
||||
.AddUInt32(c)
|
||||
.AddUInt8Array(Codec.Compose(args[0], this));
|
||||
.AddUInt8Array(Codec.Compose(args[0], this.Instance.Warehouse, this));
|
||||
Send(bl.ToArray());
|
||||
}
|
||||
else
|
||||
@@ -102,7 +102,7 @@ partial class DistributedConnection
|
||||
var bl = new BinaryList();
|
||||
bl.AddUInt8((byte)(0x60 | (byte)action))
|
||||
.AddUInt32(c)
|
||||
.AddUInt8Array(Codec.Compose(args, this));
|
||||
.AddUInt8Array(Codec.Compose(args, this.Instance.Warehouse, this));
|
||||
Send(bl.ToArray());
|
||||
}
|
||||
|
||||
@@ -127,14 +127,14 @@ partial class DistributedConnection
|
||||
{
|
||||
var bl = new BinaryList();
|
||||
bl.AddUInt8((byte)(0x20 | (byte)action))
|
||||
.AddUInt8Array(Codec.Compose(args[0], this));
|
||||
.AddUInt8Array(Codec.Compose(args[0], this.Instance.Warehouse, this));
|
||||
Send(bl.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
var bl = new BinaryList();
|
||||
bl.AddUInt8((byte)(0x20 | (byte)action))
|
||||
.AddUInt8Array(Codec.Compose(args, this));
|
||||
.AddUInt8Array(Codec.Compose(args, this.Instance.Warehouse, this));
|
||||
Send(bl.ToArray());
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ partial class DistributedConnection
|
||||
var bl = new BinaryList();
|
||||
bl.AddUInt8((byte)(0xA0 | (byte)action))
|
||||
.AddUInt32(callbackId)
|
||||
.AddUInt8Array(Codec.Compose(args[0], this));
|
||||
.AddUInt8Array(Codec.Compose(args[0], this.Instance.Warehouse, this));
|
||||
Send(bl.ToArray());
|
||||
}
|
||||
else
|
||||
@@ -163,7 +163,7 @@ partial class DistributedConnection
|
||||
var bl = new BinaryList();
|
||||
bl.AddUInt8((byte)(0xA0 | (byte)action))
|
||||
.AddUInt32(callbackId)
|
||||
.AddUInt8Array(Codec.Compose(args, this));
|
||||
.AddUInt8Array(Codec.Compose(args, this.Instance.Warehouse, this));
|
||||
Send(bl.ToArray());
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ public class ConstantTemplate : MemberTemplate
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddUInt8Array(Codec.Compose(Value, null))
|
||||
.AddUInt8Array(Codec.Compose(Value, null, null))
|
||||
.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp)
|
||||
.ToArray();
|
||||
@@ -63,7 +63,7 @@ public class ConstantTemplate : MemberTemplate
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddUInt8Array(Codec.Compose(Value, null))
|
||||
.AddUInt8Array(Codec.Compose(Value, null, null))
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
@@ -119,7 +119,7 @@ namespace Esiur.Security.Membership
|
||||
// local nonce + password or token + remote nonce
|
||||
var challenge = hashFunc.ComputeHash(new BinaryList()
|
||||
.AddUInt8Array(remoteNonce)
|
||||
.AddUInt8Array(Codec.Compose(qa.Answer, null))
|
||||
.AddUInt8Array(Codec.Compose(qa.Answer, null, null))
|
||||
.AddUInt8Array(localNonce)
|
||||
.ToArray());
|
||||
|
||||
|
Reference in New Issue
Block a user