mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-09-13 12:43:17 +00:00
tdu
This commit is contained in:
@@ -338,11 +338,11 @@ public static class Codec
|
||||
};
|
||||
|
||||
|
||||
internal static (TransmissionDataUnitIdentifier identifier, byte[])
|
||||
internal static (TransmissionDataUnitIdentifier identifier, byte[] data, byte[] metadata)
|
||||
ComposeInternal(object valueOrSource, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (valueOrSource == null)
|
||||
return (TransmissionDataUnitIdentifier.Null, null);
|
||||
return (TransmissionDataUnitIdentifier.Null, null, null);
|
||||
|
||||
var type = valueOrSource.GetType();
|
||||
|
||||
@@ -369,7 +369,7 @@ public static class Codec
|
||||
valueOrSource = ((IUserType)valueOrSource).Get();
|
||||
|
||||
if (valueOrSource == null)
|
||||
return (TransmissionDataUnitIdentifier.Null, null);
|
||||
return (TransmissionDataUnitIdentifier.Null, null, null);
|
||||
|
||||
|
||||
type = valueOrSource.GetType();
|
||||
@@ -377,20 +377,20 @@ public static class Codec
|
||||
|
||||
if (Composers.ContainsKey(type))
|
||||
{
|
||||
var (hdr, data) = Composers[type](valueOrSource, warehouse, connection);
|
||||
return (hdr, data);
|
||||
var (hdr, data, metadata) = Composers[type](valueOrSource, warehouse, connection);
|
||||
return (hdr, data, metadata);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
{
|
||||
var (hdr, data) = DataSerializer.ResourceComposer(valueOrSource, warehouse, connection);
|
||||
return (hdr, data);
|
||||
var (hdr, data, metadata) = DataSerializer.ResourceComposer(valueOrSource, warehouse, connection);
|
||||
return (hdr, data, metadata);
|
||||
}
|
||||
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
|
||||
{
|
||||
var (hdr, data) = DataSerializer.RecordComposer(valueOrSource, warehouse, connection);
|
||||
return (hdr, data);
|
||||
var (hdr, data, metadata) = DataSerializer.RecordComposer(valueOrSource, warehouse, connection);
|
||||
return (hdr, data, metadata);
|
||||
}
|
||||
else if (type.IsGenericType)
|
||||
{
|
||||
@@ -402,24 +402,24 @@ public static class Codec
|
||||
var args = type.GetGenericArguments();
|
||||
//if (Composers.ContainsKey(args[0]))
|
||||
//{
|
||||
var (hdr, data) = DataSerializer.TypedListComposer((IEnumerable)valueOrSource, args[0], warehouse, connection);
|
||||
return (hdr, data);
|
||||
var (hdr, data, metadata) = DataSerializer.TypedListComposer((IEnumerable)valueOrSource, args[0], warehouse, connection);
|
||||
return (hdr, data, metadata);
|
||||
//}
|
||||
}
|
||||
else if (genericType == typeof(Map<,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
|
||||
var (hdr, data) = DataSerializer.TypedMapComposer(valueOrSource, args[0], args[1], warehouse, connection);
|
||||
return (hdr, data);
|
||||
var (hdr, data, metadata) = DataSerializer.TypedMapComposer(valueOrSource, args[0], args[1], warehouse, connection);
|
||||
return (hdr, data, metadata);
|
||||
|
||||
}
|
||||
else if (genericType == typeof(Dictionary<,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
|
||||
var (hdr, data) = DataSerializer.TypedDictionaryComposer(valueOrSource, args[0], args[1], warehouse, connection);
|
||||
return (hdr, data);
|
||||
var (hdr, data, metadata) = DataSerializer.TypedDictionaryComposer(valueOrSource, args[0], args[1], warehouse, connection);
|
||||
return (hdr, data, metadata);
|
||||
|
||||
}
|
||||
|
||||
@@ -431,8 +431,8 @@ public static class Codec
|
||||
|| genericType == typeof(ValueTuple<,,,,,,>)
|
||||
)
|
||||
{
|
||||
var (hdr, data) = DataSerializer.TupleComposer(valueOrSource, warehouse, connection);
|
||||
return (hdr, data);
|
||||
var (hdr, data, metadata) = DataSerializer.TupleComposer(valueOrSource, warehouse, connection);
|
||||
return (hdr, data, metadata);
|
||||
}
|
||||
}
|
||||
else if (type.IsArray)
|
||||
|
@@ -483,10 +483,10 @@ public static class DataSerializer
|
||||
return rt.ToArray();
|
||||
}
|
||||
|
||||
public static (TransmissionDataUnitIdentifier, byte[]) TupleComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
public static TransmissionDataUnitIdentifier TupleComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return (TransmissionDataUnitIdentifier.Null, new byte[0]);
|
||||
return (TransmissionDataUnitIdentifier.Null, new byte[0], new byte[0]);
|
||||
|
||||
var rt = new List<byte>();
|
||||
|
||||
@@ -494,7 +494,6 @@ public static class DataSerializer
|
||||
var list = fields.Select(x => x.GetValue(value)).ToArray();
|
||||
var types = fields.Select(x => RepresentationType.FromType(x.FieldType).Compose()).ToArray();
|
||||
|
||||
rt.Add((byte)list.Length);
|
||||
|
||||
foreach (var t in types)
|
||||
rt.AddRange(t);
|
||||
@@ -502,11 +501,11 @@ public static class DataSerializer
|
||||
var composed = ArrayComposer(list, warehouse, connection);
|
||||
|
||||
if (composed == null)
|
||||
return (TransmissionDataUnitIdentifier.Null, new byte[0]);
|
||||
return (TransmissionDataUnitIdentifier.Null, new byte[0], new byte[0]);
|
||||
else
|
||||
{
|
||||
rt.AddRange(composed);
|
||||
return (TransmissionDataUnitIdentifier.TypedTuple, rt.ToArray());
|
||||
return (TransmissionDataUnitIdentifier.TypedTuple, rt.ToArray(), composed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ public struct TransmissionDataUnit
|
||||
|
||||
}
|
||||
|
||||
public static byte[] Compose(TransmissionDataUnitIdentifier identifier, byte[] data, byte[] typeMetadata = null)
|
||||
public static byte[] Compose(TransmissionDataUnitIdentifier identifier, byte[] data, byte[] typeMetadata)
|
||||
{
|
||||
|
||||
if (data == null || data.Length == 0)
|
||||
@@ -50,7 +50,8 @@ public struct TransmissionDataUnit
|
||||
{
|
||||
return DC.Combine(new byte[] { (byte)identifier }, 0, 1, data, 0, (uint)data.Length);
|
||||
}
|
||||
else if (cls == TransmissionDataUnitClass.Dynamic)
|
||||
else if (cls == TransmissionDataUnitClass.Dynamic
|
||||
|| cls == TransmissionDataUnitClass.Extension)
|
||||
{
|
||||
var len = (ulong)data.LongLength;
|
||||
|
||||
@@ -151,8 +152,8 @@ public struct TransmissionDataUnit
|
||||
rt[0] = (byte)((byte)identifier | 0x8);
|
||||
rt[1] = (byte)len;
|
||||
|
||||
|
||||
Buffer.BlockCopy(data, 0, rt, 2, (int)len);
|
||||
Buffer.BlockCopy(typeMetadata, 0, rt, 2, typeMetadata.Length);
|
||||
Buffer.BlockCopy(data, 0, rt, 2 + typeMetadata.Length, data.Length);
|
||||
return rt;
|
||||
}
|
||||
else if (len <= 0xFF_FF)
|
||||
@@ -161,7 +162,9 @@ public struct TransmissionDataUnit
|
||||
rt[0] = (byte)((byte)identifier | 0x10);
|
||||
rt[1] = (byte)((len >> 8) & 0xFF);
|
||||
rt[2] = (byte)(len & 0xFF);
|
||||
Buffer.BlockCopy(data, 0, rt, 3, (int)len);
|
||||
|
||||
Buffer.BlockCopy(typeMetadata, 0, rt, 3, typeMetadata.Length);
|
||||
Buffer.BlockCopy(data, 0, rt, 3 + typeMetadata.Length, data.Length);
|
||||
return rt;
|
||||
}
|
||||
else if (len <= 0xFF_FF_FF)
|
||||
@@ -171,7 +174,10 @@ public struct TransmissionDataUnit
|
||||
rt[1] = (byte)((len >> 16) & 0xFF);
|
||||
rt[2] = (byte)((len >> 8) & 0xFF);
|
||||
rt[3] = (byte)(len & 0xFF);
|
||||
Buffer.BlockCopy(data, 0, rt, 4, (int)len);
|
||||
|
||||
Buffer.BlockCopy(typeMetadata, 0, rt, 4, typeMetadata.Length);
|
||||
Buffer.BlockCopy(data, 0, rt, 4 + typeMetadata.Length, data.Length);
|
||||
|
||||
return rt;
|
||||
}
|
||||
else if (len <= 0xFF_FF_FF_FF)
|
||||
@@ -182,7 +188,10 @@ public struct TransmissionDataUnit
|
||||
rt[2] = (byte)((len >> 16) & 0xFF);
|
||||
rt[3] = (byte)((len >> 8) & 0xFF);
|
||||
rt[4] = (byte)(len & 0xFF);
|
||||
Buffer.BlockCopy(data, 0, rt, 5, (int)len);
|
||||
|
||||
Buffer.BlockCopy(typeMetadata, 0, rt, 5, typeMetadata.Length);
|
||||
Buffer.BlockCopy(data, 0, rt, 5 + typeMetadata.Length, data.Length);
|
||||
|
||||
return rt;
|
||||
}
|
||||
else if (len <= 0xFF_FF_FF_FF_FF)
|
||||
@@ -194,7 +203,10 @@ public struct TransmissionDataUnit
|
||||
rt[3] = (byte)((len >> 16) & 0xFF);
|
||||
rt[4] = (byte)((len >> 8) & 0xFF);
|
||||
rt[5] = (byte)(len & 0xFF);
|
||||
Buffer.BlockCopy(data, 0, rt, 6, (int)len);
|
||||
|
||||
Buffer.BlockCopy(typeMetadata, 0, rt, 6, typeMetadata.Length);
|
||||
Buffer.BlockCopy(data, 0, rt, 6 + typeMetadata.Length, data.Length);
|
||||
|
||||
return rt;
|
||||
}
|
||||
else if (len <= 0xFF_FF_FF_FF_FF_FF)
|
||||
@@ -207,7 +219,10 @@ public struct TransmissionDataUnit
|
||||
rt[4] = (byte)((len >> 16) & 0xFF);
|
||||
rt[5] = (byte)((len >> 8) & 0xFF);
|
||||
rt[6] = (byte)(len & 0xFF);
|
||||
Buffer.BlockCopy(data, 0, rt, 7, (int)len);
|
||||
|
||||
Buffer.BlockCopy(typeMetadata, 0, rt, 7, typeMetadata.Length);
|
||||
Buffer.BlockCopy(data, 0, rt, 7 + typeMetadata.Length, data.Length);
|
||||
|
||||
return rt;
|
||||
}
|
||||
else //if (len <= 0xFF_FF_FF_FF_FF_FF_FF)
|
||||
@@ -221,10 +236,15 @@ public struct TransmissionDataUnit
|
||||
rt[5] = (byte)((len >> 16) & 0xFF);
|
||||
rt[6] = (byte)((len >> 8) & 0xFF);
|
||||
rt[7] = (byte)(len & 0xFF);
|
||||
Buffer.BlockCopy(data, 0, rt, 8, (int)len);
|
||||
|
||||
Buffer.BlockCopy(typeMetadata, 0, rt, 8, typeMetadata.Length);
|
||||
Buffer.BlockCopy(data, 0, rt, 8 + typeMetadata.Length, data.Length);
|
||||
|
||||
return rt;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("Not supported class type.");
|
||||
}
|
||||
|
||||
public static (ulong, TransmissionDataUnit?) Parse(byte[] data, uint offset, uint ends)
|
||||
|
Reference in New Issue
Block a user