mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-09-13 12:43:17 +00:00
next
This commit is contained in:
@@ -180,13 +180,13 @@ public static class Codec
|
|||||||
/// <param name="connection">DistributedConnection is required in case a structure in the array holds items at the other end.</param>
|
/// <param name="connection">DistributedConnection is required in case a structure in the array holds items at the other end.</param>
|
||||||
/// <param name="dataType">DataType, in case the data is not prepended with DataType</param>
|
/// <param name="dataType">DataType, in case the data is not prepended with DataType</param>
|
||||||
/// <returns>Value</returns>
|
/// <returns>Value</returns>
|
||||||
public static (uint, object) ParseAsync(byte[] data, uint offset, DistributedConnection connection, uint[] requestSequence, TransmissionDataUnit? dataType = null)
|
public static (uint, object) ParseAsync(byte[] data, uint offset, DistributedConnection connection, uint[] requestSequence, ParsedTDU? dataType = null)
|
||||||
{
|
{
|
||||||
uint len = 0;
|
uint len = 0;
|
||||||
|
|
||||||
if (dataType == null)
|
if (dataType == null)
|
||||||
{
|
{
|
||||||
(var longLen, dataType) = TransmissionDataUnit.Parse(data, offset, (uint)data.Length);
|
(var longLen, dataType) = ParsedTDU.Parse(data, offset, (uint)data.Length);
|
||||||
|
|
||||||
if (dataType == null)
|
if (dataType == null)
|
||||||
throw new NullReferenceException("DataType can't be parsed.");
|
throw new NullReferenceException("DataType can't be parsed.");
|
||||||
@@ -201,11 +201,11 @@ public static class Codec
|
|||||||
|
|
||||||
//Console.WriteLine("Parsing " + tt.Class + " " + tt.Identifier);
|
//Console.WriteLine("Parsing " + tt.Class + " " + tt.Identifier);
|
||||||
|
|
||||||
if (tt.Class == TransmissionDataUnitClass.Fixed)
|
if (tt.Class == TDUClass.Fixed)
|
||||||
{
|
{
|
||||||
return (len, FixedAsyncParsers[tt.Exponent][tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, connection, requestSequence));
|
return (len, FixedAsyncParsers[tt.Exponent][tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, connection, requestSequence));
|
||||||
}
|
}
|
||||||
else if (tt.Class == TransmissionDataUnitClass.Dynamic)
|
else if (tt.Class == TDUClass.Dynamic)
|
||||||
{
|
{
|
||||||
return (len, DynamicAsyncParsers[tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, connection, requestSequence));
|
return (len, DynamicAsyncParsers[tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, connection, requestSequence));
|
||||||
}
|
}
|
||||||
@@ -215,13 +215,13 @@ public static class Codec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (uint, object) ParseSync(byte[] data, uint offset, Warehouse warehouse, TransmissionDataUnit? dataType = null)
|
public static (uint, object) ParseSync(byte[] data, uint offset, Warehouse warehouse, ParsedTDU? dataType = null)
|
||||||
{
|
{
|
||||||
uint len = 0;
|
uint len = 0;
|
||||||
|
|
||||||
if (dataType == null)
|
if (dataType == null)
|
||||||
{
|
{
|
||||||
(var longLen, dataType) = TransmissionDataUnit.Parse(data, offset, (uint)data.Length);
|
(var longLen, dataType) = ParsedTDU.Parse(data, offset, (uint)data.Length);
|
||||||
|
|
||||||
if (dataType == null)
|
if (dataType == null)
|
||||||
throw new NullReferenceException("DataType can't be parsed.");
|
throw new NullReferenceException("DataType can't be parsed.");
|
||||||
@@ -234,11 +234,11 @@ public static class Codec
|
|||||||
|
|
||||||
var tt = dataType.Value;
|
var tt = dataType.Value;
|
||||||
|
|
||||||
if (tt.Class == TransmissionDataUnitClass.Fixed)
|
if (tt.Class == TDUClass.Fixed)
|
||||||
{
|
{
|
||||||
return (len, FixedParsers[tt.Exponent][tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, warehouse));
|
return (len, FixedParsers[tt.Exponent][tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, warehouse));
|
||||||
}
|
}
|
||||||
else if (tt.Class == TransmissionDataUnitClass.Dynamic)
|
else if (tt.Class == TDUClass.Dynamic)
|
||||||
{
|
{
|
||||||
return (len, DynamicParsers[tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, warehouse));
|
return (len, DynamicParsers[tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, warehouse));
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ public static class Codec
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate TransmissionDataUnit Composer(object value, Warehouse warehouse, DistributedConnection connection);
|
public delegate TDU Composer(object value, Warehouse warehouse, DistributedConnection connection);
|
||||||
|
|
||||||
public static Dictionary<Type, Composer> Composers = new Dictionary<Type, Composer>()
|
public static Dictionary<Type, Composer> Composers = new Dictionary<Type, Composer>()
|
||||||
{
|
{
|
||||||
@@ -338,11 +338,11 @@ public static class Codec
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
internal static TransmissionDataUnit
|
internal static TDU
|
||||||
ComposeInternal(object valueOrSource, Warehouse warehouse, DistributedConnection connection)
|
ComposeInternal(object valueOrSource, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (valueOrSource == null)
|
if (valueOrSource == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, null, 0, 0);
|
return new TDU(TDUIdentifier.Null);
|
||||||
|
|
||||||
var type = valueOrSource.GetType();
|
var type = valueOrSource.GetType();
|
||||||
|
|
||||||
@@ -369,7 +369,7 @@ public static class Codec
|
|||||||
valueOrSource = ((IUserType)valueOrSource).Get();
|
valueOrSource = ((IUserType)valueOrSource).Get();
|
||||||
|
|
||||||
if (valueOrSource == null)
|
if (valueOrSource == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, null, 0, 0);
|
return new TDU(TDUIdentifier.Null);
|
||||||
|
|
||||||
|
|
||||||
type = valueOrSource.GetType();
|
type = valueOrSource.GetType();
|
||||||
@@ -445,7 +445,7 @@ public static class Codec
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, null, 0, 0);
|
return new TDU(TDUIdentifier.Null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,7 +460,7 @@ public static class Codec
|
|||||||
public static byte[] Compose(object valueOrSource, Warehouse warehouse, DistributedConnection connection)//, bool prependType = true)
|
public static byte[] Compose(object valueOrSource, Warehouse warehouse, DistributedConnection connection)//, bool prependType = true)
|
||||||
{
|
{
|
||||||
var tdu = ComposeInternal(valueOrSource, warehouse, connection);
|
var tdu = ComposeInternal(valueOrSource, warehouse, connection);
|
||||||
return tdu.Compose();
|
return tdu.Composed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsAnonymous(Type type)
|
public static bool IsAnonymous(Type type)
|
||||||
|
@@ -680,13 +680,13 @@ public static class DataDeserializer
|
|||||||
//TransmissionDataUnitIdentifier? previous = null;
|
//TransmissionDataUnitIdentifier? previous = null;
|
||||||
//byte[]? previousUUID = null;
|
//byte[]? previousUUID = null;
|
||||||
|
|
||||||
TransmissionDataUnit? previous = null;
|
ParsedTDU? previous = null;
|
||||||
|
|
||||||
while (length > 0)
|
while (length > 0)
|
||||||
{
|
{
|
||||||
var (longLen, dataType) = TransmissionDataUnit.Parse(data, offset, (uint)data.Length);
|
var (longLen, dataType) = ParsedTDU.Parse(data, offset, (uint)data.Length);
|
||||||
|
|
||||||
if (dataType.Value.Identifier == TransmissionDataUnitIdentifier.Same)
|
if (dataType.Value.Identifier == TDUIdentifier.Same)
|
||||||
{
|
{
|
||||||
// Add UUID
|
// Add UUID
|
||||||
}
|
}
|
||||||
|
@@ -14,116 +14,116 @@ public static class DataSerializer
|
|||||||
{
|
{
|
||||||
public delegate byte[] Serializer(object value);
|
public delegate byte[] Serializer(object value);
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit Int32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU Int32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (int)value;
|
var v = (int)value;
|
||||||
var rt = new byte[4];
|
var rt = new byte[4];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((int*)ptr) = v;
|
*((int*)ptr) = v;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Int32, rt, 0, 4);
|
return new TDU(TDUIdentifier.Int32, rt, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit UInt32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU UInt32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (uint)value;
|
var v = (uint)value;
|
||||||
var rt = new byte[4];
|
var rt = new byte[4];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((uint*)ptr) = v;
|
*((uint*)ptr) = v;
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.UInt32, rt, 0, 4);
|
return new TDU(TDUIdentifier.UInt32, rt, 4);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit Int16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU Int16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (short)value;
|
var v = (short)value;
|
||||||
var rt = new byte[2];
|
var rt = new byte[2];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((short*)ptr) = v;
|
*((short*)ptr) = v;
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Int16, rt, 0, 2);
|
return new TDU(TDUIdentifier.Int16, rt, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit UInt16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU UInt16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (ushort)value;
|
var v = (ushort)value;
|
||||||
var rt = new byte[2];
|
var rt = new byte[2];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((ushort*)ptr) = v;
|
*((ushort*)ptr) = v;
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.UInt16, rt, 0, 2);
|
return new TDU(TDUIdentifier.UInt16, rt, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit Float32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU Float32Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (float)value;
|
var v = (float)value;
|
||||||
var rt = new byte[4];
|
var rt = new byte[4];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((float*)ptr) = v;
|
*((float*)ptr) = v;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Float32, rt, 0, 4);
|
return new TDU(TDUIdentifier.Float32, rt, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit Float64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU Float64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (double)value;
|
var v = (double)value;
|
||||||
var rt = new byte[8];
|
var rt = new byte[8];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((double*)ptr) = v;
|
*((double*)ptr) = v;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Float64, rt, 0, 8);
|
return new TDU(TDUIdentifier.Float64, rt, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit Int64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU Int64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (long)value;
|
var v = (long)value;
|
||||||
var rt = new byte[8];
|
var rt = new byte[8];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((long*)ptr) = v;
|
*((long*)ptr) = v;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Int64, rt, 0, 8);
|
return new TDU(TDUIdentifier.Int64, rt, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit UIn64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU UIn64Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (ulong)value;
|
var v = (ulong)value;
|
||||||
var rt = new byte[8];
|
var rt = new byte[8];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((ulong*)ptr) = v;
|
*((ulong*)ptr) = v;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.UInt64, rt, 0, 8);
|
return new TDU(TDUIdentifier.UInt64, rt, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit DateTimeComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU DateTimeComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = ((DateTime)value).ToUniversalTime().Ticks;
|
var v = ((DateTime)value).ToUniversalTime().Ticks;
|
||||||
var rt = new byte[8];
|
var rt = new byte[8];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((long*)ptr) = v;
|
*((long*)ptr) = v;
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.DateTime, rt, 0, 8);
|
return new TDU(TDUIdentifier.DateTime, rt, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit Decimal128Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU Decimal128Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (decimal)value;
|
var v = (decimal)value;
|
||||||
var rt = new byte[16];
|
var rt = new byte[16];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((decimal*)ptr) = v;
|
*((decimal*)ptr) = v;
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Decimal128, rt, 0, 16);
|
return new TDU(TDUIdentifier.Decimal128, rt, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static TransmissionDataUnit StringComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU StringComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var b = Encoding.UTF8.GetBytes((string)value);
|
var b = Encoding.UTF8.GetBytes((string)value);
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.String, b, 0, (uint)b.Length);
|
return new TDU(TDUIdentifier.String, b, (uint)b.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit EnumComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU EnumComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, null, 0, 0);
|
return new TDU(TDUIdentifier.Null, null, 0);
|
||||||
|
|
||||||
//var warehouse = connection?.Instance?.Warehouse ?? connection?.Server?.Instance?.Warehouse;
|
//var warehouse = connection?.Instance?.Warehouse ?? connection?.Server?.Instance?.Warehouse;
|
||||||
//if (warehouse == null)
|
//if (warehouse == null)
|
||||||
@@ -136,73 +136,73 @@ public static class DataSerializer
|
|||||||
var ct = template.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
|
var ct = template.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
|
||||||
|
|
||||||
if (ct == null)
|
if (ct == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, null, 0, 0);
|
return new TDU(TDUIdentifier.Null, null, 0);
|
||||||
|
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.TypedEnum,
|
return new TDU(TDUIdentifier.TypedEnum,
|
||||||
new byte[] { ct.Index }, 0, 1, template.ClassId.Data);
|
new byte[] { ct.Index }, 1, template.ClassId.Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit UInt8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU UInt8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.UInt8,
|
return new TDU(TDUIdentifier.UInt8,
|
||||||
new byte[] { (byte)value }, 0, 1);
|
new byte[] { (byte)value }, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit Int8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU Int8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Int8,
|
return new TDU(TDUIdentifier.Int8,
|
||||||
new byte[] { (byte)(sbyte)value }, 0, 1);
|
new byte[] { (byte)(sbyte)value }, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit Char8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU Char8Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Int8,
|
return new TDU(TDUIdentifier.Int8,
|
||||||
new byte[] { (byte)(char)value }, 0, 1);
|
new byte[] { (byte)(char)value }, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit Char16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU Char16Composer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var v = (char)value;
|
var v = (char)value;
|
||||||
var rt = new byte[2];
|
var rt = new byte[2];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((char*)ptr) = v;
|
*((char*)ptr) = v;
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Char16, rt, 0, 2);
|
return new TDU(TDUIdentifier.Char16, rt, 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit BoolComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU BoolComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if ((bool)value)
|
if ((bool)value)
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.True, null, 0, 0);
|
return new TDU(TDUIdentifier.True);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.True, null, 0, 0);
|
return new TDU(TDUIdentifier.True);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static TransmissionDataUnit NotModifiedComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU NotModifiedComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.NotModified, null, 0, 0);
|
return new TDU(TDUIdentifier.NotModified);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit RawDataComposerFromArray(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU RawDataComposerFromArray(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var b = (byte[])value;
|
var b = (byte[])value;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.RawData, b, 0, (uint)b.Length);
|
return new TDU(TDUIdentifier.RawData, b, (uint)b.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit RawDataComposerFromList(dynamic value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU RawDataComposerFromList(dynamic value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var b = value as List<byte>;
|
var b = value as List<byte>;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.RawData, b.ToArray(), 0, (uint)b.Count);
|
return new TDU(TDUIdentifier.RawData, b.ToArray(), (uint)b.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static (TransmissionDataUnitIdentifier, byte[]) ListComposerFromArray(dynamic value, DistributedConnection connection)
|
//public static (TDUIdentifier, byte[]) ListComposerFromArray(dynamic value, DistributedConnection connection)
|
||||||
//{
|
//{
|
||||||
// var rt = new List<byte>();
|
// var rt = new List<byte>();
|
||||||
// var array = (object[])value;
|
// var array = (object[])value;
|
||||||
@@ -210,31 +210,31 @@ public static class DataSerializer
|
|||||||
// for (var i = 0; i < array.Length; i++)
|
// for (var i = 0; i < array.Length; i++)
|
||||||
// rt.AddRange(Codec.Compose(array[i], connection));
|
// rt.AddRange(Codec.Compose(array[i], connection));
|
||||||
|
|
||||||
// return (TransmissionDataUnitIdentifier.List, rt.ToArray());
|
// return (TDUIdentifier.List, rt.ToArray());
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public static TransmissionDataUnit ListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU ListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var rt = ArrayComposer((IEnumerable)value, warehouse, connection);
|
var rt = ArrayComposer((IEnumerable)value, warehouse, connection);
|
||||||
|
|
||||||
if (rt == null)
|
if (rt == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 0);
|
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||||
else
|
else
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.List, rt, 0, (uint)rt.Length);
|
return new TDU(TDUIdentifier.List, rt, (uint)rt.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static TransmissionDataUnit TypedListComposer(IEnumerable value, Type type, Warehouse warehouse, DistributedConnection connection)
|
public static TDU TypedListComposer(IEnumerable value, Type type, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var composed = ArrayComposer((IEnumerable)value, warehouse, connection);
|
var composed = ArrayComposer((IEnumerable)value, warehouse, connection);
|
||||||
|
|
||||||
if (composed == null)
|
if (composed == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 0);
|
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||||
|
|
||||||
var metadata = RepresentationType.FromType(type).Compose();
|
var metadata = RepresentationType.FromType(type).Compose();
|
||||||
|
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.TypedList, composed, 0,
|
return new TDU(TDUIdentifier.TypedList, composed,
|
||||||
(uint)composed.Length, metadata);
|
(uint)composed.Length, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,10 +249,10 @@ public static class DataSerializer
|
|||||||
// .ToArray();
|
// .ToArray();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public static TransmissionDataUnit PropertyValueArrayComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU PropertyValueArrayComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 0);
|
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||||
|
|
||||||
var rt = new List<byte>();
|
var rt = new List<byte>();
|
||||||
var ar = value as PropertyValue[];
|
var ar = value as PropertyValue[];
|
||||||
@@ -264,14 +264,14 @@ public static class DataSerializer
|
|||||||
rt.AddRange(Codec.Compose(pv.Value, warehouse, connection));
|
rt.AddRange(Codec.Compose(pv.Value, warehouse, connection));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.RawData, rt.ToArray(), 0,
|
return new TDU(TDUIdentifier.RawData, rt.ToArray(),
|
||||||
(uint)rt.Count);
|
(uint)rt.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit TypedMapComposer(object value, Type keyType, Type valueType, Warehouse warehouse, DistributedConnection connection)
|
public static TDU TypedMapComposer(object value, Type keyType, Type valueType, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 0);
|
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||||
|
|
||||||
var kt = RepresentationType.FromType(keyType).Compose();
|
var kt = RepresentationType.FromType(keyType).Compose();
|
||||||
var vt = RepresentationType.FromType(valueType).Compose();
|
var vt = RepresentationType.FromType(valueType).Compose();
|
||||||
@@ -284,13 +284,13 @@ public static class DataSerializer
|
|||||||
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||||
|
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.TypedMap, rt.ToArray(), 0, (uint)rt.Count,
|
return new TDU(TDUIdentifier.TypedMap, rt.ToArray(), (uint)rt.Count,
|
||||||
DC.Combine(kt, 0, (uint)kt.Length, vt, 0, (uint)vt.Length));
|
DC.Combine(kt, 0, (uint)kt.Length, vt, 0, (uint)vt.Length));
|
||||||
}
|
}
|
||||||
public static TransmissionDataUnit TypedDictionaryComposer(object value, Type keyType, Type valueType, Warehouse warehouse, DistributedConnection connection)
|
public static TDU TypedDictionaryComposer(object value, Type keyType, Type valueType, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, null, 0, 0);
|
return new TDU(TDUIdentifier.Null, null, 0);
|
||||||
|
|
||||||
var kt = RepresentationType.FromType(keyType).Compose();
|
var kt = RepresentationType.FromType(keyType).Compose();
|
||||||
var vt = RepresentationType.FromType(valueType).Compose();
|
var vt = RepresentationType.FromType(valueType).Compose();
|
||||||
@@ -313,7 +313,7 @@ public static class DataSerializer
|
|||||||
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||||
|
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.TypedMap, rt.ToArray(), 0, (uint)rt.Count,
|
return new TDU(TDUIdentifier.TypedMap, rt.ToArray(), (uint)rt.Count,
|
||||||
DC.Combine(kt, 0, (uint)kt.Length, vt, 0, (uint)vt.Length));
|
DC.Combine(kt, 0, (uint)kt.Length, vt, 0, (uint)vt.Length));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,19 +324,18 @@ public static class DataSerializer
|
|||||||
|
|
||||||
var rt = new List<byte>();
|
var rt = new List<byte>();
|
||||||
|
|
||||||
TransmissionDataUnit? previous = null;
|
TDU? previous = null;
|
||||||
|
|
||||||
foreach (var i in value)
|
foreach (var i in value)
|
||||||
{
|
{
|
||||||
var tdu = Codec.ComposeInternal(i, warehouse, connection);
|
var tdu = Codec.ComposeInternal(i, warehouse, connection);
|
||||||
if (tdu.MatchType(previous.Value))
|
if (previous != null && tdu.MatchType(previous.Value))
|
||||||
{
|
{
|
||||||
rt.AddRange(TransmissionDataUnit.Compose(TransmissionDataUnitIdentifier.NotModified,
|
rt.Add((byte)TDUIdentifier.NotModified);
|
||||||
tdu.Data, null));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt.AddRange(tdu.Compose());
|
rt.AddRange(tdu.Composed);
|
||||||
}
|
}
|
||||||
|
|
||||||
previous = tdu;
|
previous = tdu;
|
||||||
@@ -345,36 +344,36 @@ public static class DataSerializer
|
|||||||
return rt.ToArray();
|
return rt.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit ResourceListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU ResourceListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 0);
|
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||||
|
|
||||||
var composed = ArrayComposer((IEnumerable)value, warehouse, connection);
|
var composed = ArrayComposer((IEnumerable)value, warehouse, connection);
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.ResourceList, composed, 0,
|
return new TDU(TDUIdentifier.ResourceList, composed,
|
||||||
(uint)composed.Length);
|
(uint)composed.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit RecordListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU RecordListComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 0);
|
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||||
|
|
||||||
var composed = ArrayComposer((IEnumerable)value, warehouse, connection);
|
var composed = ArrayComposer((IEnumerable)value, warehouse, connection);
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.RecordList,
|
return new TDU(TDUIdentifier.RecordList,
|
||||||
composed, 0, (uint)composed.Length);
|
composed, (uint)composed.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit ResourceComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU ResourceComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var resource = (IResource)value;
|
var resource = (IResource)value;
|
||||||
|
|
||||||
if (resource.Instance == null || resource.Instance.IsDestroyed)
|
if (resource.Instance == null || resource.Instance.IsDestroyed)
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, null, 0, 0);
|
return new TDU(TDUIdentifier.Null, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Codec.IsLocalResource(resource, connection))
|
if (Codec.IsLocalResource(resource, connection))
|
||||||
@@ -382,21 +381,21 @@ public static class DataSerializer
|
|||||||
var rid = (resource as DistributedResource).DistributedResourceInstanceId;
|
var rid = (resource as DistributedResource).DistributedResourceInstanceId;
|
||||||
|
|
||||||
if (rid <= 0xFF)
|
if (rid <= 0xFF)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.LocalResource8, new byte[] { (byte)rid }, 0, 1);
|
return new TDU(TDUIdentifier.LocalResource8, new byte[] { (byte)rid }, 1);
|
||||||
else if (rid <= 0xFFFF)
|
else if (rid <= 0xFFFF)
|
||||||
{
|
{
|
||||||
var rt = new byte[2];
|
var rt = new byte[2];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((ushort*)ptr) = (ushort)rid;
|
*((ushort*)ptr) = (ushort)rid;
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.LocalResource16, rt, 0, 2);
|
return new TDU(TDUIdentifier.LocalResource16, rt, 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var rt = new byte[4];
|
var rt = new byte[4];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((uint*)ptr) = rid;
|
*((uint*)ptr) = rid;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.LocalResource32, rt, 0, 4);
|
return new TDU(TDUIdentifier.LocalResource32, rt, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -408,29 +407,29 @@ public static class DataSerializer
|
|||||||
var rid = resource.Instance.Id;
|
var rid = resource.Instance.Id;
|
||||||
|
|
||||||
if (rid <= 0xFF)
|
if (rid <= 0xFF)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.RemoteResource8, new byte[] { (byte)rid }, 0, 1);
|
return new TDU(TDUIdentifier.RemoteResource8, new byte[] { (byte)rid }, 1);
|
||||||
else if (rid <= 0xFFFF)
|
else if (rid <= 0xFFFF)
|
||||||
{
|
{
|
||||||
var rt = new byte[2];
|
var rt = new byte[2];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((ushort*)ptr) = (ushort)rid;
|
*((ushort*)ptr) = (ushort)rid;
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.RemoteResource16, rt, 0, 2);
|
return new TDU(TDUIdentifier.RemoteResource16, rt, 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var rt = new byte[4];
|
var rt = new byte[4];
|
||||||
fixed (byte* ptr = rt)
|
fixed (byte* ptr = rt)
|
||||||
*((uint*)ptr) = rid;
|
*((uint*)ptr) = rid;
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.RemoteResource32, rt, 0, 4);
|
return new TDU(TDUIdentifier.RemoteResource32, rt, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit MapComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU MapComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 1);
|
return new TDU(TDUIdentifier.Null, new byte[0], 1);
|
||||||
|
|
||||||
var rt = new List<byte>();
|
var rt = new List<byte>();
|
||||||
var map = (IMap)value;
|
var map = (IMap)value;
|
||||||
@@ -438,16 +437,16 @@ public static class DataSerializer
|
|||||||
foreach (var el in map.Serialize())
|
foreach (var el in map.Serialize())
|
||||||
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Map, rt.ToArray(), 0, (uint)rt.Count);
|
return new TDU(TDUIdentifier.Map, rt.ToArray(), (uint)rt.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit UUIDComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU UUIDComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.UUID, ((UUID)value).Data, 0, 16);
|
return new TDU(TDUIdentifier.UUID, ((UUID)value).Data, 16);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe TransmissionDataUnit RecordComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static unsafe TDU RecordComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
var rt = new List<byte>();// BinaryList();
|
var rt = new List<byte>();// BinaryList();
|
||||||
var record = (IRecord)value;
|
var record = (IRecord)value;
|
||||||
@@ -461,7 +460,7 @@ public static class DataSerializer
|
|||||||
rt.AddRange(Codec.Compose(propValue, warehouse, connection));
|
rt.AddRange(Codec.Compose(propValue, warehouse, connection));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Record, rt.ToArray(), 0,
|
return new TDU(TDUIdentifier.Record, rt.ToArray(),
|
||||||
(uint)rt.Count,
|
(uint)rt.Count,
|
||||||
template.ClassId.Data);
|
template.ClassId.Data);
|
||||||
}
|
}
|
||||||
@@ -481,10 +480,10 @@ public static class DataSerializer
|
|||||||
return rt.ToArray();
|
return rt.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmissionDataUnit TupleComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
public static TDU TupleComposer(object value, Warehouse warehouse, DistributedConnection connection)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 0);
|
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||||
|
|
||||||
var fields = value.GetType().GetFields();
|
var fields = value.GetType().GetFields();
|
||||||
var list = fields.Select(x => x.GetValue(value)).ToArray();
|
var list = fields.Select(x => x.GetValue(value)).ToArray();
|
||||||
@@ -498,10 +497,10 @@ public static class DataSerializer
|
|||||||
var composed = ArrayComposer(list, warehouse, connection);
|
var composed = ArrayComposer(list, warehouse, connection);
|
||||||
|
|
||||||
if (composed == null)
|
if (composed == null)
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.Null, new byte[0], 0, 0);
|
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new TransmissionDataUnit(TransmissionDataUnitIdentifier.TypedTuple, composed, 0,
|
return new TDU(TDUIdentifier.TypedTuple, composed,
|
||||||
(uint)composed.Length, metadata.ToArray());
|
(uint)composed.Length, metadata.ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
123
Esiur/Data/ParsedTDU.cs
Normal file
123
Esiur/Data/ParsedTDU.cs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Esiur.Data
|
||||||
|
{
|
||||||
|
public struct ParsedTDU
|
||||||
|
{
|
||||||
|
public TDUIdentifier Identifier;
|
||||||
|
public int Index;
|
||||||
|
public TDUClass Class;
|
||||||
|
public uint Offset;
|
||||||
|
public ulong ContentLength;
|
||||||
|
public byte[] Data;
|
||||||
|
public byte Exponent;
|
||||||
|
public ulong TotalLength;
|
||||||
|
public byte[] Metadata;
|
||||||
|
|
||||||
|
public static (ulong, ParsedTDU?) Parse(byte[] data, uint offset, uint ends)
|
||||||
|
{
|
||||||
|
var h = data[offset++];
|
||||||
|
|
||||||
|
var cls = (TDUClass)(h >> 6);
|
||||||
|
|
||||||
|
if (cls == TDUClass.Fixed)
|
||||||
|
{
|
||||||
|
var exp = (h & 0x38) >> 3;
|
||||||
|
|
||||||
|
if (exp == 0)
|
||||||
|
return (1, new ParsedTDU()
|
||||||
|
{
|
||||||
|
Identifier = (TDUIdentifier)h,
|
||||||
|
Data = data,
|
||||||
|
Offset = offset,
|
||||||
|
Class = cls,
|
||||||
|
Exponent = (byte)exp,
|
||||||
|
Index = (byte)h & 0x7,
|
||||||
|
ContentLength = 0,
|
||||||
|
TotalLength = 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
ulong cl = (ulong)(1 << (exp - 1));
|
||||||
|
|
||||||
|
if (ends - offset < cl)
|
||||||
|
return (cl - (ends - offset), null);
|
||||||
|
|
||||||
|
//offset += (uint)cl;
|
||||||
|
|
||||||
|
return (1 + cl, new ParsedTDU()
|
||||||
|
{
|
||||||
|
Identifier = (TDUIdentifier)h,
|
||||||
|
Data = data,
|
||||||
|
Offset = offset,
|
||||||
|
Class = cls,
|
||||||
|
ContentLength = cl,
|
||||||
|
TotalLength = 1 + cl,
|
||||||
|
Exponent = (byte)exp,
|
||||||
|
Index = (byte)h & 0x7,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (cls == TDUClass.Typed)
|
||||||
|
{
|
||||||
|
ulong cll = (ulong)(h >> 3) & 0x7;
|
||||||
|
|
||||||
|
if (ends - offset < cll)
|
||||||
|
return (cll - (ends - offset), null);
|
||||||
|
|
||||||
|
ulong cl = 0;
|
||||||
|
|
||||||
|
for (uint i = 0; i < cll; i++)
|
||||||
|
cl = cl << 8 | data[offset++];
|
||||||
|
|
||||||
|
if (ends - offset < cl)
|
||||||
|
return (cl - (ends - offset), null);
|
||||||
|
|
||||||
|
var metaData = DC.Clip(data, offset + 1, data[offset]);
|
||||||
|
offset += data[offset];
|
||||||
|
|
||||||
|
|
||||||
|
return (1 + cl + cll, new ParsedTDU()
|
||||||
|
{
|
||||||
|
Identifier = (TDUIdentifier)(h & 0xC7),
|
||||||
|
Data = data,
|
||||||
|
Offset = offset,
|
||||||
|
Class = cls,
|
||||||
|
ContentLength = cl,
|
||||||
|
TotalLength = 1 + cl + cll,
|
||||||
|
Index = (byte)h & 0x7,
|
||||||
|
Metadata = metaData,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ulong cll = (ulong)(h >> 3) & 0x7;
|
||||||
|
|
||||||
|
if (ends - offset < cll)
|
||||||
|
return (cll - (ends - offset), null);
|
||||||
|
|
||||||
|
ulong cl = 0;
|
||||||
|
|
||||||
|
for (uint i = 0; i < cll; i++)
|
||||||
|
cl = cl << 8 | data[offset++];
|
||||||
|
|
||||||
|
if (ends - offset < cl)
|
||||||
|
return (cl - (ends - offset), null);
|
||||||
|
|
||||||
|
|
||||||
|
return (1 + cl + cll,
|
||||||
|
new ParsedTDU()
|
||||||
|
{
|
||||||
|
Identifier = (TDUIdentifier)(h & 0xC7),
|
||||||
|
Data = data,
|
||||||
|
Offset = offset,
|
||||||
|
Class = cls,
|
||||||
|
ContentLength = cl,
|
||||||
|
TotalLength = 1 + cl + cll,
|
||||||
|
Index = (byte)h & 0x7
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -76,30 +76,30 @@ namespace Esiur.Data
|
|||||||
RepresentationTypeIdentifier.TypedResource
|
RepresentationTypeIdentifier.TypedResource
|
||||||
};
|
};
|
||||||
|
|
||||||
static Map<TransmissionDataUnitIdentifier, RepresentationTypeIdentifier> typesMap = new Map<TransmissionDataUnitIdentifier, RepresentationTypeIdentifier>()
|
static Map<TDUIdentifier, RepresentationTypeIdentifier> typesMap = new Map<TDUIdentifier, RepresentationTypeIdentifier>()
|
||||||
{
|
{
|
||||||
[TransmissionDataUnitIdentifier.UInt8] = RepresentationTypeIdentifier.UInt8,
|
[TDUIdentifier.UInt8] = RepresentationTypeIdentifier.UInt8,
|
||||||
[TransmissionDataUnitIdentifier.Int8] = RepresentationTypeIdentifier.Int8,
|
[TDUIdentifier.Int8] = RepresentationTypeIdentifier.Int8,
|
||||||
[TransmissionDataUnitIdentifier.UInt16] = RepresentationTypeIdentifier.UInt16,
|
[TDUIdentifier.UInt16] = RepresentationTypeIdentifier.UInt16,
|
||||||
[TransmissionDataUnitIdentifier.Int16] = RepresentationTypeIdentifier.Int16,
|
[TDUIdentifier.Int16] = RepresentationTypeIdentifier.Int16,
|
||||||
[TransmissionDataUnitIdentifier.UInt32] = RepresentationTypeIdentifier.UInt32,
|
[TDUIdentifier.UInt32] = RepresentationTypeIdentifier.UInt32,
|
||||||
[TransmissionDataUnitIdentifier.Int32] = RepresentationTypeIdentifier.Int32,
|
[TDUIdentifier.Int32] = RepresentationTypeIdentifier.Int32,
|
||||||
[TransmissionDataUnitIdentifier.UInt64] = RepresentationTypeIdentifier.UInt64,
|
[TDUIdentifier.UInt64] = RepresentationTypeIdentifier.UInt64,
|
||||||
[TransmissionDataUnitIdentifier.Int64] = RepresentationTypeIdentifier.Int64,
|
[TDUIdentifier.Int64] = RepresentationTypeIdentifier.Int64,
|
||||||
[TransmissionDataUnitIdentifier.UInt128] = RepresentationTypeIdentifier.UInt128,
|
[TDUIdentifier.UInt128] = RepresentationTypeIdentifier.UInt128,
|
||||||
[TransmissionDataUnitIdentifier.Int128] = RepresentationTypeIdentifier.Int128,
|
[TDUIdentifier.Int128] = RepresentationTypeIdentifier.Int128,
|
||||||
[TransmissionDataUnitIdentifier.Char8] = RepresentationTypeIdentifier.Char,
|
[TDUIdentifier.Char8] = RepresentationTypeIdentifier.Char,
|
||||||
[TransmissionDataUnitIdentifier.DateTime] = RepresentationTypeIdentifier.DateTime,
|
[TDUIdentifier.DateTime] = RepresentationTypeIdentifier.DateTime,
|
||||||
[TransmissionDataUnitIdentifier.Float32] = RepresentationTypeIdentifier.Float32,
|
[TDUIdentifier.Float32] = RepresentationTypeIdentifier.Float32,
|
||||||
[TransmissionDataUnitIdentifier.Float64] = RepresentationTypeIdentifier.Float64,
|
[TDUIdentifier.Float64] = RepresentationTypeIdentifier.Float64,
|
||||||
[TransmissionDataUnitIdentifier.Decimal128] = RepresentationTypeIdentifier.Decimal,
|
[TDUIdentifier.Decimal128] = RepresentationTypeIdentifier.Decimal,
|
||||||
[TransmissionDataUnitIdentifier.False] = RepresentationTypeIdentifier.Bool,
|
[TDUIdentifier.False] = RepresentationTypeIdentifier.Bool,
|
||||||
[TransmissionDataUnitIdentifier.True] = RepresentationTypeIdentifier.Bool,
|
[TDUIdentifier.True] = RepresentationTypeIdentifier.Bool,
|
||||||
[TransmissionDataUnitIdentifier.Map] = RepresentationTypeIdentifier.Map,
|
[TDUIdentifier.Map] = RepresentationTypeIdentifier.Map,
|
||||||
[TransmissionDataUnitIdentifier.List] = RepresentationTypeIdentifier.List,
|
[TDUIdentifier.List] = RepresentationTypeIdentifier.List,
|
||||||
[TransmissionDataUnitIdentifier.RawData] = RepresentationTypeIdentifier.RawData,
|
[TDUIdentifier.RawData] = RepresentationTypeIdentifier.RawData,
|
||||||
[TransmissionDataUnitIdentifier.Record] = RepresentationTypeIdentifier.Record,
|
[TDUIdentifier.Record] = RepresentationTypeIdentifier.Record,
|
||||||
[TransmissionDataUnitIdentifier.String] = RepresentationTypeIdentifier.String,
|
[TDUIdentifier.String] = RepresentationTypeIdentifier.String,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
287
Esiur/Data/TDU.cs
Normal file
287
Esiur/Data/TDU.cs
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
using Esiur.Net.IIP;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using System.Xml.Schema;
|
||||||
|
using static Esiur.Data.Codec;
|
||||||
|
|
||||||
|
namespace Esiur.Data;
|
||||||
|
|
||||||
|
// Transmission Data Unit
|
||||||
|
public struct TDU
|
||||||
|
{
|
||||||
|
public TDUIdentifier Identifier;
|
||||||
|
//public int Index;
|
||||||
|
public TDUClass Class;
|
||||||
|
//public ulong ContentLength;
|
||||||
|
|
||||||
|
public byte[] Composed;
|
||||||
|
//public uint Offset;
|
||||||
|
|
||||||
|
public byte[] Metadata;
|
||||||
|
|
||||||
|
//public ulong Size
|
||||||
|
//{
|
||||||
|
// get
|
||||||
|
// {
|
||||||
|
// if (TotalSize != ulong.MaxValue)
|
||||||
|
// return TotalSize;
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// if (ContentLength <= 0xFF)
|
||||||
|
// return 2 + ContentLength;
|
||||||
|
// else if (ContentLength <= 0xFF_FF)
|
||||||
|
// return 3 + ContentLength;
|
||||||
|
// else if (ContentLength <= 0xFF_FF_FF)
|
||||||
|
// return 4 + ContentLength;
|
||||||
|
// else if (ContentLength <= 0xFF_FF_FF_FF)
|
||||||
|
// return 5 + ContentLength;
|
||||||
|
// else if (ContentLength <= 0xFF_FF_FF_FF_FF)
|
||||||
|
// return 6 + ContentLength;
|
||||||
|
// else if (ContentLength <= 0xFF_FF_FF_FF_FF_FF)
|
||||||
|
// return 7 + ContentLength;
|
||||||
|
// else if (ContentLength <= 0xFF_FF_FF_FF_FF_FF_FF)
|
||||||
|
// return 8 + ContentLength;
|
||||||
|
// else //if (ContentLength <= 0xFF_FF_FF_FF_FF_FF_FF_FF)
|
||||||
|
// return 9 + ContentLength;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//private ulong TotalSize;
|
||||||
|
|
||||||
|
public TDU()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public TDU(TDUIdentifier identifier)
|
||||||
|
{
|
||||||
|
Identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TDU(TDUIdentifier identifier,
|
||||||
|
byte[] data, ulong length, byte[] metadata = null)
|
||||||
|
{
|
||||||
|
Identifier = identifier;
|
||||||
|
//Index = (byte)identifier & 0x7;
|
||||||
|
Class = (TDUClass)((byte)identifier >> 6);
|
||||||
|
Metadata = metadata;
|
||||||
|
|
||||||
|
|
||||||
|
if (Class == TDUClass.Fixed)
|
||||||
|
{
|
||||||
|
Composed = DC.Combine(new byte[] { (byte)Identifier }, 0, 1, data, 0, (uint)length);
|
||||||
|
}
|
||||||
|
else if (Class == TDUClass.Dynamic
|
||||||
|
|| Class == TDUClass.Extension)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (length == 0)
|
||||||
|
{
|
||||||
|
Composed = new byte[1] { (byte)Identifier };
|
||||||
|
}
|
||||||
|
else if (length <= 0xFF)
|
||||||
|
{
|
||||||
|
Composed = new byte[2 + length];
|
||||||
|
Composed[0] = (byte)((byte)Identifier | 0x8);
|
||||||
|
Composed[1] = (byte)length;
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 2, (int)length);
|
||||||
|
}
|
||||||
|
else if (length <= 0xFF_FF)
|
||||||
|
{
|
||||||
|
var Composed = new byte[3 + length];
|
||||||
|
Composed[0] = (byte)((byte)Identifier | 0x10);
|
||||||
|
Composed[1] = (byte)((length >> 8) & 0xFF);
|
||||||
|
Composed[2] = (byte)(length & 0xFF);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 3, (int)length);
|
||||||
|
}
|
||||||
|
else if (length <= 0xFF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[4 + length];
|
||||||
|
Composed[0] = (byte)((byte)Identifier | 0x18);
|
||||||
|
Composed[1] = (byte)((length >> 16) & 0xFF);
|
||||||
|
Composed[2] = (byte)((length >> 8) & 0xFF);
|
||||||
|
Composed[3] = (byte)(length & 0xFF);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 4, (int)length);
|
||||||
|
}
|
||||||
|
else if (length <= 0xFF_FF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[5 + length];
|
||||||
|
Composed[0] = (byte)((byte)Identifier | 0x20);
|
||||||
|
Composed[1] = (byte)((length >> 24) & 0xFF);
|
||||||
|
Composed[2] = (byte)((length >> 16) & 0xFF);
|
||||||
|
Composed[3] = (byte)((length >> 8) & 0xFF);
|
||||||
|
Composed[4] = (byte)(length & 0xFF);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 5, (int)length);
|
||||||
|
}
|
||||||
|
else if (length <= 0xFF_FF_FF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[6 + length];
|
||||||
|
Composed[0] = (byte)((byte)Identifier | 0x28);
|
||||||
|
Composed[1] = (byte)((length >> 32) & 0xFF);
|
||||||
|
Composed[2] = (byte)((length >> 24) & 0xFF);
|
||||||
|
Composed[3] = (byte)((length >> 16) & 0xFF);
|
||||||
|
Composed[4] = (byte)((length >> 8) & 0xFF);
|
||||||
|
Composed[5] = (byte)(length & 0xFF);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 6, (int)length);
|
||||||
|
}
|
||||||
|
else if (length <= 0xFF_FF_FF_FF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[7 + length];
|
||||||
|
Composed[0] = (byte)((byte)Identifier | 0x30);
|
||||||
|
Composed[1] = (byte)((length >> 40) & 0xFF);
|
||||||
|
Composed[2] = (byte)((length >> 32) & 0xFF);
|
||||||
|
Composed[3] = (byte)((length >> 24) & 0xFF);
|
||||||
|
Composed[4] = (byte)((length >> 16) & 0xFF);
|
||||||
|
Composed[5] = (byte)((length >> 8) & 0xFF);
|
||||||
|
Composed[6] = (byte)(length & 0xFF);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 7, (int)length);
|
||||||
|
}
|
||||||
|
else //if (len <= 0xFF_FF_FF_FF_FF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[8 + length];
|
||||||
|
Composed[0] = (byte)((byte)Identifier | 0x38);
|
||||||
|
Composed[1] = (byte)((length >> 48) & 0xFF);
|
||||||
|
Composed[2] = (byte)((length >> 40) & 0xFF);
|
||||||
|
Composed[3] = (byte)((length >> 32) & 0xFF);
|
||||||
|
Composed[4] = (byte)((length >> 24) & 0xFF);
|
||||||
|
Composed[5] = (byte)((length >> 16) & 0xFF);
|
||||||
|
Composed[6] = (byte)((length >> 8) & 0xFF);
|
||||||
|
Composed[7] = (byte)(length & 0xFF);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 8, (int)length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Class == TDUClass.Typed)
|
||||||
|
{
|
||||||
|
if (metadata == null)
|
||||||
|
throw new Exception("Metadata must be provided for types.");
|
||||||
|
|
||||||
|
|
||||||
|
if (metadata.Length > 0xFF)
|
||||||
|
throw new Exception("Metadata can't exceed 255 bytes in length.");
|
||||||
|
|
||||||
|
var metaLen = (byte)metadata.Length;
|
||||||
|
|
||||||
|
var len = 1 + (ulong)metaLen + length;
|
||||||
|
|
||||||
|
|
||||||
|
if (length == 0)
|
||||||
|
{
|
||||||
|
Composed = new byte[1] { (byte)Identifier };
|
||||||
|
}
|
||||||
|
else if (metadata.Length > 0xFF)
|
||||||
|
{
|
||||||
|
throw new Exception("Metadata can't exceed 255 bytes in length.");
|
||||||
|
}
|
||||||
|
else if (length <= 0xFF)
|
||||||
|
{
|
||||||
|
Composed = new byte[2 + len];
|
||||||
|
Composed[0] = (byte)((byte)Identifier | 0x8);
|
||||||
|
Composed[1] = (byte)len;
|
||||||
|
Composed[2] = metaLen;
|
||||||
|
|
||||||
|
Buffer.BlockCopy(metadata, 0, Composed, 3, metaLen);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 3 + metaLen, (int)length);
|
||||||
|
}
|
||||||
|
else if (len <= 0xFF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[3 + len];
|
||||||
|
Composed[0] = (byte)((byte)identifier | 0x10);
|
||||||
|
Composed[1] = (byte)((len >> 8) & 0xFF);
|
||||||
|
Composed[2] = (byte)(len & 0xFF);
|
||||||
|
Composed[3] = metaLen;
|
||||||
|
|
||||||
|
Buffer.BlockCopy(metadata, 0, Composed, 4, metaLen);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 4 + metaLen, (int)length);
|
||||||
|
}
|
||||||
|
else if (len <= 0xFF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[4 + len];
|
||||||
|
Composed[0] = (byte)((byte)identifier | 0x18);
|
||||||
|
Composed[1] = (byte)((len >> 16) & 0xFF);
|
||||||
|
Composed[2] = (byte)((len >> 8) & 0xFF);
|
||||||
|
Composed[3] = (byte)(len & 0xFF);
|
||||||
|
Composed[4] = metaLen;
|
||||||
|
|
||||||
|
Buffer.BlockCopy(metadata, 0, Composed, 5, metaLen);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 5 + metaLen, (int)length);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (len <= 0xFF_FF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[5 + len];
|
||||||
|
Composed[0] = (byte)((byte)identifier | 0x20);
|
||||||
|
Composed[1] = (byte)((len >> 24) & 0xFF);
|
||||||
|
Composed[2] = (byte)((len >> 16) & 0xFF);
|
||||||
|
Composed[3] = (byte)((len >> 8) & 0xFF);
|
||||||
|
Composed[4] = (byte)(len & 0xFF);
|
||||||
|
Composed[5] = metaLen;
|
||||||
|
|
||||||
|
Buffer.BlockCopy(metadata, 0, Composed, 6, metaLen);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 6 + metaLen, (int)length);
|
||||||
|
}
|
||||||
|
else if (len <= 0xFF_FF_FF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[6 + len];
|
||||||
|
Composed[0] = (byte)((byte)identifier | 0x28);
|
||||||
|
Composed[1] = (byte)((len >> 32) & 0xFF);
|
||||||
|
Composed[2] = (byte)((len >> 24) & 0xFF);
|
||||||
|
Composed[3] = (byte)((len >> 16) & 0xFF);
|
||||||
|
Composed[4] = (byte)((len >> 8) & 0xFF);
|
||||||
|
Composed[5] = (byte)(len & 0xFF);
|
||||||
|
Composed[6] = metaLen;
|
||||||
|
|
||||||
|
Buffer.BlockCopy(metadata, 0, Composed, 7, metaLen);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 7 + metaLen, (int)length);
|
||||||
|
}
|
||||||
|
else if (len <= 0xFF_FF_FF_FF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[7 + len];
|
||||||
|
Composed[0] = (byte)((byte)identifier | 0x30);
|
||||||
|
Composed[1] = (byte)((len >> 40) & 0xFF);
|
||||||
|
Composed[2] = (byte)((len >> 32) & 0xFF);
|
||||||
|
Composed[3] = (byte)((len >> 24) & 0xFF);
|
||||||
|
Composed[4] = (byte)((len >> 16) & 0xFF);
|
||||||
|
Composed[5] = (byte)((len >> 8) & 0xFF);
|
||||||
|
Composed[6] = (byte)(len & 0xFF);
|
||||||
|
Composed[7] = metaLen;
|
||||||
|
|
||||||
|
Buffer.BlockCopy(metadata, 0, Composed, 8, metaLen);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 8 + metaLen, (int)length);
|
||||||
|
}
|
||||||
|
else //if (len <= 0xFF_FF_FF_FF_FF_FF_FF)
|
||||||
|
{
|
||||||
|
Composed = new byte[8 + len];
|
||||||
|
Composed[0] = (byte)((byte)identifier | 0x38);
|
||||||
|
Composed[1] = (byte)((len >> 48) & 0xFF);
|
||||||
|
Composed[2] = (byte)((len >> 40) & 0xFF);
|
||||||
|
Composed[3] = (byte)((len >> 32) & 0xFF);
|
||||||
|
Composed[4] = (byte)((len >> 24) & 0xFF);
|
||||||
|
Composed[5] = (byte)((len >> 16) & 0xFF);
|
||||||
|
Composed[6] = (byte)((len >> 8) & 0xFF);
|
||||||
|
Composed[7] = (byte)(len & 0xFF);
|
||||||
|
Composed[8] = metaLen;
|
||||||
|
|
||||||
|
Buffer.BlockCopy(metadata, 0, Composed, 9, metaLen);
|
||||||
|
Buffer.BlockCopy(data, 0, Composed, 9 + metaLen, (int)length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool MatchType(TDU with)
|
||||||
|
{
|
||||||
|
if (Identifier != with.Identifier)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (Class == TDUClass.Typed)
|
||||||
|
if (!Metadata.SequenceEqual(with.Metadata))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,7 +4,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Esiur.Data
|
namespace Esiur.Data
|
||||||
{
|
{
|
||||||
public enum TransmissionDataUnitClass
|
public enum TDUClass
|
||||||
{
|
{
|
||||||
Fixed = 0x0,
|
Fixed = 0x0,
|
||||||
Dynamic = 0x1,
|
Dynamic = 0x1,
|
@@ -4,7 +4,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Esiur.Data
|
namespace Esiur.Data
|
||||||
{
|
{
|
||||||
public enum TransmissionDataUnitIdentifier
|
public enum TDUIdentifier
|
||||||
{
|
{
|
||||||
Null = 0x0,
|
Null = 0x0,
|
||||||
False = 0x1,
|
False = 0x1,
|
@@ -1,337 +0,0 @@
|
|||||||
using Esiur.Net.IIP;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace Esiur.Data;
|
|
||||||
|
|
||||||
|
|
||||||
public struct TransmissionDataUnit
|
|
||||||
{
|
|
||||||
public TransmissionDataUnitIdentifier Identifier;
|
|
||||||
public int Index;
|
|
||||||
public TransmissionDataUnitClass Class;
|
|
||||||
public uint Offset;
|
|
||||||
public ulong ContentLength;
|
|
||||||
public byte Exponent;
|
|
||||||
public byte[] Data;
|
|
||||||
public byte[] Metadata;
|
|
||||||
|
|
||||||
public ulong Size;
|
|
||||||
|
|
||||||
public TransmissionDataUnit(TransmissionDataUnitIdentifier identifier,
|
|
||||||
byte[] data, uint offset,
|
|
||||||
ulong length, byte[] metadata = null,
|
|
||||||
byte exponent = 0)
|
|
||||||
{
|
|
||||||
Identifier = identifier;
|
|
||||||
Index = (byte)identifier & 0x7;
|
|
||||||
Class = (TransmissionDataUnitClass)((byte)identifier >> 6);
|
|
||||||
Offset = offset;
|
|
||||||
ContentLength = length;
|
|
||||||
Exponent = exponent;
|
|
||||||
Data = data;
|
|
||||||
Metadata = metadata;
|
|
||||||
|
|
||||||
Size = Class == TransmissionDataUnitClass.Fixed ? 1 + length: 1 + length +
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] GetTypeMetadata()
|
|
||||||
{
|
|
||||||
if (Class != TransmissionDataUnitClass.Typed)
|
|
||||||
throw new Exception("Class has no metadata.");
|
|
||||||
|
|
||||||
var size = Data[Offset];
|
|
||||||
return Data.Clip(Offset + 1, size);
|
|
||||||
|
|
||||||
}
|
|
||||||
public bool MatchType(TransmissionDataUnit with)
|
|
||||||
{
|
|
||||||
if (Identifier != with.Identifier)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (Class == TransmissionDataUnitClass.Typed)
|
|
||||||
if (!Metadata.SequenceEqual(with.Metadata))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] Compose()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] Compose(TransmissionDataUnitIdentifier identifier, byte[] data, byte[] typeMetadata)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (data == null || data.Length == 0)
|
|
||||||
return new byte[] { (byte)identifier };
|
|
||||||
|
|
||||||
var cls = (TransmissionDataUnitClass)((int)identifier >> 6);
|
|
||||||
if (cls == TransmissionDataUnitClass.Fixed)
|
|
||||||
{
|
|
||||||
return DC.Combine(new byte[] { (byte)identifier }, 0, 1, data, 0, (uint)data.Length);
|
|
||||||
}
|
|
||||||
else if (cls == TransmissionDataUnitClass.Dynamic
|
|
||||||
|| cls == TransmissionDataUnitClass.Extension)
|
|
||||||
{
|
|
||||||
var len = (ulong)data.LongLength;
|
|
||||||
|
|
||||||
if (len == 0)
|
|
||||||
{
|
|
||||||
return new byte[1] { (byte)identifier };
|
|
||||||
}
|
|
||||||
else if (len <= 0xFF)
|
|
||||||
{
|
|
||||||
var rt = new byte[2 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x8);
|
|
||||||
rt[1] = (byte)len;
|
|
||||||
Buffer.BlockCopy(data, 0, rt, 2, (int)len);
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
else if (len <= 0xFF_FF)
|
|
||||||
{
|
|
||||||
var rt = new byte[3 + len];
|
|
||||||
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);
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
else if (len <= 0xFF_FF_FF)
|
|
||||||
{
|
|
||||||
var rt = new byte[4 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x18);
|
|
||||||
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);
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
else if (len <= 0xFF_FF_FF_FF)
|
|
||||||
{
|
|
||||||
var rt = new byte[5 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x20);
|
|
||||||
rt[1] = (byte)((len >> 24) & 0xFF);
|
|
||||||
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);
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
else if (len <= 0xFF_FF_FF_FF_FF)
|
|
||||||
{
|
|
||||||
var rt = new byte[6 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x28);
|
|
||||||
rt[1] = (byte)((len >> 32) & 0xFF);
|
|
||||||
rt[2] = (byte)((len >> 24) & 0xFF);
|
|
||||||
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);
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
else if (len <= 0xFF_FF_FF_FF_FF_FF)
|
|
||||||
{
|
|
||||||
var rt = new byte[7 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x30);
|
|
||||||
rt[1] = (byte)((len >> 40) & 0xFF);
|
|
||||||
rt[2] = (byte)((len >> 32) & 0xFF);
|
|
||||||
rt[3] = (byte)((len >> 24) & 0xFF);
|
|
||||||
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);
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
else //if (len <= 0xFF_FF_FF_FF_FF_FF_FF)
|
|
||||||
{
|
|
||||||
var rt = new byte[8 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x38);
|
|
||||||
rt[1] = (byte)((len >> 48) & 0xFF);
|
|
||||||
rt[2] = (byte)((len >> 40) & 0xFF);
|
|
||||||
rt[3] = (byte)((len >> 32) & 0xFF);
|
|
||||||
rt[4] = (byte)((len >> 24) & 0xFF);
|
|
||||||
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);
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (cls == TransmissionDataUnitClass.Typed)
|
|
||||||
{
|
|
||||||
|
|
||||||
var len = 1 + (ulong)typeMetadata.LongLength + (ulong)data.LongLength;
|
|
||||||
|
|
||||||
if (len == 0)
|
|
||||||
{
|
|
||||||
return new byte[1] { (byte)identifier };
|
|
||||||
}
|
|
||||||
else if (len <= 0xFF)
|
|
||||||
{
|
|
||||||
var rt = new byte[2 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x8);
|
|
||||||
rt[1] = (byte)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)
|
|
||||||
{
|
|
||||||
var rt = new byte[3 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x10);
|
|
||||||
rt[1] = (byte)((len >> 8) & 0xFF);
|
|
||||||
rt[2] = (byte)(len & 0xFF);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
var rt = new byte[4 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x18);
|
|
||||||
rt[1] = (byte)((len >> 16) & 0xFF);
|
|
||||||
rt[2] = (byte)((len >> 8) & 0xFF);
|
|
||||||
rt[3] = (byte)(len & 0xFF);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
var rt = new byte[5 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x20);
|
|
||||||
rt[1] = (byte)((len >> 24) & 0xFF);
|
|
||||||
rt[2] = (byte)((len >> 16) & 0xFF);
|
|
||||||
rt[3] = (byte)((len >> 8) & 0xFF);
|
|
||||||
rt[4] = (byte)(len & 0xFF);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
var rt = new byte[6 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x28);
|
|
||||||
rt[1] = (byte)((len >> 32) & 0xFF);
|
|
||||||
rt[2] = (byte)((len >> 24) & 0xFF);
|
|
||||||
rt[3] = (byte)((len >> 16) & 0xFF);
|
|
||||||
rt[4] = (byte)((len >> 8) & 0xFF);
|
|
||||||
rt[5] = (byte)(len & 0xFF);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
var rt = new byte[7 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x30);
|
|
||||||
rt[1] = (byte)((len >> 40) & 0xFF);
|
|
||||||
rt[2] = (byte)((len >> 32) & 0xFF);
|
|
||||||
rt[3] = (byte)((len >> 24) & 0xFF);
|
|
||||||
rt[4] = (byte)((len >> 16) & 0xFF);
|
|
||||||
rt[5] = (byte)((len >> 8) & 0xFF);
|
|
||||||
rt[6] = (byte)(len & 0xFF);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
var rt = new byte[8 + len];
|
|
||||||
rt[0] = (byte)((byte)identifier | 0x38);
|
|
||||||
rt[1] = (byte)((len >> 48) & 0xFF);
|
|
||||||
rt[2] = (byte)((len >> 40) & 0xFF);
|
|
||||||
rt[3] = (byte)((len >> 32) & 0xFF);
|
|
||||||
rt[4] = (byte)((len >> 24) & 0xFF);
|
|
||||||
rt[5] = (byte)((len >> 16) & 0xFF);
|
|
||||||
rt[6] = (byte)((len >> 8) & 0xFF);
|
|
||||||
rt[7] = (byte)(len & 0xFF);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
var h = data[offset++];
|
|
||||||
|
|
||||||
var cls = (TransmissionDataUnitClass)(h >> 6);
|
|
||||||
|
|
||||||
if (cls == TransmissionDataUnitClass.Fixed)
|
|
||||||
{
|
|
||||||
var exp = (h & 0x38) >> 3;
|
|
||||||
|
|
||||||
if (exp == 0)
|
|
||||||
return (1, new TransmissionDataUnit((TransmissionDataUnitIdentifier)h, data, offset, 0));
|
|
||||||
|
|
||||||
ulong cl = (ulong)(1 << (exp - 1));
|
|
||||||
|
|
||||||
if (ends - offset < cl)
|
|
||||||
return (cl - (ends - offset), null);
|
|
||||||
|
|
||||||
//offset += (uint)cl;
|
|
||||||
|
|
||||||
return (1 + cl, new TransmissionDataUnit((TransmissionDataUnitIdentifier)h, data, offset, cl, null, (byte)exp));
|
|
||||||
}
|
|
||||||
else if (cls == TransmissionDataUnitClass.Typed)
|
|
||||||
{
|
|
||||||
ulong cll = (ulong)(h >> 3) & 0x7;
|
|
||||||
|
|
||||||
if (ends - offset < cll)
|
|
||||||
return (cll - (ends - offset), null);
|
|
||||||
|
|
||||||
ulong cl = 0;
|
|
||||||
|
|
||||||
for (uint i = 0; i < cll; i++)
|
|
||||||
cl = cl << 8 | data[offset++];
|
|
||||||
|
|
||||||
if (ends - offset < cl)
|
|
||||||
return (cl - (ends - offset), null);
|
|
||||||
|
|
||||||
var metaData = DC.Clip(data, offset + 1, data[offset]);
|
|
||||||
offset += data[offset];
|
|
||||||
|
|
||||||
return (1 + cl + cll, new TransmissionDataUnit((TransmissionDataUnitIdentifier)(h & 0xC7), data, offset, cl, metaData));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ulong cll = (ulong)(h >> 3) & 0x7;
|
|
||||||
|
|
||||||
if (ends - offset < cll)
|
|
||||||
return (cll - (ends - offset), null);
|
|
||||||
|
|
||||||
ulong cl = 0;
|
|
||||||
|
|
||||||
for (uint i = 0; i < cll; i++)
|
|
||||||
cl = cl << 8 | data[offset++];
|
|
||||||
|
|
||||||
if (ends - offset < cl)
|
|
||||||
return (cl - (ends - offset), null);
|
|
||||||
|
|
||||||
|
|
||||||
return (1 + cl + cll, new TransmissionDataUnit((TransmissionDataUnitIdentifier)(h & 0xC7), data, offset, cl));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -51,9 +51,9 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public delegate void ProtocolGeneralHandler(DistributedConnection connection, TransmissionDataUnit dataType, byte[] data);
|
public delegate void ProtocolGeneralHandler(DistributedConnection connection, ParsedTDU dataType, byte[] data);
|
||||||
|
|
||||||
public delegate void ProtocolRequestReplyHandler(DistributedConnection connection, uint callbackId, TransmissionDataUnit dataType, byte[] data);
|
public delegate void ProtocolRequestReplyHandler(DistributedConnection connection, uint callbackId, ParsedTDU dataType, byte[] data);
|
||||||
|
|
||||||
// Delegates
|
// Delegates
|
||||||
public delegate void ReadyEvent(DistributedConnection sender);
|
public delegate void ReadyEvent(DistributedConnection sender);
|
||||||
|
@@ -262,7 +262,7 @@ partial class DistributedConnection
|
|||||||
SendReply(IIPPacketReply.Chunk, callbackId, chunk);
|
SendReply(IIPPacketReply.Chunk, callbackId, chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPReplyCompleted(uint callbackId, TransmissionDataUnit dataType, byte[] data)
|
void IIPReplyCompleted(uint callbackId, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var req = requests.Take(callbackId);
|
var req = requests.Take(callbackId);
|
||||||
|
|
||||||
@@ -286,12 +286,12 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPExtensionAction(byte actionId, TransmissionDataUnit? dataType, byte[] data)
|
void IIPExtensionAction(byte actionId, ParsedTDU? dataType, byte[] data)
|
||||||
{
|
{
|
||||||
// nothing is supported now
|
// nothing is supported now
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPReplyPropagated(uint callbackId, TransmissionDataUnit dataType, byte[] data)
|
void IIPReplyPropagated(uint callbackId, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var req = requests[callbackId];
|
var req = requests[callbackId];
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPReplyError(uint callbackId, TransmissionDataUnit dataType, byte[] data, ErrorType type)
|
void IIPReplyError(uint callbackId, ParsedTDU dataType, byte[] data, ErrorType type)
|
||||||
{
|
{
|
||||||
var req = requests.Take(callbackId);
|
var req = requests.Take(callbackId);
|
||||||
|
|
||||||
@@ -334,7 +334,7 @@ partial class DistributedConnection
|
|||||||
req.TriggerError(new AsyncException(type, errorCode, errorMsg));
|
req.TriggerError(new AsyncException(type, errorCode, errorMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPReplyProgress(uint callbackId, TransmissionDataUnit dataType, byte[] data)
|
void IIPReplyProgress(uint callbackId, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var req = requests[callbackId];
|
var req = requests[callbackId];
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ partial class DistributedConnection
|
|||||||
req.TriggerProgress(ProgressType.Execution, current, total);
|
req.TriggerProgress(ProgressType.Execution, current, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPReplyWarning(uint callbackId, TransmissionDataUnit dataType, byte[] data)
|
void IIPReplyWarning(uint callbackId, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var req = requests[callbackId];
|
var req = requests[callbackId];
|
||||||
|
|
||||||
@@ -374,7 +374,7 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void IIPReplyChunk(uint callbackId, TransmissionDataUnit dataType, byte[] data)
|
void IIPReplyChunk(uint callbackId, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var req = requests[callbackId];
|
var req = requests[callbackId];
|
||||||
|
|
||||||
@@ -389,16 +389,16 @@ partial class DistributedConnection
|
|||||||
req.TriggerChunk(parsed);
|
req.TriggerChunk(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPNotificationResourceReassigned(TransmissionDataUnit dataType, byte[] data)
|
void IIPNotificationResourceReassigned(ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
// uint resourceId, uint newResourceId
|
// uint resourceId, uint newResourceId
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPNotificationResourceMoved(TransmissionDataUnit dataType, byte[] data) { }
|
void IIPNotificationResourceMoved(ParsedTDU dataType, byte[] data) { }
|
||||||
|
|
||||||
void IIPNotificationSystemFailure(TransmissionDataUnit dataType, byte[] data) { }
|
void IIPNotificationSystemFailure(ParsedTDU dataType, byte[] data) { }
|
||||||
|
|
||||||
void IIPNotificationResourceDestroyed(TransmissionDataUnit dataType, byte[] data)
|
void IIPNotificationResourceDestroyed(ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (size, rt) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType);
|
var (size, rt) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType);
|
||||||
|
|
||||||
@@ -429,7 +429,7 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPNotificationPropertyModified(TransmissionDataUnit dataType, byte[] data)
|
void IIPNotificationPropertyModified(ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
// resourceId, index, value
|
// resourceId, index, value
|
||||||
var (valueOffset, valueSize, args) =
|
var (valueOffset, valueSize, args) =
|
||||||
@@ -468,7 +468,7 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IIPNotificationEventOccurred(TransmissionDataUnit dataType, byte[] data)
|
void IIPNotificationEventOccurred(ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
// resourceId, index, value
|
// resourceId, index, value
|
||||||
var (valueOffset, valueSize, args) =
|
var (valueOffset, valueSize, args) =
|
||||||
@@ -517,7 +517,7 @@ partial class DistributedConnection
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestAttachResource(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestAttachResource(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
@@ -572,7 +572,7 @@ partial class DistributedConnection
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestReattachResource(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestReattachResource(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
// resourceId, index, value
|
// resourceId, index, value
|
||||||
var (valueOffset, valueSize, args) =
|
var (valueOffset, valueSize, args) =
|
||||||
@@ -630,7 +630,7 @@ partial class DistributedConnection
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestDetachResource(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestDetachResource(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
@@ -661,7 +661,7 @@ partial class DistributedConnection
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestCreateResource(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestCreateResource(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (_, parsed) = Codec.ParseAsync(data, 0, this, null, dataType);
|
var (_, parsed) = Codec.ParseAsync(data, 0, this, null, dataType);
|
||||||
|
|
||||||
@@ -722,7 +722,7 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IIPRequestDeleteResource(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestDeleteResource(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
@@ -751,7 +751,7 @@ partial class DistributedConnection
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestMoveResource(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestMoveResource(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
||||||
@@ -790,12 +790,12 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void IIPRequestToken(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestToken(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
// @TODO: To be implemented
|
// @TODO: To be implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestLinkTemplates(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestLinkTemplates(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
|
|
||||||
@@ -828,7 +828,7 @@ partial class DistributedConnection
|
|||||||
Instance.Warehouse.Query(resourceLink).Then(queryCallback);
|
Instance.Warehouse.Query(resourceLink).Then(queryCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestTemplateFromClassName(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestTemplateFromClassName(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
|
|
||||||
@@ -847,7 +847,7 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestTemplateFromClassId(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestTemplateFromClassId(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
@@ -869,7 +869,7 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void IIPRequestTemplateFromResourceId(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestTemplateFromResourceId(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
@@ -892,7 +892,7 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void IIPRequestGetResourceIdByLink(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestGetResourceIdByLink(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (_, parsed) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, parsed) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
var resourceLink = (string)parsed;
|
var resourceLink = (string)parsed;
|
||||||
@@ -920,7 +920,7 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestQueryResources(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestQueryResources(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (_, parsed) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
var (_, parsed) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType);
|
||||||
|
|
||||||
@@ -978,7 +978,7 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IIPRequestProcedureCall(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestProcedureCall(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
||||||
dataType.ContentLength, Instance.Warehouse, 1);
|
dataType.ContentLength, Instance.Warehouse, 1);
|
||||||
@@ -1038,7 +1038,7 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestStaticCall(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestStaticCall(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
||||||
dataType.ContentLength, Instance.Warehouse, 2);
|
dataType.ContentLength, Instance.Warehouse, 2);
|
||||||
@@ -1115,7 +1115,7 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestInvokeFunction(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestInvokeFunction(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
||||||
dataType.ContentLength, Instance.Warehouse, 2);
|
dataType.ContentLength, Instance.Warehouse, 2);
|
||||||
@@ -1371,7 +1371,7 @@ partial class DistributedConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestSubscribe(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestSubscribe(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
||||||
@@ -1430,7 +1430,7 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IIPRequestUnsubscribe(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestUnsubscribe(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
||||||
@@ -1491,7 +1491,7 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void IIPRequestSetProperty(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestSetProperty(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
||||||
@@ -2056,7 +2056,7 @@ partial class DistributedConnection
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void IIPRequestKeepAlive(uint callback, TransmissionDataUnit dataType, byte[] data)
|
void IIPRequestKeepAlive(uint callback, ParsedTDU dataType, byte[] data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset,
|
||||||
|
@@ -136,7 +136,7 @@ public class IIPAuthPacket : Packet
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransmissionDataUnit? DataType
|
public ParsedTDU? DataType
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
@@ -188,7 +188,7 @@ public class IIPAuthPacket : Packet
|
|||||||
if (NotEnough(offset, ends, 1))
|
if (NotEnough(offset, ends, 1))
|
||||||
return -dataLengthNeeded;
|
return -dataLengthNeeded;
|
||||||
|
|
||||||
(var size, DataType) = TransmissionDataUnit.Parse(data, offset, ends);
|
(var size, DataType) = ParsedTDU.Parse(data, offset, ends);
|
||||||
|
|
||||||
if (DataType == null)
|
if (DataType == null)
|
||||||
return -(int)size;
|
return -(int)size;
|
||||||
@@ -208,7 +208,7 @@ public class IIPAuthPacket : Packet
|
|||||||
if (NotEnough(offset, ends, 1))
|
if (NotEnough(offset, ends, 1))
|
||||||
return -dataLengthNeeded;
|
return -dataLengthNeeded;
|
||||||
|
|
||||||
(var size, DataType) = TransmissionDataUnit.Parse(data, offset, ends);
|
(var size, DataType) = ParsedTDU.Parse(data, offset, ends);
|
||||||
|
|
||||||
if (DataType == null)
|
if (DataType == null)
|
||||||
return -(int)size;
|
return -(int)size;
|
||||||
@@ -280,7 +280,7 @@ public class IIPAuthPacket : Packet
|
|||||||
Reference = data.GetUInt32(offset, Endian.Little);
|
Reference = data.GetUInt32(offset, Endian.Little);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
(var size, DataType) = TransmissionDataUnit.Parse(data, offset, ends);
|
(var size, DataType) = ParsedTDU.Parse(data, offset, ends);
|
||||||
|
|
||||||
if (DataType == null)
|
if (DataType == null)
|
||||||
return -(int)size;
|
return -(int)size;
|
||||||
@@ -445,7 +445,7 @@ public class IIPAuthPacket : Packet
|
|||||||
if (NotEnough(offset, ends, 1))
|
if (NotEnough(offset, ends, 1))
|
||||||
return -dataLengthNeeded;
|
return -dataLengthNeeded;
|
||||||
|
|
||||||
(var size, DataType) = TransmissionDataUnit.Parse(data, offset, ends);
|
(var size, DataType) = ParsedTDU.Parse(data, offset, ends);
|
||||||
|
|
||||||
if (DataType == null)
|
if (DataType == null)
|
||||||
return -(int)size;
|
return -(int)size;
|
||||||
|
@@ -44,7 +44,7 @@ class IIPPacket : Packet
|
|||||||
|
|
||||||
public byte Extension { get; set; }
|
public byte Extension { get; set; }
|
||||||
|
|
||||||
public TransmissionDataUnit? DataType { get; set; }
|
public ParsedTDU? DataType { get; set; }
|
||||||
|
|
||||||
|
|
||||||
private uint dataLengthNeeded;
|
private uint dataLengthNeeded;
|
||||||
@@ -124,7 +124,7 @@ class IIPPacket : Packet
|
|||||||
if (NotEnough(offset, ends, 1))
|
if (NotEnough(offset, ends, 1))
|
||||||
return -dataLengthNeeded;
|
return -dataLengthNeeded;
|
||||||
|
|
||||||
(var size, DataType) = TransmissionDataUnit.Parse(data, offset, ends);
|
(var size, DataType) = ParsedTDU.Parse(data, offset, ends);
|
||||||
|
|
||||||
if (DataType == null)
|
if (DataType == null)
|
||||||
return -(int)size;
|
return -(int)size;
|
||||||
|
@@ -59,10 +59,11 @@ namespace Test
|
|||||||
static void TestSerialization(object x, DistributedConnection connection = null)
|
static void TestSerialization(object x, DistributedConnection connection = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
var y = Codec.Compose(x, connection);
|
var d = Codec.Compose(x, Warehouse.Default, connection);
|
||||||
var rr = DC.ToHex(y);
|
// var rr = DC.ToHex(y);
|
||||||
|
|
||||||
Console.WriteLine(x.GetType().Name + ": " + rr);
|
var y = Codec.ParseSync(d, 0, Warehouse.Default);
|
||||||
|
Console.WriteLine($"{x.GetType().Name}: {x} == {y}, {d.ToHex()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,7 +82,13 @@ namespace Test
|
|||||||
|
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
|
TestSerialization("Hello");
|
||||||
|
TestSerialization(10);
|
||||||
|
TestSerialization(10.1);
|
||||||
|
TestSerialization(10.1d);
|
||||||
|
TestSerialization((byte)1);
|
||||||
|
TestSerialization((byte)2);
|
||||||
|
TestSerialization(new int[] { 1, 2, 3, 4 });
|
||||||
//var x = LogLevel.Warning;
|
//var x = LogLevel.Warning;
|
||||||
|
|
||||||
//TestSerialization(LogLevel.Warning);
|
//TestSerialization(LogLevel.Warning);
|
||||||
|
Reference in New Issue
Block a user