mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-04-03 20:08:21 +00:00
WIP
This commit is contained in:
@@ -64,7 +64,7 @@ public class BinaryList
|
||||
}
|
||||
|
||||
|
||||
public BinaryList AddUUID(UUID value)
|
||||
public BinaryList AddUUID(Uuid value)
|
||||
{
|
||||
list.AddRange(value.Data);
|
||||
return this;
|
||||
|
||||
@@ -41,8 +41,8 @@ public static class Codec
|
||||
|
||||
//delegate AsyncReply AsyncParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence);
|
||||
|
||||
delegate object AsyncParser(ParsedTDU tdu, EpConnection connection, uint[] requestSequence);
|
||||
delegate object SyncParser(ParsedTDU tdu, Warehouse warehouse);
|
||||
delegate object AsyncParser(ParsedTdu tdu, EpConnection connection, uint[] requestSequence);
|
||||
delegate object SyncParser(ParsedTdu tdu, Warehouse warehouse);
|
||||
|
||||
static AsyncParser[][] FixedAsyncParsers = new AsyncParser[][]
|
||||
{
|
||||
@@ -195,20 +195,20 @@ public static class Codec
|
||||
public static (uint, object) ParseAsync(byte[] data, uint offset, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
|
||||
var tdu = ParsedTDU.Parse(data, offset, (uint)data.Length);
|
||||
var tdu = ParsedTdu.Parse(data, offset, (uint)data.Length);
|
||||
|
||||
if (tdu.Class == TDUClass.Invalid)
|
||||
if (tdu.Class == TduClass.Invalid)
|
||||
throw new NullReferenceException("DataType can't be parsed.");
|
||||
|
||||
if (tdu.Class == TDUClass.Fixed)
|
||||
if (tdu.Class == TduClass.Fixed)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, FixedAsyncParsers[tdu.Exponent][tdu.Index](tdu, connection, requestSequence));
|
||||
}
|
||||
else if (tdu.Class == TDUClass.Dynamic)
|
||||
else if (tdu.Class == TduClass.Dynamic)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, DynamicAsyncParsers[tdu.Index](tdu, connection, requestSequence));
|
||||
}
|
||||
else if (tdu.Class == TDUClass.Typed)
|
||||
else if (tdu.Class == TduClass.Typed)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, TypedAsyncParsers[tdu.Index](tdu, connection, requestSequence));
|
||||
}
|
||||
@@ -219,20 +219,20 @@ public static class Codec
|
||||
}
|
||||
}
|
||||
|
||||
public static (uint, object) ParseAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static (uint, object) ParseAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
if (tdu.Class == TDUClass.Invalid)
|
||||
if (tdu.Class == TduClass.Invalid)
|
||||
throw new NullReferenceException("DataType can't be parsed.");
|
||||
|
||||
if (tdu.Class == TDUClass.Fixed)
|
||||
if (tdu.Class == TduClass.Fixed)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, FixedAsyncParsers[tdu.Exponent][tdu.Index](tdu, connection, requestSequence));
|
||||
}
|
||||
else if (tdu.Class == TDUClass.Dynamic)
|
||||
else if (tdu.Class == TduClass.Dynamic)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, DynamicAsyncParsers[tdu.Index](tdu, connection, requestSequence));
|
||||
}
|
||||
else if (tdu.Class == TDUClass.Typed)
|
||||
else if (tdu.Class == TduClass.Typed)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, TypedAsyncParsers[tdu.Index](tdu, connection, requestSequence));
|
||||
}
|
||||
@@ -243,17 +243,17 @@ public static class Codec
|
||||
}
|
||||
}
|
||||
|
||||
public static (uint, object) ParseSync(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static (uint, object) ParseSync(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
if (tdu.Class == TDUClass.Fixed)
|
||||
if (tdu.Class == TduClass.Fixed)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, FixedParsers[tdu.Exponent][tdu.Index](tdu, warehouse));
|
||||
}
|
||||
else if (tdu.Class == TDUClass.Dynamic)
|
||||
else if (tdu.Class == TduClass.Dynamic)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, DynamicParsers[tdu.Index](tdu, warehouse));
|
||||
}
|
||||
else if (tdu.Class == TDUClass.Typed)
|
||||
else if (tdu.Class == TduClass.Typed)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, TypedParsers[tdu.Index](tdu, warehouse));
|
||||
}
|
||||
@@ -266,21 +266,21 @@ public static class Codec
|
||||
|
||||
public static (uint, object) ParseSync(byte[] data, uint offset, Warehouse warehouse)
|
||||
{
|
||||
var tdu = ParsedTDU.Parse(data, offset, (uint)data.Length);
|
||||
var tdu = ParsedTdu.Parse(data, offset, (uint)data.Length);
|
||||
|
||||
if (tdu.Class == TDUClass.Invalid)
|
||||
if (tdu.Class == TduClass.Invalid)
|
||||
throw new NullReferenceException("DataType can't be parsed.");
|
||||
|
||||
|
||||
if (tdu.Class == TDUClass.Fixed)
|
||||
if (tdu.Class == TduClass.Fixed)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, FixedParsers[tdu.Exponent][tdu.Index](tdu, warehouse));
|
||||
}
|
||||
else if (tdu.Class == TDUClass.Dynamic)
|
||||
else if (tdu.Class == TduClass.Dynamic)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, DynamicParsers[tdu.Index](tdu, warehouse));
|
||||
}
|
||||
else if (tdu.Class == TDUClass.Typed)
|
||||
else if (tdu.Class == TduClass.Typed)
|
||||
{
|
||||
return ((uint)tdu.TotalLength, TypedParsers[tdu.Index](tdu, warehouse));
|
||||
}
|
||||
@@ -307,7 +307,7 @@ public static class Codec
|
||||
return false;
|
||||
}
|
||||
|
||||
public delegate TDU Composer(object value, Warehouse warehouse, EpConnection connection);
|
||||
public delegate Tdu Composer(object value, Warehouse warehouse, EpConnection connection);
|
||||
|
||||
public static Dictionary<Type, Composer> Composers = new Dictionary<Type, Composer>()
|
||||
{
|
||||
@@ -347,7 +347,7 @@ public static class Codec
|
||||
//[typeof(List<byte?>)] = DataSerializer.RawDataComposerFromList,
|
||||
[typeof(string)] = DataSerializer.StringComposer,
|
||||
[typeof(ResourceLink)] = DataSerializer.ResourceLinkComposer,
|
||||
[typeof(UUID)] = DataSerializer.UUIDComposer,
|
||||
[typeof(Uuid)] = DataSerializer.UUIDComposer,
|
||||
// Special
|
||||
[typeof(object[])] = DataSerializer.ListComposer,
|
||||
[typeof(List<object>)] = DataSerializer.ListComposer,
|
||||
@@ -381,11 +381,11 @@ public static class Codec
|
||||
};
|
||||
|
||||
|
||||
internal static TDU
|
||||
internal static Tdu
|
||||
ComposeInternal(object valueOrSource, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if (valueOrSource == null)
|
||||
return new TDU(TDUIdentifier.Null, null, 0);
|
||||
return new Tdu(TduIdentifier.Null, null, 0);
|
||||
|
||||
var type = valueOrSource.GetType();
|
||||
|
||||
@@ -412,7 +412,7 @@ public static class Codec
|
||||
valueOrSource = ((IUserType)valueOrSource).Get();
|
||||
|
||||
if (valueOrSource == null)
|
||||
return new TDU(TDUIdentifier.Null, null, 0);
|
||||
return new Tdu(TduIdentifier.Null, null, 0);
|
||||
|
||||
|
||||
type = valueOrSource.GetType();
|
||||
@@ -488,7 +488,7 @@ public static class Codec
|
||||
|
||||
}
|
||||
|
||||
return new TDU(TDUIdentifier.Null, null, 0);
|
||||
return new Tdu(TduIdentifier.Null, null, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -813,9 +813,9 @@ public static class DC // Data Converter
|
||||
return ar.ToArray();
|
||||
}
|
||||
|
||||
public static UUID GetUUID(this byte[] data, uint offset)
|
||||
public static Uuid GetUUID(this byte[] data, uint offset)
|
||||
{
|
||||
return new UUID(data, offset);
|
||||
return new Uuid(data, offset);
|
||||
}
|
||||
|
||||
//public static Guid GetGuid(this byte[] data, uint offset)
|
||||
|
||||
@@ -17,246 +17,246 @@ namespace Esiur.Data;
|
||||
|
||||
public static class DataDeserializer
|
||||
{
|
||||
public static object NullParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static object NullParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static object NullParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object NullParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static object BooleanTrueParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static object BooleanTrueParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static object BooleanTrueParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object BooleanTrueParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static object BooleanFalseParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static object BooleanFalseParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static object BooleanFalseParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object BooleanFalseParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static object NotModifiedParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static object NotModifiedParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return NotModified.Default;
|
||||
}
|
||||
|
||||
public static object NotModifiedParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object NotModifiedParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return NotModified.Default;
|
||||
}
|
||||
|
||||
public static object UInt8ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static object UInt8ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return tdu.Data[tdu.Offset];
|
||||
}
|
||||
public static object UInt8Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object UInt8Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return tdu.Data[tdu.Offset];
|
||||
}
|
||||
|
||||
public static object Int8ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static object Int8ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return (sbyte)tdu.Data[tdu.Offset];
|
||||
}
|
||||
public static object Int8Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object Int8Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return (sbyte)tdu.Data[tdu.Offset];
|
||||
}
|
||||
|
||||
public static unsafe object Char16ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object Char16ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(char*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Char16Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object Char16Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(char*)ptr;
|
||||
}
|
||||
|
||||
public static object Char8ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static object Char8ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return (char)tdu.Data[tdu.Offset];
|
||||
}
|
||||
|
||||
public static object Char8Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object Char8Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return (char)tdu.Data[tdu.Offset];
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object Int16ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object Int16ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(short*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Int16Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object Int16Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(short*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object UInt16ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object UInt16ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(ushort*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object UInt16Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object UInt16Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(ushort*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Int32ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object Int32ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(int*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Int32Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object Int32Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(int*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object UInt32ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object UInt32ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(uint*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object UInt32Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object UInt32Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(uint*)ptr;
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object Float32ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object Float32ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(float*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Float32Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object Float32Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(float*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Float64ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object Float64ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(double*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Float64Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object Float64Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(double*)ptr;
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object Decimal128ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object Decimal128ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(decimal*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Decimal128Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object Decimal128Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(decimal*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object UUIDParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object UUIDParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new UUID(tdu.Data, tdu.Offset);
|
||||
return new Uuid(tdu.Data, tdu.Offset);
|
||||
}
|
||||
|
||||
public static unsafe object UUIDParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object UUIDParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return new UUID(tdu.Data, tdu.Offset);
|
||||
return new Uuid(tdu.Data, tdu.Offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static unsafe object Int128ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object Int128ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr1 = &tdu.Data[tdu.Offset])
|
||||
fixed (byte* ptr2 = &tdu.Data[tdu.Offset + 8])
|
||||
return new Int128(*(ulong*)ptr1, *(ulong*)ptr2);
|
||||
}
|
||||
|
||||
public static unsafe object Int128Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object Int128Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr1 = &tdu.Data[tdu.Offset])
|
||||
fixed (byte* ptr2 = &tdu.Data[tdu.Offset + 8])
|
||||
return new Int128(*(ulong*)ptr1, *(ulong*)ptr2);
|
||||
}
|
||||
|
||||
public static unsafe object UInt128ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object UInt128ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr1 = &tdu.Data[tdu.Offset])
|
||||
fixed (byte* ptr2 = &tdu.Data[tdu.Offset + 8])
|
||||
return new UInt128(*(ulong*)ptr1, *(ulong*)ptr2);
|
||||
}
|
||||
|
||||
public static unsafe object UInt128Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object UInt128Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr1 = &tdu.Data[tdu.Offset])
|
||||
fixed (byte* ptr2 = &tdu.Data[tdu.Offset + 8])
|
||||
return new UInt128(*(ulong*)ptr1, *(ulong*)ptr2);
|
||||
}
|
||||
|
||||
public static unsafe object Int64ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object Int64ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(long*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object Int64Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object Int64Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(long*)ptr;
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object UInt64ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object UInt64ParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(ulong*)ptr;
|
||||
}
|
||||
|
||||
public static unsafe object UInt64Parser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object UInt64Parser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return *(ulong*)ptr;
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object DateTimeParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object DateTimeParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return new DateTime(*(long*)ptr, DateTimeKind.Utc);
|
||||
|
||||
}
|
||||
public static unsafe object DateTimeParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object DateTimeParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return new DateTime(*(long*)ptr, DateTimeKind.Utc);
|
||||
@@ -264,7 +264,7 @@ public static class DataDeserializer
|
||||
}
|
||||
|
||||
|
||||
public static object ResourceLinkParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static object ResourceLinkParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var link = tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
|
||||
if (connection == null)
|
||||
@@ -277,13 +277,13 @@ public static class DataDeserializer
|
||||
}
|
||||
}
|
||||
|
||||
public static object ResourceLinkParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object ResourceLinkParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
var link = tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
|
||||
return new ResourceLink(link);
|
||||
}
|
||||
|
||||
public static unsafe object ResourceParser8Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object ResourceParser8Async(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
if (connection == null)
|
||||
return new ResourceId(false, tdu.Data[tdu.Offset]);
|
||||
@@ -291,12 +291,12 @@ public static class DataDeserializer
|
||||
return connection.Fetch(tdu.Data[tdu.Offset], requestSequence);
|
||||
}
|
||||
|
||||
public static unsafe object ResourceParser8(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object ResourceParser8(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return new ResourceId(false, tdu.Data[tdu.Offset]);
|
||||
}
|
||||
|
||||
public static unsafe object LocalResourceParser8Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object LocalResourceParser8Async(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
if (connection == null)
|
||||
return new ResourceId(true, tdu.Data[tdu.Offset]);
|
||||
@@ -304,12 +304,12 @@ public static class DataDeserializer
|
||||
return connection.Instance.Warehouse.GetById(tdu.Data[tdu.Offset]);
|
||||
}
|
||||
|
||||
public static unsafe object LocalResourceParser8(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object LocalResourceParser8(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return new ResourceId(true, tdu.Data[tdu.Offset]);
|
||||
}
|
||||
|
||||
public static unsafe object ResourceParser16Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object ResourceParser16Async(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
if (connection == null)
|
||||
@@ -318,14 +318,14 @@ public static class DataDeserializer
|
||||
return connection.Fetch(*(ushort*)ptr, requestSequence);
|
||||
}
|
||||
|
||||
public static unsafe object ResourceParser16(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object ResourceParser16(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return new ResourceId(false, *(ushort*)ptr);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object LocalResourceParser16Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object LocalResourceParser16Async(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
if (connection == null)
|
||||
@@ -334,13 +334,13 @@ public static class DataDeserializer
|
||||
return connection.Instance.Warehouse.GetById(*(ushort*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe object LocalResourceParser16(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object LocalResourceParser16(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return new ResourceId(true, *(ushort*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe object ResourceParser32Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object ResourceParser32Async(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
if (connection == null)
|
||||
@@ -349,14 +349,14 @@ public static class DataDeserializer
|
||||
return connection.Fetch(*(uint*)ptr, requestSequence);
|
||||
}
|
||||
|
||||
public static unsafe object ResourceParser32(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object ResourceParser32(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return new ResourceId(false, *(uint*)ptr);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object LocalResourceParser32Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object LocalResourceParser32Async(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
if (connection == null)
|
||||
@@ -365,35 +365,35 @@ public static class DataDeserializer
|
||||
return connection.Instance.Warehouse.GetById(*(uint*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe object LocalResourceParser32(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object LocalResourceParser32(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
fixed (byte* ptr = &tdu.Data[tdu.Offset])
|
||||
return new ResourceId(true, *(uint*)ptr);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object RawDataParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object RawDataParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return tdu.Data.Clip(tdu.Offset, (uint)tdu.ContentLength);
|
||||
}
|
||||
|
||||
public static unsafe object RawDataParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object RawDataParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return tdu.Data.Clip(tdu.Offset, (uint)tdu.ContentLength);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object StringParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object StringParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
|
||||
}
|
||||
|
||||
public static unsafe object StringParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object StringParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
return tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
|
||||
}
|
||||
|
||||
public static unsafe object RecordParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object RecordParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var typeId = tdu.Metadata.GetUUID(0);
|
||||
var typeDef = connection.Instance.Warehouse.GetTypeDefById(typeId,
|
||||
@@ -403,8 +403,8 @@ public static class DataDeserializer
|
||||
|
||||
var list = new AsyncBag<object>();
|
||||
|
||||
ParsedTDU current;
|
||||
ParsedTDU? previous = null;
|
||||
ParsedTdu current;
|
||||
ParsedTdu? previous = null;
|
||||
|
||||
var offset = tdu.Offset;
|
||||
var length = tdu.ContentLength;
|
||||
@@ -414,22 +414,22 @@ public static class DataDeserializer
|
||||
{
|
||||
for (var i = 0; i < typeDef.Properties.Length; i++)
|
||||
{
|
||||
current = ParsedTDU.Parse(tdu.Data, offset, ends);
|
||||
current = ParsedTdu.Parse(tdu.Data, offset, ends);
|
||||
|
||||
if (current.Class == TDUClass.Invalid)
|
||||
if (current.Class == TduClass.Invalid)
|
||||
throw new Exception("Unknown type.");
|
||||
|
||||
|
||||
if (current.Identifier == TDUIdentifier.TypeContinuation)
|
||||
if (current.Identifier == TduIdentifier.TypeContinuation)
|
||||
{
|
||||
current.Class = previous.Value.Class;
|
||||
current.Identifier = previous.Value.Identifier;
|
||||
current.Metadata = previous.Value.Metadata;
|
||||
}
|
||||
else if (current.Identifier == TDUIdentifier.TypeOfTarget)
|
||||
else if (current.Identifier == TduIdentifier.TypeOfTarget)
|
||||
{
|
||||
var (idf, mt) = typeDef.Properties[i].ValueType.GetMetadata();
|
||||
current.Class = TDUClass.Typed;
|
||||
current.Class = TduClass.Typed;
|
||||
current.Identifier = idf;
|
||||
current.Metadata = mt;
|
||||
current.Index = (int)idf & 0x7;
|
||||
@@ -515,7 +515,7 @@ public static class DataDeserializer
|
||||
}
|
||||
|
||||
|
||||
public static unsafe object RecordParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object RecordParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
var typeId = tdu.Metadata.GetUUID(0);
|
||||
var typeDef = warehouse.GetTypeDefById(typeId, TypeDefKind.Record);
|
||||
@@ -529,8 +529,8 @@ public static class DataDeserializer
|
||||
|
||||
var list = new List<object>();
|
||||
|
||||
ParsedTDU current;
|
||||
ParsedTDU? previous = null;
|
||||
ParsedTdu current;
|
||||
ParsedTdu? previous = null;
|
||||
|
||||
var offset = tdu.Offset;
|
||||
var length = tdu.ContentLength;
|
||||
@@ -539,22 +539,22 @@ public static class DataDeserializer
|
||||
|
||||
for (var i = 0; i < typeDef.Properties.Length; i++)
|
||||
{
|
||||
current = ParsedTDU.Parse(tdu.Data, offset, ends);
|
||||
current = ParsedTdu.Parse(tdu.Data, offset, ends);
|
||||
|
||||
if (current.Class == TDUClass.Invalid)
|
||||
if (current.Class == TduClass.Invalid)
|
||||
throw new Exception("Unknown type.");
|
||||
|
||||
|
||||
if (current.Identifier == TDUIdentifier.TypeContinuation)
|
||||
if (current.Identifier == TduIdentifier.TypeContinuation)
|
||||
{
|
||||
current.Class = previous.Value.Class;
|
||||
current.Identifier = previous.Value.Identifier;
|
||||
current.Metadata = previous.Value.Metadata;
|
||||
}
|
||||
else if (current.Identifier == TDUIdentifier.TypeOfTarget)
|
||||
else if (current.Identifier == TduIdentifier.TypeOfTarget)
|
||||
{
|
||||
var (idf, mt) = typeDef.Properties[i].ValueType.GetMetadata();
|
||||
current.Class = TDUClass.Typed;
|
||||
current.Class = TduClass.Typed;
|
||||
current.Identifier = idf;
|
||||
current.Metadata = mt;
|
||||
current.Index = (int)idf & 0x7;
|
||||
@@ -605,17 +605,17 @@ public static class DataDeserializer
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe object ConstantParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe object ConstantParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe object ConstantParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object ConstantParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply EnumParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static unsafe AsyncReply EnumParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
|
||||
var typeId = tdu.Metadata.GetUUID(0);
|
||||
@@ -643,7 +643,7 @@ public static class DataDeserializer
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe object EnumParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static unsafe object EnumParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
|
||||
var typeId = tdu.Metadata.GetUUID(0);
|
||||
@@ -664,7 +664,7 @@ public static class DataDeserializer
|
||||
}
|
||||
|
||||
|
||||
public static AsyncReply RecordListParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static AsyncReply RecordListParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var rt = new AsyncBag<IRecord>();
|
||||
|
||||
@@ -691,7 +691,7 @@ public static class DataDeserializer
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static object RecordListParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object RecordListParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
var rt = new List<IRecord>();
|
||||
|
||||
@@ -717,7 +717,7 @@ public static class DataDeserializer
|
||||
return rt.ToArray();
|
||||
}
|
||||
|
||||
public static AsyncReply ResourceListParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static AsyncReply ResourceListParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var rt = new AsyncBag<IResource>();
|
||||
|
||||
@@ -745,7 +745,7 @@ public static class DataDeserializer
|
||||
}
|
||||
|
||||
|
||||
public static object ResourceListParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object ResourceListParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
var rt = new List<IResource>();
|
||||
|
||||
@@ -771,7 +771,7 @@ public static class DataDeserializer
|
||||
return rt.ToArray();
|
||||
}
|
||||
|
||||
public static AsyncBag<object> ListParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static AsyncBag<object> ListParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
//var rt = new AsyncBag<object>();
|
||||
|
||||
@@ -806,8 +806,8 @@ public static class DataDeserializer
|
||||
|
||||
//var list = new List<object>();
|
||||
|
||||
ParsedTDU current;
|
||||
ParsedTDU? previous = null;
|
||||
ParsedTdu current;
|
||||
ParsedTdu? previous = null;
|
||||
|
||||
var offset = tdu.Offset;
|
||||
var length = tdu.ContentLength;
|
||||
@@ -815,13 +815,13 @@ public static class DataDeserializer
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
current = ParsedTDU.Parse(tdu.Data, offset, ends);
|
||||
current = ParsedTdu.Parse(tdu.Data, offset, ends);
|
||||
|
||||
if (current.Class == TDUClass.Invalid)
|
||||
if (current.Class == TduClass.Invalid)
|
||||
throw new Exception("Unknown type.");
|
||||
|
||||
|
||||
if (current.Identifier == TDUIdentifier.TypeContinuation)
|
||||
if (current.Identifier == TduIdentifier.TypeContinuation)
|
||||
{
|
||||
current.Class = previous.Value.Class;
|
||||
current.Identifier = previous.Value.Identifier;
|
||||
@@ -850,12 +850,12 @@ public static class DataDeserializer
|
||||
|
||||
}
|
||||
|
||||
public static object ListParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object ListParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
var list = new List<object>();
|
||||
|
||||
ParsedTDU current;
|
||||
ParsedTDU? previous = null;
|
||||
ParsedTdu current;
|
||||
ParsedTdu? previous = null;
|
||||
|
||||
var offset = tdu.Offset;
|
||||
var length = tdu.ContentLength;
|
||||
@@ -863,13 +863,13 @@ public static class DataDeserializer
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
current = ParsedTDU.Parse(tdu.Data, offset, ends);
|
||||
current = ParsedTdu.Parse(tdu.Data, offset, ends);
|
||||
|
||||
if (current.Class == TDUClass.Invalid)
|
||||
if (current.Class == TduClass.Invalid)
|
||||
throw new Exception("Unknown type.");
|
||||
|
||||
|
||||
if (current.Identifier == TDUIdentifier.TypeContinuation)
|
||||
if (current.Identifier == TduIdentifier.TypeContinuation)
|
||||
{
|
||||
current.Class = previous.Value.Class;
|
||||
current.Identifier = previous.Value.Identifier;
|
||||
@@ -923,25 +923,25 @@ public static class DataDeserializer
|
||||
}
|
||||
|
||||
|
||||
public static AsyncReply TypedMapParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static AsyncReply TypedMapParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
|
||||
var rt = new AsyncReply();
|
||||
|
||||
// get key type
|
||||
|
||||
var (keyCs, keysTru) = TRU.Parse(tdu.Metadata, 0);
|
||||
var (valueCs, valuesTru) = TRU.Parse(tdu.Metadata, keyCs);
|
||||
var (keyCs, keysTru) = Tru.Parse(tdu.Metadata, 0);
|
||||
var (valueCs, valuesTru) = Tru.Parse(tdu.Metadata, keyCs);
|
||||
|
||||
var map = (IMap)Activator.CreateInstance(typeof(Map<,>).MakeGenericType(
|
||||
keysTru.GetRuntimeType(connection.Instance.Warehouse),
|
||||
valuesTru.GetRuntimeType(connection.Instance.Warehouse)));
|
||||
|
||||
|
||||
var keysTdu = ParsedTDU.Parse(tdu.Data, tdu.Offset,
|
||||
var keysTdu = ParsedTdu.Parse(tdu.Data, tdu.Offset,
|
||||
(uint)(tdu.Offset + tdu.ContentLength));
|
||||
|
||||
var valuesTdu = ParsedTDU.Parse(tdu.Data,
|
||||
var valuesTdu = ParsedTdu.Parse(tdu.Data,
|
||||
(uint)(keysTdu.Offset + keysTdu.ContentLength),
|
||||
tdu.Ends);
|
||||
|
||||
@@ -1011,29 +1011,29 @@ public static class DataDeserializer
|
||||
|
||||
}
|
||||
|
||||
public static Array TypedArrayParser(ParsedTDU tdu, TRU tru, Warehouse warehouse)
|
||||
public static Array TypedArrayParser(ParsedTdu tdu, Tru tru, Warehouse warehouse)
|
||||
{
|
||||
switch (tru.Identifier)
|
||||
{
|
||||
case TRUIdentifier.Int32:
|
||||
case TruIdentifier.Int32:
|
||||
return GroupInt32Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength));
|
||||
case TRUIdentifier.Int64:
|
||||
case TruIdentifier.Int64:
|
||||
return GroupInt64Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength));
|
||||
case TRUIdentifier.Int16:
|
||||
case TruIdentifier.Int16:
|
||||
return GroupInt16Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength));
|
||||
case TRUIdentifier.UInt32:
|
||||
case TruIdentifier.UInt32:
|
||||
return GroupUInt32Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength));
|
||||
case TRUIdentifier.UInt64:
|
||||
case TruIdentifier.UInt64:
|
||||
return GroupUInt64Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength));
|
||||
case TRUIdentifier.UInt16:
|
||||
case TruIdentifier.UInt16:
|
||||
return GroupUInt16Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength));
|
||||
case TRUIdentifier.Enum:
|
||||
case TruIdentifier.Enum:
|
||||
|
||||
var enumType = tru.GetRuntimeType(warehouse);
|
||||
|
||||
@@ -1053,8 +1053,8 @@ public static class DataDeserializer
|
||||
|
||||
var list = new List<object>();
|
||||
|
||||
ParsedTDU current;
|
||||
ParsedTDU? previous = null;
|
||||
ParsedTdu current;
|
||||
ParsedTdu? previous = null;
|
||||
|
||||
var offset = tdu.Offset;
|
||||
var length = tdu.ContentLength;
|
||||
@@ -1062,22 +1062,22 @@ public static class DataDeserializer
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
current = ParsedTDU.Parse(tdu.Data, offset, ends);
|
||||
current = ParsedTdu.Parse(tdu.Data, offset, ends);
|
||||
|
||||
if (current.Class == TDUClass.Invalid)
|
||||
if (current.Class == TduClass.Invalid)
|
||||
throw new Exception("Unknown type.");
|
||||
|
||||
|
||||
if (current.Identifier == TDUIdentifier.TypeContinuation)
|
||||
if (current.Identifier == TduIdentifier.TypeContinuation)
|
||||
{
|
||||
current.Class = previous.Value.Class;
|
||||
current.Identifier = previous.Value.Identifier;
|
||||
current.Metadata = previous.Value.Metadata;
|
||||
}
|
||||
else if (current.Identifier == TDUIdentifier.TypeOfTarget)
|
||||
else if (current.Identifier == TduIdentifier.TypeOfTarget)
|
||||
{
|
||||
var (idf, mt) = tru.GetMetadata();
|
||||
current.Class = TDUClass.Typed;
|
||||
current.Class = TduClass.Typed;
|
||||
current.Identifier = idf;
|
||||
current.Metadata = mt;
|
||||
current.Index = (int)idf & 0x7;
|
||||
@@ -1107,21 +1107,21 @@ public static class DataDeserializer
|
||||
|
||||
}
|
||||
|
||||
public static object TypedMapParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object TypedMapParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
// get key type
|
||||
|
||||
var (keyCs, keysTru) = TRU.Parse(tdu.Metadata, 0);
|
||||
var (valueCs, valuesTru) = TRU.Parse(tdu.Metadata, keyCs);
|
||||
var (keyCs, keysTru) = Tru.Parse(tdu.Metadata, 0);
|
||||
var (valueCs, valuesTru) = Tru.Parse(tdu.Metadata, keyCs);
|
||||
|
||||
var map = (IMap)Activator.CreateInstance(typeof(Map<,>).MakeGenericType(keysTru.GetRuntimeType(warehouse), valuesTru.GetRuntimeType(warehouse)));
|
||||
|
||||
|
||||
|
||||
var keysTdu = ParsedTDU.Parse(tdu.Data, tdu.Offset,
|
||||
var keysTdu = ParsedTdu.Parse(tdu.Data, tdu.Offset,
|
||||
(uint)(tdu.Offset + tdu.ContentLength));
|
||||
|
||||
var valuesTdu = ParsedTDU.Parse(tdu.Data,
|
||||
var valuesTdu = ParsedTdu.Parse(tdu.Data,
|
||||
(uint)(keysTdu.Offset + keysTdu.ContentLength),
|
||||
tdu.Ends);
|
||||
|
||||
@@ -1135,20 +1135,20 @@ public static class DataDeserializer
|
||||
|
||||
}
|
||||
|
||||
public static AsyncReply TupleParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static AsyncReply TupleParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
|
||||
var rt = new AsyncReply();
|
||||
|
||||
// var tupleSize = tdu.Metadata[0];
|
||||
|
||||
var trus = new List<TRU>();
|
||||
var trus = new List<Tru>();
|
||||
|
||||
uint mtOffset = 0;
|
||||
|
||||
while (mtOffset < tdu.Metadata.Length)
|
||||
{
|
||||
var (cs, tru) = TRU.Parse(tdu.Metadata, mtOffset);
|
||||
var (cs, tru) = Tru.Parse(tdu.Metadata, mtOffset);
|
||||
trus.Add(tru);
|
||||
mtOffset += cs;
|
||||
}
|
||||
@@ -1156,8 +1156,8 @@ public static class DataDeserializer
|
||||
var results = new AsyncBag<object>();
|
||||
var types = trus.Select(x => x.GetRuntimeType(connection.Instance.Warehouse)).ToArray();
|
||||
|
||||
ParsedTDU current;
|
||||
ParsedTDU? previous = null;
|
||||
ParsedTdu current;
|
||||
ParsedTdu? previous = null;
|
||||
|
||||
var offset = tdu.Offset;
|
||||
var length = tdu.ContentLength;
|
||||
@@ -1166,15 +1166,15 @@ public static class DataDeserializer
|
||||
|
||||
for (var i = 0; i < trus.Count; i++)
|
||||
{
|
||||
current = ParsedTDU.Parse(tdu.Data, offset, ends);
|
||||
current = ParsedTdu.Parse(tdu.Data, offset, ends);
|
||||
|
||||
if (current.Class == TDUClass.Invalid)
|
||||
if (current.Class == TduClass.Invalid)
|
||||
throw new Exception("Unknown type.");
|
||||
|
||||
if (current.Identifier == TDUIdentifier.TypeOfTarget)
|
||||
if (current.Identifier == TduIdentifier.TypeOfTarget)
|
||||
{
|
||||
var (idf, mt) = trus[i].GetMetadata();
|
||||
current.Class = TDUClass.Typed;
|
||||
current.Class = TduClass.Typed;
|
||||
current.Identifier = idf;
|
||||
current.Metadata = mt;
|
||||
current.Index = (int)idf & 0x7;
|
||||
@@ -1234,16 +1234,16 @@ public static class DataDeserializer
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static object TupleParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object TupleParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
var tupleSize = tdu.Metadata[0];
|
||||
|
||||
var trus = new List<TRU>();
|
||||
var trus = new List<Tru>();
|
||||
|
||||
uint mtOffset = 1;
|
||||
for (var i = 0; i < tupleSize; i++)
|
||||
{
|
||||
var (cs, tru) = TRU.Parse(tdu.Metadata, mtOffset);
|
||||
var (cs, tru) = Tru.Parse(tdu.Metadata, mtOffset);
|
||||
trus.Add(tru);
|
||||
mtOffset += cs;
|
||||
}
|
||||
@@ -1251,8 +1251,8 @@ public static class DataDeserializer
|
||||
var results = new List<object>();
|
||||
var types = trus.Select(x => x.GetRuntimeType(warehouse)).ToArray();
|
||||
|
||||
ParsedTDU current;
|
||||
ParsedTDU? previous = null;
|
||||
ParsedTdu current;
|
||||
ParsedTdu? previous = null;
|
||||
|
||||
var offset = tdu.Offset;
|
||||
var length = tdu.ContentLength;
|
||||
@@ -1261,15 +1261,15 @@ public static class DataDeserializer
|
||||
|
||||
for (var i = 0; i < tupleSize; i++)
|
||||
{
|
||||
current = ParsedTDU.Parse(tdu.Data, offset, ends);
|
||||
current = ParsedTdu.Parse(tdu.Data, offset, ends);
|
||||
|
||||
if (current.Class == TDUClass.Invalid)
|
||||
if (current.Class == TduClass.Invalid)
|
||||
throw new Exception("Unknown type.");
|
||||
|
||||
if (current.Identifier == TDUIdentifier.TypeOfTarget)
|
||||
if (current.Identifier == TduIdentifier.TypeOfTarget)
|
||||
{
|
||||
var (idf, mt) = trus[i].GetMetadata();
|
||||
current.Class = TDUClass.Typed;
|
||||
current.Class = TduClass.Typed;
|
||||
current.Identifier = idf;
|
||||
current.Metadata = mt;
|
||||
current.Index = (int)idf & 0x7;
|
||||
@@ -1325,30 +1325,30 @@ public static class DataDeserializer
|
||||
|
||||
}
|
||||
|
||||
public static AsyncReply TypedArrayParserAsync(ParsedTDU tdu, TRU tru, EpConnection connection, uint[] requestSequence)
|
||||
public static AsyncReply TypedArrayParserAsync(ParsedTdu tdu, Tru tru, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
switch (tru.Identifier)
|
||||
{
|
||||
case TRUIdentifier.Int32:
|
||||
case TruIdentifier.Int32:
|
||||
return new AsyncReply(GroupInt32Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength)));
|
||||
case TRUIdentifier.Int64:
|
||||
case TruIdentifier.Int64:
|
||||
return new AsyncReply(GroupInt64Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength)));
|
||||
case TRUIdentifier.Int16:
|
||||
case TruIdentifier.Int16:
|
||||
return new AsyncReply(GroupInt16Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength)));
|
||||
case TRUIdentifier.UInt32:
|
||||
case TruIdentifier.UInt32:
|
||||
return new AsyncReply(GroupUInt32Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength)));
|
||||
case TRUIdentifier.UInt64:
|
||||
case TruIdentifier.UInt64:
|
||||
return new AsyncReply(GroupUInt64Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength)));
|
||||
case TRUIdentifier.UInt16:
|
||||
case TruIdentifier.UInt16:
|
||||
return new AsyncReply(GroupUInt16Codec.Decode(tdu.Data.AsSpan(
|
||||
(int)tdu.Offset, (int)tdu.ContentLength)));
|
||||
|
||||
case TRUIdentifier.Enum:
|
||||
case TruIdentifier.Enum:
|
||||
var enumType = tru.GetRuntimeType(connection.Instance.Warehouse);
|
||||
|
||||
var rt = Array.CreateInstance(enumType, (int)tdu.ContentLength);
|
||||
@@ -1370,8 +1370,8 @@ public static class DataDeserializer
|
||||
|
||||
list.ArrayType = tru.GetRuntimeType(connection.Instance.Warehouse);
|
||||
|
||||
ParsedTDU current;
|
||||
ParsedTDU? previous = null;
|
||||
ParsedTdu current;
|
||||
ParsedTdu? previous = null;
|
||||
|
||||
var offset = tdu.Offset;
|
||||
var length = tdu.ContentLength;
|
||||
@@ -1379,22 +1379,22 @@ public static class DataDeserializer
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
current = ParsedTDU.Parse(tdu.Data, offset, ends);
|
||||
current = ParsedTdu.Parse(tdu.Data, offset, ends);
|
||||
|
||||
if (current.Class == TDUClass.Invalid)
|
||||
if (current.Class == TduClass.Invalid)
|
||||
throw new Exception("Unknown type.");
|
||||
|
||||
|
||||
if (current.Identifier == TDUIdentifier.TypeContinuation)
|
||||
if (current.Identifier == TduIdentifier.TypeContinuation)
|
||||
{
|
||||
current.Class = previous.Value.Class;
|
||||
current.Identifier = previous.Value.Identifier;
|
||||
current.Metadata = previous.Value.Metadata;
|
||||
}
|
||||
else if (current.Identifier == TDUIdentifier.TypeOfTarget)
|
||||
else if (current.Identifier == TduIdentifier.TypeOfTarget)
|
||||
{
|
||||
var (idf, mt) = tru.GetMetadata();
|
||||
current.Class = TDUClass.Typed;
|
||||
current.Class = TduClass.Typed;
|
||||
current.Identifier = idf;
|
||||
current.Metadata = mt;
|
||||
current.Index = (int)idf & 0x7;
|
||||
@@ -1421,10 +1421,10 @@ public static class DataDeserializer
|
||||
|
||||
}
|
||||
|
||||
public static AsyncReply TypedListParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
|
||||
public static AsyncReply TypedListParserAsync(ParsedTdu tdu, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
// get the type
|
||||
var (hdrCs, tru) = TRU.Parse(tdu.Metadata, 0);
|
||||
var (hdrCs, tru) = Tru.Parse(tdu.Metadata, 0);
|
||||
|
||||
return TypedArrayParserAsync(tdu, tru, connection, requestSequence);
|
||||
|
||||
@@ -1498,10 +1498,10 @@ public static class DataDeserializer
|
||||
//}
|
||||
}
|
||||
|
||||
public static object TypedListParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
public static object TypedListParser(ParsedTdu tdu, Warehouse warehouse)
|
||||
{
|
||||
// get the type
|
||||
var (hdrCs, tru) = TRU.Parse(tdu.Metadata, 0);
|
||||
var (hdrCs, tru) = Tru.Parse(tdu.Metadata, 0);
|
||||
|
||||
return TypedArrayParser(tdu, tru, warehouse);
|
||||
}
|
||||
@@ -1511,7 +1511,7 @@ public static class DataDeserializer
|
||||
var rt = new AsyncBag<PropertyValue>();
|
||||
|
||||
|
||||
ListParserAsync(new ParsedTDU() { Data = data, Offset = offset, ContentLength = length }
|
||||
ListParserAsync(new ParsedTdu() { Data = data, Offset = offset, ContentLength = length }
|
||||
, connection, requestSequence).Then(x =>
|
||||
{
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ public static class DataSerializer
|
||||
{
|
||||
public delegate byte[] Serializer(object value);
|
||||
|
||||
public static unsafe TDU Int32Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu Int32Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = (int)value;
|
||||
|
||||
if (v >= sbyte.MinValue && v <= sbyte.MaxValue)
|
||||
{
|
||||
return new TDU(TDUIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
return new Tdu(TduIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
}
|
||||
else if (v >= short.MinValue && v <= short.MaxValue)
|
||||
{
|
||||
@@ -32,7 +32,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((short*)ptr) = (short)v;
|
||||
|
||||
return new TDU(TDUIdentifier.Int16, rt, 2);
|
||||
return new Tdu(TduIdentifier.Int16, rt, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -40,18 +40,18 @@ public static class DataSerializer
|
||||
var rt = new byte[4];
|
||||
fixed (byte* ptr = rt)
|
||||
*((int*)ptr) = v;
|
||||
return new TDU(TDUIdentifier.Int32, rt, 4);
|
||||
return new Tdu(TduIdentifier.Int32, rt, 4);
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe TDU UInt32Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu UInt32Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = (uint)value;
|
||||
|
||||
if (v <= byte.MaxValue)
|
||||
{
|
||||
// Fits in 1 byte
|
||||
return new TDU(TDUIdentifier.UInt8, new byte[] { (byte)v }, 1);
|
||||
return new Tdu(TduIdentifier.UInt8, new byte[] { (byte)v }, 1);
|
||||
}
|
||||
else if (v <= ushort.MaxValue)
|
||||
{
|
||||
@@ -60,7 +60,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((ushort*)ptr) = (ushort)v;
|
||||
|
||||
return new TDU(TDUIdentifier.UInt16, rt, 2);
|
||||
return new Tdu(TduIdentifier.UInt16, rt, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -69,18 +69,18 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((uint*)ptr) = v;
|
||||
|
||||
return new TDU(TDUIdentifier.UInt32, rt, 4);
|
||||
return new Tdu(TduIdentifier.UInt32, rt, 4);
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe TDU Int16Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu Int16Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = (short)value;
|
||||
|
||||
if (v >= sbyte.MinValue && v <= sbyte.MaxValue)
|
||||
{
|
||||
// Fits in 1 byte
|
||||
return new TDU(TDUIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
return new Tdu(TduIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -89,18 +89,18 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((short*)ptr) = v;
|
||||
|
||||
return new TDU(TDUIdentifier.Int16, rt, 2);
|
||||
return new Tdu(TduIdentifier.Int16, rt, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe TDU UInt16Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu UInt16Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = (ushort)value;
|
||||
|
||||
if (v <= byte.MaxValue)
|
||||
{
|
||||
// Fits in 1 byte
|
||||
return new TDU(TDUIdentifier.UInt8, new byte[] { (byte)v }, 1);
|
||||
return new Tdu(TduIdentifier.UInt8, new byte[] { (byte)v }, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,19 +109,19 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((ushort*)ptr) = v;
|
||||
|
||||
return new TDU(TDUIdentifier.UInt16, rt, 2);
|
||||
return new Tdu(TduIdentifier.UInt16, rt, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static unsafe TDU Float32Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu Float32Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
float v = (float)value;
|
||||
|
||||
// Special IEEE-754 values
|
||||
if (float.IsNaN(v) || float.IsInfinity(v))
|
||||
{
|
||||
return new TDU(TDUIdentifier.Infinity, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Infinity, new byte[0], 0);
|
||||
}
|
||||
|
||||
// If v is an exact integer, prefer smallest signed width up to Int32
|
||||
@@ -130,7 +130,7 @@ public static class DataSerializer
|
||||
// Note: casts are safe because we check bounds first.
|
||||
if (v >= sbyte.MinValue && v <= sbyte.MaxValue)
|
||||
{
|
||||
return new TDU(TDUIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
return new Tdu(TduIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
}
|
||||
|
||||
if (v >= short.MinValue && v <= short.MaxValue)
|
||||
@@ -138,7 +138,7 @@ public static class DataSerializer
|
||||
var rt = new byte[2];
|
||||
fixed (byte* ptr = rt)
|
||||
*((short*)ptr) = (short)v;
|
||||
return new TDU(TDUIdentifier.Int16, rt, 2);
|
||||
return new Tdu(TduIdentifier.Int16, rt, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,26 +147,26 @@ public static class DataSerializer
|
||||
var rt = new byte[4];
|
||||
fixed (byte* ptr = rt)
|
||||
*((float*)ptr) = v;
|
||||
return new TDU(TDUIdentifier.Float32, rt, 4);
|
||||
return new Tdu(TduIdentifier.Float32, rt, 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public unsafe static TDU Float64Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public unsafe static Tdu Float64Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
double v = (double)value;
|
||||
|
||||
// Special IEEE-754 values
|
||||
if (double.IsNaN(v) || double.IsInfinity(v))
|
||||
{
|
||||
return new TDU(TDUIdentifier.Infinity, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Infinity, new byte[0], 0);
|
||||
}
|
||||
|
||||
// If v is an exact integer, choose the smallest signed width
|
||||
if (v == Math.Truncate(v))
|
||||
{
|
||||
if (v >= sbyte.MinValue && v <= sbyte.MaxValue)
|
||||
return new TDU(TDUIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
return new Tdu(TduIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
|
||||
if (v >= short.MinValue && v <= short.MaxValue)
|
||||
{
|
||||
@@ -175,7 +175,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((short*)ptr) = (short)v;
|
||||
|
||||
return new TDU(TDUIdentifier.Int16, rt, 2);
|
||||
return new Tdu(TduIdentifier.Int16, rt, 2);
|
||||
}
|
||||
|
||||
if (v >= int.MinValue && v <= int.MaxValue)
|
||||
@@ -185,7 +185,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((int*)ptr) = (int)v;
|
||||
|
||||
return new TDU(TDUIdentifier.Int32, rt, 4);
|
||||
return new Tdu(TduIdentifier.Int32, rt, 4);
|
||||
}
|
||||
|
||||
// If it's integral but outside Int64 range, fall through to Float64.
|
||||
@@ -200,7 +200,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((float*)ptr) = f;
|
||||
|
||||
return new TDU(TDUIdentifier.Float32, rt, 4);
|
||||
return new Tdu(TduIdentifier.Float32, rt, 4);
|
||||
}
|
||||
|
||||
// Default: Float64
|
||||
@@ -208,17 +208,17 @@ public static class DataSerializer
|
||||
var rt = new byte[8];
|
||||
fixed (byte* ptr = rt)
|
||||
*((double*)ptr) = v;
|
||||
return new TDU(TDUIdentifier.Float64, rt, 8);
|
||||
return new Tdu(TduIdentifier.Float64, rt, 8);
|
||||
}
|
||||
}
|
||||
public static unsafe TDU Int64Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu Int64Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = (long)value;
|
||||
|
||||
if (v >= sbyte.MinValue && v <= sbyte.MaxValue)
|
||||
{
|
||||
// Fits in 1 byte
|
||||
return new TDU(TDUIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
return new Tdu(TduIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
}
|
||||
else if (v >= short.MinValue && v <= short.MaxValue)
|
||||
{
|
||||
@@ -227,7 +227,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((short*)ptr) = (short)v;
|
||||
|
||||
return new TDU(TDUIdentifier.Int16, rt, 2);
|
||||
return new Tdu(TduIdentifier.Int16, rt, 2);
|
||||
}
|
||||
else if (v >= int.MinValue && v <= int.MaxValue)
|
||||
{
|
||||
@@ -236,7 +236,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((int*)ptr) = (int)v;
|
||||
|
||||
return new TDU(TDUIdentifier.Int32, rt, 4);
|
||||
return new Tdu(TduIdentifier.Int32, rt, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -245,18 +245,18 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((long*)ptr) = v;
|
||||
|
||||
return new TDU(TDUIdentifier.Int64, rt, 8);
|
||||
return new Tdu(TduIdentifier.Int64, rt, 8);
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe TDU UInt64Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu UInt64Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = (ulong)value;
|
||||
|
||||
if (v <= byte.MaxValue)
|
||||
{
|
||||
// Fits in 1 byte
|
||||
return new TDU(TDUIdentifier.UInt8, new byte[] { (byte)v }, 1);
|
||||
return new Tdu(TduIdentifier.UInt8, new byte[] { (byte)v }, 1);
|
||||
}
|
||||
else if (v <= ushort.MaxValue)
|
||||
{
|
||||
@@ -265,7 +265,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((ushort*)ptr) = (ushort)v;
|
||||
|
||||
return new TDU(TDUIdentifier.UInt16, rt, 2);
|
||||
return new Tdu(TduIdentifier.UInt16, rt, 2);
|
||||
}
|
||||
else if (v <= uint.MaxValue)
|
||||
{
|
||||
@@ -274,7 +274,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((uint*)ptr) = (uint)v;
|
||||
|
||||
return new TDU(TDUIdentifier.UInt32, rt, 4);
|
||||
return new Tdu(TduIdentifier.UInt32, rt, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -283,19 +283,19 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((ulong*)ptr) = v;
|
||||
|
||||
return new TDU(TDUIdentifier.UInt64, rt, 8);
|
||||
return new Tdu(TduIdentifier.UInt64, rt, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static unsafe TDU DateTimeComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu DateTimeComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = ((DateTime)value).ToUniversalTime().Ticks;
|
||||
var rt = new byte[8];
|
||||
fixed (byte* ptr = rt)
|
||||
*((long*)ptr) = v;
|
||||
|
||||
return new TDU(TDUIdentifier.DateTime, rt, 8);
|
||||
return new Tdu(TduIdentifier.DateTime, rt, 8);
|
||||
}
|
||||
|
||||
//public static unsafe TDU Decimal128Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
@@ -308,7 +308,7 @@ public static class DataSerializer
|
||||
// return new TDU(TDUIdentifier.Decimal128, rt, 16);
|
||||
//}
|
||||
|
||||
public static unsafe TDU Decimal128Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu Decimal128Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = (decimal)value;
|
||||
|
||||
@@ -320,27 +320,27 @@ public static class DataSerializer
|
||||
if (scale == 0)
|
||||
{
|
||||
if (v >= sbyte.MinValue && v <= sbyte.MaxValue)
|
||||
return new TDU(TDUIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
return new Tdu(TduIdentifier.Int8, new byte[] { (byte)(sbyte)v }, 1);
|
||||
|
||||
if (v >= short.MinValue && v <= short.MaxValue)
|
||||
{
|
||||
var b = new byte[2];
|
||||
BinaryPrimitives.WriteInt16LittleEndian(b, (short)v);
|
||||
return new TDU(TDUIdentifier.Int16, b, 2);
|
||||
return new Tdu(TduIdentifier.Int16, b, 2);
|
||||
}
|
||||
|
||||
if (v >= int.MinValue && v <= int.MaxValue)
|
||||
{
|
||||
var b = new byte[4];
|
||||
BinaryPrimitives.WriteInt32LittleEndian(b, (int)v);
|
||||
return new TDU(TDUIdentifier.Int32, b, 4);
|
||||
return new Tdu(TduIdentifier.Int32, b, 4);
|
||||
}
|
||||
|
||||
if (v >= long.MinValue && v <= long.MaxValue)
|
||||
{
|
||||
var b = new byte[8];
|
||||
BinaryPrimitives.WriteInt64LittleEndian(b, (long)v);
|
||||
return new TDU(TDUIdentifier.Int64, b, 8);
|
||||
return new Tdu(TduIdentifier.Int64, b, 8);
|
||||
}
|
||||
// else fall through (needs 96+ bits)
|
||||
}
|
||||
@@ -355,7 +355,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((float*)ptr) = f;
|
||||
|
||||
return new TDU(TDUIdentifier.Float32, rt, 4);
|
||||
return new Tdu(TduIdentifier.Float32, rt, 4);
|
||||
}
|
||||
|
||||
// Try exact Float64 (8 bytes)
|
||||
@@ -367,7 +367,7 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((double*)ptr) = d;
|
||||
|
||||
return new TDU(TDUIdentifier.Float64, rt, 8);
|
||||
return new Tdu(TduIdentifier.Float64, rt, 8);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -377,29 +377,29 @@ public static class DataSerializer
|
||||
fixed (byte* ptr = rt)
|
||||
*((decimal*)ptr) = v;
|
||||
|
||||
return new TDU(TDUIdentifier.Decimal128, rt, 16);
|
||||
return new Tdu(TduIdentifier.Decimal128, rt, 16);
|
||||
}
|
||||
}
|
||||
|
||||
public static TDU StringComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu StringComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var b = Encoding.UTF8.GetBytes((string)value);
|
||||
|
||||
return new TDU(TDUIdentifier.String, b, (uint)b.Length);
|
||||
return new Tdu(TduIdentifier.String, b, (uint)b.Length);
|
||||
}
|
||||
|
||||
public static TDU ResourceLinkComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu ResourceLinkComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var b = Encoding.UTF8.GetBytes((ResourceLink)value);
|
||||
|
||||
return new TDU(TDUIdentifier.ResourceLink, b, (uint)b.Length);
|
||||
return new Tdu(TduIdentifier.ResourceLink, b, (uint)b.Length);
|
||||
}
|
||||
|
||||
|
||||
public static TDU EnumComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu EnumComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return new TDU(TDUIdentifier.Null, null, 0);
|
||||
return new Tdu(TduIdentifier.Null, null, 0);
|
||||
|
||||
|
||||
//var warehouse = connection?.Instance?.Warehouse ?? connection?.Server?.Instance?.Warehouse;
|
||||
@@ -413,71 +413,71 @@ public static class DataSerializer
|
||||
var ct = typeDef.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
|
||||
|
||||
if (ct == null)
|
||||
return new TDU(TDUIdentifier.Null, null, 0);
|
||||
return new Tdu(TduIdentifier.Null, null, 0);
|
||||
|
||||
//return Codec.ComposeInternal(intVal, warehouse, connection);
|
||||
|
||||
return new TDU(TDUIdentifier.TypedEnum,
|
||||
return new Tdu(TduIdentifier.TypedEnum,
|
||||
new byte[] { ct.Index }, 1, typeDef.Id.Data);
|
||||
}
|
||||
|
||||
public static TDU UInt8Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu UInt8Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
return new TDU(TDUIdentifier.UInt8,
|
||||
return new Tdu(TduIdentifier.UInt8,
|
||||
new byte[] { (byte)value }, 1);
|
||||
}
|
||||
|
||||
public static TDU Int8Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu Int8Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
return new TDU(TDUIdentifier.Int8,
|
||||
return new Tdu(TduIdentifier.Int8,
|
||||
new byte[] { (byte)(sbyte)value }, 1);
|
||||
}
|
||||
|
||||
public static TDU Char8Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu Char8Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
return new TDU(TDUIdentifier.Int8,
|
||||
return new Tdu(TduIdentifier.Int8,
|
||||
new byte[] { (byte)(char)value }, 1);
|
||||
}
|
||||
|
||||
public static unsafe TDU Char16Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu Char16Composer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var v = (char)value;
|
||||
var rt = new byte[2];
|
||||
fixed (byte* ptr = rt)
|
||||
*((char*)ptr) = v;
|
||||
|
||||
return new TDU(TDUIdentifier.Char16, rt, 2);
|
||||
return new Tdu(TduIdentifier.Char16, rt, 2);
|
||||
|
||||
}
|
||||
|
||||
public static TDU BoolComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu BoolComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if ((bool)value)
|
||||
{
|
||||
return new TDU(TDUIdentifier.True, null, 0);
|
||||
return new Tdu(TduIdentifier.True, null, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TDU(TDUIdentifier.False, null, 0);
|
||||
return new Tdu(TduIdentifier.False, null, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static TDU NotModifiedComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu NotModifiedComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
return new TDU(TDUIdentifier.NotModified, null, 0);
|
||||
return new Tdu(TduIdentifier.NotModified, null, 0);
|
||||
}
|
||||
|
||||
public static TDU RawDataComposerFromArray(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu RawDataComposerFromArray(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var b = (byte[])value;
|
||||
return new TDU(TDUIdentifier.RawData, b, (uint)b.Length);
|
||||
return new Tdu(TduIdentifier.RawData, b, (uint)b.Length);
|
||||
}
|
||||
|
||||
public static TDU RawDataComposerFromList(dynamic value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu RawDataComposerFromList(dynamic value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var b = value as List<byte>;
|
||||
return new TDU(TDUIdentifier.RawData, b.ToArray(), (uint)b.Count);
|
||||
return new Tdu(TduIdentifier.RawData, b.ToArray(), (uint)b.Count);
|
||||
}
|
||||
|
||||
//public static (TDUIdentifier, byte[]) ListComposerFromArray(dynamic value, EpConnection connection)
|
||||
@@ -491,16 +491,16 @@ public static class DataSerializer
|
||||
// return (TDUIdentifier.List, rt.ToArray());
|
||||
//}
|
||||
|
||||
public static TDU ListComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu ListComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
|
||||
var composed = DynamicArrayComposer((IEnumerable)value, warehouse, connection);
|
||||
|
||||
if (composed == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 0);
|
||||
else
|
||||
{
|
||||
return new TDU(TDUIdentifier.List, composed, (uint)composed.Length);
|
||||
return new Tdu(TduIdentifier.List, composed, (uint)composed.Length);
|
||||
}
|
||||
|
||||
//if (value == null)
|
||||
@@ -534,7 +534,7 @@ public static class DataSerializer
|
||||
//return new TDU(TDUIdentifier.List, rt.ToArray(), (uint)rt.Count);
|
||||
}
|
||||
|
||||
public static byte[] TypedArrayComposer(IEnumerable value, TRU tru, Warehouse warehouse, EpConnection connection)
|
||||
public static byte[] TypedArrayComposer(IEnumerable value, Tru tru, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
byte[] composed;
|
||||
|
||||
@@ -542,31 +542,31 @@ public static class DataSerializer
|
||||
return null;
|
||||
|
||||
|
||||
if (tru.Identifier == TRUIdentifier.Int32)
|
||||
if (tru.Identifier == TruIdentifier.Int32)
|
||||
{
|
||||
composed = GroupInt32Codec.Encode((IList<int>)value);
|
||||
}
|
||||
else if (tru.Identifier == TRUIdentifier.Int64)
|
||||
else if (tru.Identifier == TruIdentifier.Int64)
|
||||
{
|
||||
composed = GroupInt64Codec.Encode((IList<long>)value);
|
||||
}
|
||||
else if (tru.Identifier == TRUIdentifier.Int16)
|
||||
else if (tru.Identifier == TruIdentifier.Int16)
|
||||
{
|
||||
composed = GroupInt16Codec.Encode((IList<short>)value);
|
||||
}
|
||||
else if (tru.Identifier == TRUIdentifier.UInt32)
|
||||
else if (tru.Identifier == TruIdentifier.UInt32)
|
||||
{
|
||||
composed = GroupUInt32Codec.Encode((IList<uint>)value);
|
||||
}
|
||||
else if (tru.Identifier == TRUIdentifier.UInt64)
|
||||
else if (tru.Identifier == TruIdentifier.UInt64)
|
||||
{
|
||||
composed = GroupUInt64Codec.Encode((IList<ulong>)value);
|
||||
}
|
||||
else if (tru.Identifier == TRUIdentifier.UInt16)
|
||||
else if (tru.Identifier == TruIdentifier.UInt16)
|
||||
{
|
||||
composed = GroupUInt16Codec.Encode((IList<ushort>)value);
|
||||
}
|
||||
else if (tru.Identifier == TRUIdentifier.Enum)
|
||||
else if (tru.Identifier == TruIdentifier.Enum)
|
||||
{
|
||||
|
||||
var rt = new List<byte>();
|
||||
@@ -587,21 +587,21 @@ public static class DataSerializer
|
||||
{
|
||||
var rt = new List<byte>();
|
||||
|
||||
TDU? previous = null;
|
||||
Tdu? previous = null;
|
||||
var isTyped = tru.IsTyped();
|
||||
|
||||
foreach (var i in value)
|
||||
{
|
||||
var tdu = Codec.ComposeInternal(i, warehouse, connection);
|
||||
|
||||
var currentTru = TRU.FromType(i?.GetType());
|
||||
var currentTru = Tru.FromType(i?.GetType());
|
||||
|
||||
if (isTyped && tru.Match(currentTru))
|
||||
{
|
||||
var d = tdu.Composed.Clip(tdu.ContentOffset,
|
||||
(uint)tdu.Composed.Length - tdu.ContentOffset);
|
||||
|
||||
var ntd = new TDU(TDUIdentifier.TypeOfTarget, d, (ulong)d.Length);
|
||||
var ntd = new Tdu(TduIdentifier.TypeOfTarget, d, (ulong)d.Length);
|
||||
rt.AddRange(ntd.Composed);
|
||||
}
|
||||
else
|
||||
@@ -611,7 +611,7 @@ public static class DataSerializer
|
||||
var d = tdu.Composed.Clip(tdu.ContentOffset,
|
||||
(uint)tdu.Composed.Length - tdu.ContentOffset);
|
||||
|
||||
var ntd = new TDU(TDUIdentifier.TypeContinuation, d, (ulong)d.Length);
|
||||
var ntd = new Tdu(TduIdentifier.TypeContinuation, d, (ulong)d.Length);
|
||||
rt.AddRange(ntd.Composed);
|
||||
}
|
||||
else
|
||||
@@ -630,18 +630,18 @@ public static class DataSerializer
|
||||
|
||||
}
|
||||
|
||||
public static TDU TypedListComposer(IEnumerable value, Type type, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu TypedListComposer(IEnumerable value, Type type, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var tru = TRU.FromType(type);
|
||||
var tru = Tru.FromType(type);
|
||||
|
||||
byte[] composed = TypedArrayComposer(value, tru, warehouse, connection);
|
||||
|
||||
if (composed == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 0);
|
||||
|
||||
var metadata = tru.Compose();
|
||||
|
||||
return new TDU(TDUIdentifier.TypedList, composed, (uint)composed.Length, metadata);
|
||||
return new Tdu(TduIdentifier.TypedList, composed, (uint)composed.Length, metadata);
|
||||
}
|
||||
|
||||
//public static byte[] PropertyValueComposer(PropertyValue propertyValue, EpConnection connection)//, bool includeAge = true)
|
||||
@@ -655,10 +655,10 @@ public static class DataSerializer
|
||||
// .ToArray();
|
||||
//}
|
||||
|
||||
public static TDU PropertyValueArrayComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu PropertyValueArrayComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 0);
|
||||
|
||||
var rt = new List<byte>();
|
||||
var ar = value as PropertyValue[];
|
||||
@@ -670,17 +670,17 @@ public static class DataSerializer
|
||||
rt.AddRange(Codec.Compose(pv.Value, warehouse, connection));
|
||||
}
|
||||
|
||||
return new TDU(TDUIdentifier.RawData, rt.ToArray(),
|
||||
return new Tdu(TduIdentifier.RawData, rt.ToArray(),
|
||||
(uint)rt.Count);
|
||||
}
|
||||
|
||||
public static TDU TypedMapComposer(object value, Type keyType, Type valueType, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu TypedMapComposer(object value, Type keyType, Type valueType, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 0);
|
||||
|
||||
var kt = TRU.FromType(keyType);
|
||||
var vt = TRU.FromType(valueType);
|
||||
var kt = Tru.FromType(keyType);
|
||||
var vt = Tru.FromType(valueType);
|
||||
|
||||
//var rt = new List<byte>();
|
||||
|
||||
@@ -700,26 +700,26 @@ public static class DataSerializer
|
||||
//foreach (var el in map.Serialize())
|
||||
// rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||
|
||||
var keysTdu = new TDU(TDUIdentifier.TypeOfTarget, compsedKeys, (uint)compsedKeys.Length).Composed;
|
||||
var valuesTdu = new TDU(TDUIdentifier.TypeOfTarget, compsedValues, (uint)compsedValues.Length).Composed;
|
||||
var keysTdu = new Tdu(TduIdentifier.TypeOfTarget, compsedKeys, (uint)compsedKeys.Length).Composed;
|
||||
var valuesTdu = new Tdu(TduIdentifier.TypeOfTarget, compsedValues, (uint)compsedValues.Length).Composed;
|
||||
|
||||
var all = DC.Combine(keysTdu, 0, (uint)keysTdu.Length, valuesTdu, 0, (uint)valuesTdu.Length);
|
||||
|
||||
return new TDU(TDUIdentifier.TypedMap, all, (uint)all.Length, metadata);
|
||||
return new Tdu(TduIdentifier.TypedMap, all, (uint)all.Length, metadata);
|
||||
|
||||
|
||||
|
||||
//return new TDU(TDUIdentifier.TypedMap, rt.ToArray(), (uint)rt.Count,
|
||||
// );
|
||||
}
|
||||
public static TDU TypedDictionaryComposer(object value, Type keyType, Type valueType, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu TypedDictionaryComposer(object value, Type keyType, Type valueType, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
|
||||
if (value == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 0);
|
||||
|
||||
var kt = TRU.FromType(keyType);
|
||||
var vt = TRU.FromType(valueType);
|
||||
var kt = Tru.FromType(keyType);
|
||||
var vt = Tru.FromType(valueType);
|
||||
|
||||
//var rt = new List<byte>();
|
||||
|
||||
@@ -739,12 +739,12 @@ public static class DataSerializer
|
||||
//foreach (var el in map.Serialize())
|
||||
// rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||
|
||||
var keysTdu = new TDU(TDUIdentifier.TypeOfTarget, compsedKeys, (uint)compsedKeys.Length).Composed;
|
||||
var valuesTdu = new TDU(TDUIdentifier.TypeOfTarget, compsedValues, (uint)compsedValues.Length).Composed;
|
||||
var keysTdu = new Tdu(TduIdentifier.TypeOfTarget, compsedKeys, (uint)compsedKeys.Length).Composed;
|
||||
var valuesTdu = new Tdu(TduIdentifier.TypeOfTarget, compsedValues, (uint)compsedValues.Length).Composed;
|
||||
|
||||
var all = DC.Combine(keysTdu, 0, (uint)keysTdu.Length, valuesTdu, 0, (uint)valuesTdu.Length);
|
||||
|
||||
return new TDU(TDUIdentifier.TypedMap, all, (uint)all.Length, metadata);
|
||||
return new Tdu(TduIdentifier.TypedMap, all, (uint)all.Length, metadata);
|
||||
|
||||
|
||||
//if (value == null)
|
||||
@@ -782,7 +782,7 @@ public static class DataSerializer
|
||||
|
||||
var rt = new List<byte>();
|
||||
|
||||
TDU? previous = null;
|
||||
Tdu? previous = null;
|
||||
|
||||
foreach (var i in value)
|
||||
{
|
||||
@@ -792,7 +792,7 @@ public static class DataSerializer
|
||||
var d = tdu.Composed.Clip(tdu.ContentOffset,
|
||||
(uint)tdu.Composed.Length - tdu.ContentOffset);
|
||||
|
||||
var ntd = new TDU(TDUIdentifier.TypeContinuation, d, (ulong)d.Length);
|
||||
var ntd = new Tdu(TduIdentifier.TypeContinuation, d, (ulong)d.Length);
|
||||
rt.AddRange(ntd.Composed);
|
||||
}
|
||||
else
|
||||
@@ -806,36 +806,36 @@ public static class DataSerializer
|
||||
return rt.ToArray();
|
||||
}
|
||||
|
||||
public static TDU ResourceListComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu ResourceListComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 0);
|
||||
|
||||
var composed = DynamicArrayComposer((IEnumerable)value, warehouse, connection);
|
||||
|
||||
return new TDU(TDUIdentifier.ResourceList, composed,
|
||||
return new Tdu(TduIdentifier.ResourceList, composed,
|
||||
(uint)composed.Length);
|
||||
}
|
||||
|
||||
public static TDU RecordListComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu RecordListComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 0);
|
||||
|
||||
var composed = DynamicArrayComposer((IEnumerable)value, warehouse, connection);
|
||||
|
||||
return new TDU(TDUIdentifier.RecordList,
|
||||
return new Tdu(TduIdentifier.RecordList,
|
||||
composed, (uint)composed.Length);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe TDU ResourceComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu ResourceComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var resource = (IResource)value;
|
||||
|
||||
if (resource.Instance == null || resource.Instance.IsDestroyed)
|
||||
{
|
||||
return new TDU(TDUIdentifier.Null, null, 0);
|
||||
return new Tdu(TduIdentifier.Null, null, 0);
|
||||
}
|
||||
|
||||
if (Codec.IsLocalResource(resource, connection))
|
||||
@@ -843,21 +843,21 @@ public static class DataSerializer
|
||||
var rid = (resource as EpResource).DistributedResourceInstanceId;
|
||||
|
||||
if (rid <= 0xFF)
|
||||
return new TDU(TDUIdentifier.LocalResource8, new byte[] { (byte)rid }, 1);
|
||||
return new Tdu(TduIdentifier.LocalResource8, new byte[] { (byte)rid }, 1);
|
||||
else if (rid <= 0xFFFF)
|
||||
{
|
||||
var rt = new byte[2];
|
||||
fixed (byte* ptr = rt)
|
||||
*((ushort*)ptr) = (ushort)rid;
|
||||
|
||||
return new TDU(TDUIdentifier.LocalResource16, rt, 2);
|
||||
return new Tdu(TduIdentifier.LocalResource16, rt, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
var rt = new byte[4];
|
||||
fixed (byte* ptr = rt)
|
||||
*((uint*)ptr) = rid;
|
||||
return new TDU(TDUIdentifier.LocalResource32, rt, 4);
|
||||
return new Tdu(TduIdentifier.LocalResource32, rt, 4);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -868,29 +868,29 @@ public static class DataSerializer
|
||||
var rid = resource.Instance.Id;
|
||||
|
||||
if (rid <= 0xFF)
|
||||
return new TDU(TDUIdentifier.RemoteResource8, new byte[] { (byte)rid }, 1);
|
||||
return new Tdu(TduIdentifier.RemoteResource8, new byte[] { (byte)rid }, 1);
|
||||
else if (rid <= 0xFFFF)
|
||||
{
|
||||
var rt = new byte[2];
|
||||
fixed (byte* ptr = rt)
|
||||
*((ushort*)ptr) = (ushort)rid;
|
||||
|
||||
return new TDU(TDUIdentifier.RemoteResource16, rt, 2);
|
||||
return new Tdu(TduIdentifier.RemoteResource16, rt, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
var rt = new byte[4];
|
||||
fixed (byte* ptr = rt)
|
||||
*((uint*)ptr) = rid;
|
||||
return new TDU(TDUIdentifier.RemoteResource32, rt, 4);
|
||||
return new Tdu(TduIdentifier.RemoteResource32, rt, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe TDU MapComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu MapComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 1);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 1);
|
||||
|
||||
var rt = new List<byte>();
|
||||
var map = (IMap)value;
|
||||
@@ -898,16 +898,16 @@ public static class DataSerializer
|
||||
foreach (var el in map.Serialize())
|
||||
rt.AddRange(Codec.Compose(el, warehouse, connection));
|
||||
|
||||
return new TDU(TDUIdentifier.Map, rt.ToArray(), (uint)rt.Count);
|
||||
return new Tdu(TduIdentifier.Map, rt.ToArray(), (uint)rt.Count);
|
||||
}
|
||||
|
||||
public static unsafe TDU UUIDComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu UUIDComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
return new TDU(TDUIdentifier.UUID, ((UUID)value).Data, 16);
|
||||
return new Tdu(TduIdentifier.UUID, ((Uuid)value).Data, 16);
|
||||
|
||||
}
|
||||
|
||||
public static unsafe TDU RecordComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static unsafe Tdu RecordComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
var rt = new List<byte>();
|
||||
var record = (IRecord)value;
|
||||
@@ -921,7 +921,7 @@ public static class DataSerializer
|
||||
|
||||
//if (propValue == null)
|
||||
// return TDU(TDUIdentifier.Null, null, 0);
|
||||
var tru = TRU.FromType(propValue?.GetType());
|
||||
var tru = Tru.FromType(propValue?.GetType());
|
||||
var tdu = Codec.ComposeInternal(propValue, warehouse, connection);
|
||||
|
||||
|
||||
@@ -930,14 +930,14 @@ public static class DataSerializer
|
||||
{
|
||||
// strip metadata
|
||||
var len = (uint)tdu.Composed.Length - tdu.ContentOffset;
|
||||
tdu = new TDU(TDUIdentifier.TypeOfTarget,
|
||||
tdu = new Tdu(TduIdentifier.TypeOfTarget,
|
||||
tdu.Composed.Clip(tdu.ContentOffset, len), len);
|
||||
}
|
||||
|
||||
rt.AddRange(tdu.Composed);
|
||||
}
|
||||
|
||||
return new TDU(TDUIdentifier.Record, rt.ToArray(),
|
||||
return new Tdu(TduIdentifier.Record, rt.ToArray(),
|
||||
(uint)rt.Count,
|
||||
typeDef.Id.Data);
|
||||
}
|
||||
@@ -958,14 +958,14 @@ public static class DataSerializer
|
||||
return rt.ToArray();
|
||||
}
|
||||
|
||||
public static TDU TupleComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
public static Tdu TupleComposer(object value, Warehouse warehouse, EpConnection connection)
|
||||
{
|
||||
if (value == null)
|
||||
return new TDU(TDUIdentifier.Null, new byte[0], 0);
|
||||
return new Tdu(TduIdentifier.Null, new byte[0], 0);
|
||||
|
||||
var fields = value.GetType().GetFields();
|
||||
var list = fields.Select(x => x.GetValue(value)).ToArray();
|
||||
var trus = fields.Select(x => TRU.FromType(x.FieldType)).ToArray();
|
||||
var trus = fields.Select(x => Tru.FromType(x.FieldType)).ToArray();
|
||||
|
||||
|
||||
var metadata = new List<byte>();
|
||||
@@ -982,21 +982,21 @@ public static class DataSerializer
|
||||
|
||||
var tdu = Codec.ComposeInternal(tupleValue, warehouse, connection);
|
||||
|
||||
var valueTru = TRU.FromType(tupleValue?.GetType());
|
||||
var valueTru = Tru.FromType(tupleValue?.GetType());
|
||||
|
||||
if (targetTru.IsTyped() &&
|
||||
targetTru.Match(valueTru))
|
||||
{
|
||||
// strip metadata
|
||||
var len = (uint)tdu.Composed.Length - tdu.ContentOffset;
|
||||
tdu = new TDU(TDUIdentifier.TypeOfTarget,
|
||||
tdu = new Tdu(TduIdentifier.TypeOfTarget,
|
||||
tdu.Composed.Clip(tdu.ContentOffset, len), len);
|
||||
}
|
||||
|
||||
rt.AddRange(tdu.Composed);
|
||||
}
|
||||
|
||||
return new TDU(TDUIdentifier.TypedTuple, rt.ToArray(),
|
||||
return new Tdu(TduIdentifier.TypedTuple, rt.ToArray(),
|
||||
(uint)rt.Count, metadata.ToArray());
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ using System.Text;
|
||||
|
||||
namespace Esiur.Data
|
||||
{
|
||||
public struct ParsedTDU
|
||||
public struct ParsedTdu
|
||||
{
|
||||
public TDUIdentifier Identifier;
|
||||
public TduIdentifier Identifier;
|
||||
public int Index;
|
||||
public TDUClass Class;
|
||||
public TduClass Class;
|
||||
public uint Offset;
|
||||
public ulong ContentLength;
|
||||
public byte[] Data;
|
||||
@@ -17,21 +17,21 @@ namespace Esiur.Data
|
||||
public byte[] Metadata;
|
||||
public uint Ends;
|
||||
|
||||
public static ParsedTDU Parse(byte[] data, uint offset, uint ends)
|
||||
public static ParsedTdu Parse(byte[] data, uint offset, uint ends)
|
||||
{
|
||||
|
||||
var h = data[offset++];
|
||||
|
||||
var cls = (TDUClass)(h >> 6);
|
||||
var cls = (TduClass)(h >> 6);
|
||||
|
||||
if (cls == TDUClass.Fixed)
|
||||
if (cls == TduClass.Fixed)
|
||||
{
|
||||
var exp = (h & 0x38) >> 3;
|
||||
|
||||
if (exp == 0)
|
||||
return new ParsedTDU()
|
||||
return new ParsedTdu()
|
||||
{
|
||||
Identifier = (TDUIdentifier)h,
|
||||
Identifier = (TduIdentifier)h,
|
||||
Data = data,
|
||||
Offset = offset,
|
||||
Class = cls,
|
||||
@@ -45,17 +45,17 @@ namespace Esiur.Data
|
||||
ulong cl = (ulong)(1 << (exp - 1));
|
||||
|
||||
if (ends - offset < cl)
|
||||
return new ParsedTDU()
|
||||
return new ParsedTdu()
|
||||
{
|
||||
Class = TDUClass.Invalid,
|
||||
Class = TduClass.Invalid,
|
||||
TotalLength = (cl - (ends - offset))
|
||||
};
|
||||
|
||||
//offset += (uint)cl;
|
||||
|
||||
return new ParsedTDU()
|
||||
return new ParsedTdu()
|
||||
{
|
||||
Identifier = (TDUIdentifier)h,
|
||||
Identifier = (TduIdentifier)h,
|
||||
Data = data,
|
||||
Offset = offset,
|
||||
Class = cls,
|
||||
@@ -66,14 +66,14 @@ namespace Esiur.Data
|
||||
Ends = ends
|
||||
};
|
||||
}
|
||||
else if (cls == TDUClass.Typed)
|
||||
else if (cls == TduClass.Typed)
|
||||
{
|
||||
ulong cll = (ulong)(h >> 3) & 0x7;
|
||||
|
||||
if (ends - offset < cll)
|
||||
return new ParsedTDU()
|
||||
return new ParsedTdu()
|
||||
{
|
||||
Class = TDUClass.Invalid,
|
||||
Class = TduClass.Invalid,
|
||||
TotalLength = (cll - (ends - offset))
|
||||
};
|
||||
|
||||
@@ -83,19 +83,19 @@ namespace Esiur.Data
|
||||
cl = cl << 8 | data[offset++];
|
||||
|
||||
if (ends - offset < cl)
|
||||
return new ParsedTDU()
|
||||
return new ParsedTdu()
|
||||
{
|
||||
TotalLength = (cl - (ends - offset)),
|
||||
Class = TDUClass.Invalid,
|
||||
Class = TduClass.Invalid,
|
||||
};
|
||||
|
||||
var metaData = DC.Clip(data, offset + 1, data[offset]);
|
||||
offset += data[offset] + (uint)1;
|
||||
|
||||
|
||||
return new ParsedTDU()
|
||||
return new ParsedTdu()
|
||||
{
|
||||
Identifier = (TDUIdentifier)(h & 0xC7),
|
||||
Identifier = (TduIdentifier)(h & 0xC7),
|
||||
Data = data,
|
||||
Offset = offset,
|
||||
Class = cls,
|
||||
@@ -111,9 +111,9 @@ namespace Esiur.Data
|
||||
ulong cll = (ulong)(h >> 3) & 0x7;
|
||||
|
||||
if (ends - offset < cll)
|
||||
return new ParsedTDU()
|
||||
return new ParsedTdu()
|
||||
{
|
||||
Class = TDUClass.Invalid,
|
||||
Class = TduClass.Invalid,
|
||||
TotalLength = (cll - (ends - offset))
|
||||
};
|
||||
|
||||
@@ -123,17 +123,17 @@ namespace Esiur.Data
|
||||
cl = cl << 8 | data[offset++];
|
||||
|
||||
if (ends - offset < cl)
|
||||
return new ParsedTDU()
|
||||
return new ParsedTdu()
|
||||
{
|
||||
Class = TDUClass.Invalid,
|
||||
Class = TduClass.Invalid,
|
||||
TotalLength = (cl - (ends - offset))
|
||||
};
|
||||
|
||||
|
||||
return
|
||||
new ParsedTDU()
|
||||
new ParsedTdu()
|
||||
{
|
||||
Identifier = (TDUIdentifier)(h & 0xC7),
|
||||
Identifier = (TduIdentifier)(h & 0xC7),
|
||||
Data = data,
|
||||
Offset = offset,
|
||||
Class = cls,
|
||||
|
||||
@@ -8,11 +8,11 @@ using static Esiur.Data.Codec;
|
||||
namespace Esiur.Data;
|
||||
|
||||
// Transmission Data Unit
|
||||
public struct TDU
|
||||
public struct Tdu
|
||||
{
|
||||
public TDUIdentifier Identifier;
|
||||
public TduIdentifier Identifier;
|
||||
//public int Index;
|
||||
public TDUClass Class;
|
||||
public TduClass Class;
|
||||
//public ulong ContentLength;
|
||||
|
||||
public byte[] Composed;
|
||||
@@ -52,35 +52,35 @@ public struct TDU
|
||||
|
||||
//private ulong TotalSize;
|
||||
|
||||
public TDU()
|
||||
public Tdu()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TDU(TDUIdentifier identifier)
|
||||
public Tdu(TduIdentifier identifier)
|
||||
{
|
||||
Identifier = identifier;
|
||||
Composed = new byte[0];
|
||||
}
|
||||
|
||||
public TDU(TDUIdentifier identifier,
|
||||
public Tdu(TduIdentifier identifier,
|
||||
byte[] data, ulong length, byte[] metadata = null)
|
||||
{
|
||||
Identifier = identifier;
|
||||
//Index = (byte)identifier & 0x7;
|
||||
Class = (TDUClass)((byte)identifier >> 6);
|
||||
Class = (TduClass)((byte)identifier >> 6);
|
||||
Metadata = metadata;
|
||||
|
||||
|
||||
if (Class == TDUClass.Fixed)
|
||||
if (Class == TduClass.Fixed)
|
||||
{
|
||||
if (length == 0)
|
||||
Composed = new byte[1] { (byte)identifier };
|
||||
else
|
||||
Composed = DC.Combine(new byte[] { (byte)Identifier }, 0, 1, data, 0, (uint)length);
|
||||
}
|
||||
else if (Class == TDUClass.Dynamic
|
||||
|| Class == TDUClass.Extension)
|
||||
else if (Class == TduClass.Dynamic
|
||||
|| Class == TduClass.Extension)
|
||||
{
|
||||
|
||||
if (length == 0)
|
||||
@@ -169,7 +169,7 @@ public struct TDU
|
||||
Buffer.BlockCopy(data, 0, Composed, 8, (int)length);
|
||||
}
|
||||
}
|
||||
else if (Class == TDUClass.Typed)
|
||||
else if (Class == TduClass.Typed)
|
||||
{
|
||||
if (metadata == null)
|
||||
throw new Exception("Metadata must be provided for types.");
|
||||
@@ -297,12 +297,12 @@ public struct TDU
|
||||
}
|
||||
|
||||
|
||||
public bool MatchType(TDU with)
|
||||
public bool MatchType(Tdu with)
|
||||
{
|
||||
if (Identifier != with.Identifier)
|
||||
return false;
|
||||
|
||||
if (Class != TDUClass.Typed || with.Class != TDUClass.Typed)
|
||||
if (Class != TduClass.Typed || with.Class != TduClass.Typed)
|
||||
return false;
|
||||
|
||||
if (!Metadata.SequenceEqual(with.Metadata))
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
|
||||
namespace Esiur.Data
|
||||
{
|
||||
public enum TDUClass
|
||||
public enum TduClass
|
||||
{
|
||||
Fixed = 0x0,
|
||||
Dynamic = 0x1,
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
|
||||
namespace Esiur.Data
|
||||
{
|
||||
public enum TDUIdentifier
|
||||
public enum TduIdentifier
|
||||
{
|
||||
Null = 0x0,
|
||||
False = 0x1,
|
||||
|
||||
@@ -14,54 +14,54 @@ using System.Text;
|
||||
|
||||
namespace Esiur.Data
|
||||
{
|
||||
public class TRU
|
||||
public class Tru
|
||||
{
|
||||
|
||||
static TRUIdentifier[] refTypes = new TRUIdentifier[]
|
||||
static TruIdentifier[] refTypes = new TruIdentifier[]
|
||||
{
|
||||
TRUIdentifier.Dynamic,
|
||||
TRUIdentifier.RawData,
|
||||
TRUIdentifier.String,
|
||||
TRUIdentifier.Resource,
|
||||
TRUIdentifier.Record,
|
||||
TRUIdentifier.Map,
|
||||
TRUIdentifier.List,
|
||||
TRUIdentifier.TypedList,
|
||||
TRUIdentifier.TypedMap,
|
||||
TRUIdentifier.Tuple2,
|
||||
TRUIdentifier.Tuple3,
|
||||
TRUIdentifier.Tuple4,
|
||||
TRUIdentifier.Tuple5,
|
||||
TRUIdentifier.Tuple6,
|
||||
TRUIdentifier.Tuple7,
|
||||
TRUIdentifier.TypedRecord,
|
||||
TRUIdentifier.TypedResource
|
||||
TruIdentifier.Dynamic,
|
||||
TruIdentifier.RawData,
|
||||
TruIdentifier.String,
|
||||
TruIdentifier.Resource,
|
||||
TruIdentifier.Record,
|
||||
TruIdentifier.Map,
|
||||
TruIdentifier.List,
|
||||
TruIdentifier.TypedList,
|
||||
TruIdentifier.TypedMap,
|
||||
TruIdentifier.Tuple2,
|
||||
TruIdentifier.Tuple3,
|
||||
TruIdentifier.Tuple4,
|
||||
TruIdentifier.Tuple5,
|
||||
TruIdentifier.Tuple6,
|
||||
TruIdentifier.Tuple7,
|
||||
TruIdentifier.TypedRecord,
|
||||
TruIdentifier.TypedResource
|
||||
};
|
||||
|
||||
static Map<TDUIdentifier, TRUIdentifier> typesMap = new Map<TDUIdentifier, TRUIdentifier>()
|
||||
static Map<TduIdentifier, TruIdentifier> typesMap = new Map<TduIdentifier, TruIdentifier>()
|
||||
{
|
||||
[TDUIdentifier.UInt8] = TRUIdentifier.UInt8,
|
||||
[TDUIdentifier.Int8] = TRUIdentifier.Int8,
|
||||
[TDUIdentifier.UInt16] = TRUIdentifier.UInt16,
|
||||
[TDUIdentifier.Int16] = TRUIdentifier.Int16,
|
||||
[TDUIdentifier.UInt32] = TRUIdentifier.UInt32,
|
||||
[TDUIdentifier.Int32] = TRUIdentifier.Int32,
|
||||
[TDUIdentifier.UInt64] = TRUIdentifier.UInt64,
|
||||
[TDUIdentifier.Int64] = TRUIdentifier.Int64,
|
||||
[TDUIdentifier.UInt128] = TRUIdentifier.UInt128,
|
||||
[TDUIdentifier.Int128] = TRUIdentifier.Int128,
|
||||
[TDUIdentifier.Char8] = TRUIdentifier.Char,
|
||||
[TDUIdentifier.DateTime] = TRUIdentifier.DateTime,
|
||||
[TDUIdentifier.Float32] = TRUIdentifier.Float32,
|
||||
[TDUIdentifier.Float64] = TRUIdentifier.Float64,
|
||||
[TDUIdentifier.Decimal128] = TRUIdentifier.Decimal,
|
||||
[TDUIdentifier.False] = TRUIdentifier.Bool,
|
||||
[TDUIdentifier.True] = TRUIdentifier.Bool,
|
||||
[TDUIdentifier.Map] = TRUIdentifier.Map,
|
||||
[TDUIdentifier.List] = TRUIdentifier.List,
|
||||
[TDUIdentifier.RawData] = TRUIdentifier.RawData,
|
||||
[TDUIdentifier.Record] = TRUIdentifier.Record,
|
||||
[TDUIdentifier.String] = TRUIdentifier.String,
|
||||
[TduIdentifier.UInt8] = TruIdentifier.UInt8,
|
||||
[TduIdentifier.Int8] = TruIdentifier.Int8,
|
||||
[TduIdentifier.UInt16] = TruIdentifier.UInt16,
|
||||
[TduIdentifier.Int16] = TruIdentifier.Int16,
|
||||
[TduIdentifier.UInt32] = TruIdentifier.UInt32,
|
||||
[TduIdentifier.Int32] = TruIdentifier.Int32,
|
||||
[TduIdentifier.UInt64] = TruIdentifier.UInt64,
|
||||
[TduIdentifier.Int64] = TruIdentifier.Int64,
|
||||
[TduIdentifier.UInt128] = TruIdentifier.UInt128,
|
||||
[TduIdentifier.Int128] = TruIdentifier.Int128,
|
||||
[TduIdentifier.Char8] = TruIdentifier.Char,
|
||||
[TduIdentifier.DateTime] = TruIdentifier.DateTime,
|
||||
[TduIdentifier.Float32] = TruIdentifier.Float32,
|
||||
[TduIdentifier.Float64] = TruIdentifier.Float64,
|
||||
[TduIdentifier.Decimal128] = TruIdentifier.Decimal,
|
||||
[TduIdentifier.False] = TruIdentifier.Bool,
|
||||
[TduIdentifier.True] = TruIdentifier.Bool,
|
||||
[TduIdentifier.Map] = TruIdentifier.Map,
|
||||
[TduIdentifier.List] = TruIdentifier.List,
|
||||
[TduIdentifier.RawData] = TruIdentifier.RawData,
|
||||
[TduIdentifier.Record] = TruIdentifier.Record,
|
||||
[TduIdentifier.String] = TruIdentifier.String,
|
||||
};
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Esiur.Data
|
||||
public Type? GetRuntimeType(Warehouse warehouse)
|
||||
{
|
||||
|
||||
if (Identifier == TRUIdentifier.TypedList)
|
||||
if (Identifier == TruIdentifier.TypedList)
|
||||
{
|
||||
var sub = SubTypes?[0].GetRuntimeType(warehouse);
|
||||
if (sub == null)
|
||||
@@ -139,7 +139,7 @@ namespace Esiur.Data
|
||||
|
||||
return rt;
|
||||
}
|
||||
else if (Identifier == TRUIdentifier.TypedMap)
|
||||
else if (Identifier == TruIdentifier.TypedMap)
|
||||
{
|
||||
var subs = SubTypes.Select(x => x.GetRuntimeType(warehouse)).ToArray();
|
||||
var rt = typeof(Map<,>).MakeGenericType(subs);
|
||||
@@ -148,59 +148,59 @@ namespace Esiur.Data
|
||||
|
||||
return Identifier switch
|
||||
{
|
||||
(TRUIdentifier.Void) => typeof(void),
|
||||
(TRUIdentifier.Dynamic) => typeof(object),
|
||||
(TRUIdentifier.Bool) => Nullable ? typeof(bool?) : typeof(bool),
|
||||
(TRUIdentifier.Char) => Nullable ? typeof(char?) : typeof(char),
|
||||
(TRUIdentifier.UInt8) => Nullable ? typeof(byte?) : typeof(byte),
|
||||
(TRUIdentifier.Int8) => Nullable ? typeof(sbyte?) : typeof(sbyte),
|
||||
(TRUIdentifier.Int16) => Nullable ? typeof(short?) : typeof(short),
|
||||
(TRUIdentifier.UInt16) => Nullable ? typeof(ushort?) : typeof(ushort),
|
||||
(TRUIdentifier.Int32) => Nullable ? typeof(int?) : typeof(int),
|
||||
(TRUIdentifier.UInt32) => Nullable ? typeof(uint?) : typeof(uint),
|
||||
(TRUIdentifier.Int64) => Nullable ? typeof(ulong?) : typeof(long),
|
||||
(TRUIdentifier.UInt64) => Nullable ? typeof(ulong?) : typeof(ulong),
|
||||
(TRUIdentifier.Float32) => Nullable ? typeof(float?) : typeof(float),
|
||||
(TRUIdentifier.Float64) => Nullable ? typeof(double?) : typeof(double),
|
||||
(TRUIdentifier.Decimal) => Nullable ? typeof(decimal?) : typeof(decimal),
|
||||
(TRUIdentifier.String) => typeof(string),
|
||||
(TRUIdentifier.DateTime) => Nullable ? typeof(DateTime?) : typeof(DateTime),
|
||||
(TRUIdentifier.Resource) => typeof(IResource),
|
||||
(TRUIdentifier.Record) => typeof(IRecord),
|
||||
(TRUIdentifier.TypedRecord) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Record)?.DefinedType,
|
||||
(TRUIdentifier.TypedResource) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Resource)?.DefinedType,
|
||||
(TRUIdentifier.Enum) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Enum)?.DefinedType,
|
||||
(TruIdentifier.Void) => typeof(void),
|
||||
(TruIdentifier.Dynamic) => typeof(object),
|
||||
(TruIdentifier.Bool) => Nullable ? typeof(bool?) : typeof(bool),
|
||||
(TruIdentifier.Char) => Nullable ? typeof(char?) : typeof(char),
|
||||
(TruIdentifier.UInt8) => Nullable ? typeof(byte?) : typeof(byte),
|
||||
(TruIdentifier.Int8) => Nullable ? typeof(sbyte?) : typeof(sbyte),
|
||||
(TruIdentifier.Int16) => Nullable ? typeof(short?) : typeof(short),
|
||||
(TruIdentifier.UInt16) => Nullable ? typeof(ushort?) : typeof(ushort),
|
||||
(TruIdentifier.Int32) => Nullable ? typeof(int?) : typeof(int),
|
||||
(TruIdentifier.UInt32) => Nullable ? typeof(uint?) : typeof(uint),
|
||||
(TruIdentifier.Int64) => Nullable ? typeof(ulong?) : typeof(long),
|
||||
(TruIdentifier.UInt64) => Nullable ? typeof(ulong?) : typeof(ulong),
|
||||
(TruIdentifier.Float32) => Nullable ? typeof(float?) : typeof(float),
|
||||
(TruIdentifier.Float64) => Nullable ? typeof(double?) : typeof(double),
|
||||
(TruIdentifier.Decimal) => Nullable ? typeof(decimal?) : typeof(decimal),
|
||||
(TruIdentifier.String) => typeof(string),
|
||||
(TruIdentifier.DateTime) => Nullable ? typeof(DateTime?) : typeof(DateTime),
|
||||
(TruIdentifier.Resource) => typeof(IResource),
|
||||
(TruIdentifier.Record) => typeof(IRecord),
|
||||
(TruIdentifier.TypedRecord) => warehouse.GetTypeDefById((Uuid)UUID!, TypeDefKind.Record)?.DefinedType,
|
||||
(TruIdentifier.TypedResource) => warehouse.GetTypeDefById((Uuid)UUID!, TypeDefKind.Resource)?.DefinedType,
|
||||
(TruIdentifier.Enum) => warehouse.GetTypeDefById((Uuid)UUID!, TypeDefKind.Enum)?.DefinedType,
|
||||
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public TRUIdentifier Identifier;
|
||||
public TruIdentifier Identifier;
|
||||
public bool Nullable;
|
||||
public UUID? UUID;
|
||||
public Uuid? UUID;
|
||||
//public RepresentationType? SubType1; // List + Map
|
||||
//public RepresentationType? SubType2; // Map
|
||||
//public RepresentationType? SubType3; // No types yet
|
||||
|
||||
public TRU[]? SubTypes = null;
|
||||
public Tru[]? SubTypes = null;
|
||||
|
||||
public TRU ToNullable()
|
||||
public Tru ToNullable()
|
||||
{
|
||||
return new TRU(Identifier, true, UUID, SubTypes);
|
||||
return new Tru(Identifier, true, UUID, SubTypes);
|
||||
}
|
||||
|
||||
public bool IsTyped()
|
||||
{
|
||||
if (Identifier == TRUIdentifier.TypedList && SubTypes[0].Identifier == TRUIdentifier.UInt8)
|
||||
if (Identifier == TruIdentifier.TypedList && SubTypes[0].Identifier == TruIdentifier.UInt8)
|
||||
return false;
|
||||
|
||||
if (Identifier == TRUIdentifier.TypedResource)
|
||||
if (Identifier == TruIdentifier.TypedResource)
|
||||
return false;
|
||||
|
||||
return (UUID != null) || (SubTypes != null && SubTypes.Length > 0);
|
||||
}
|
||||
|
||||
public bool Match(TRU other)
|
||||
public bool Match(Tru other)
|
||||
{
|
||||
//if (UUID == null && (SubTypes == null || SubTypes.Length == 0))
|
||||
// return false;
|
||||
@@ -224,19 +224,19 @@ namespace Esiur.Data
|
||||
}
|
||||
|
||||
|
||||
public (TDUIdentifier, byte[]) GetMetadata()
|
||||
public (TduIdentifier, byte[]) GetMetadata()
|
||||
{
|
||||
switch (Identifier)
|
||||
{
|
||||
case TRUIdentifier.TypedList:
|
||||
return (TDUIdentifier.TypedList, SubTypes[0].Compose());
|
||||
case TRUIdentifier.TypedRecord:
|
||||
return (TDUIdentifier.Record, UUID?.Data);
|
||||
case TRUIdentifier.TypedMap:
|
||||
return (TDUIdentifier.TypedMap,
|
||||
case TruIdentifier.TypedList:
|
||||
return (TduIdentifier.TypedList, SubTypes[0].Compose());
|
||||
case TruIdentifier.TypedRecord:
|
||||
return (TduIdentifier.Record, UUID?.Data);
|
||||
case TruIdentifier.TypedMap:
|
||||
return (TduIdentifier.TypedMap,
|
||||
SubTypes[0].Compose().Concat(SubTypes[1].Compose()).ToArray());
|
||||
case TRUIdentifier.Enum:
|
||||
return (TDUIdentifier.TypedEnum, UUID?.Data);
|
||||
case TruIdentifier.Enum:
|
||||
return (TduIdentifier.TypedEnum, UUID?.Data);
|
||||
|
||||
default:
|
||||
|
||||
@@ -267,12 +267,12 @@ namespace Esiur.Data
|
||||
// case TRUIdentifier. }
|
||||
//}
|
||||
|
||||
private static Dictionary<Type, TRU> _cache = new Dictionary<Type, TRU>();
|
||||
private static Dictionary<Type, Tru> _cache = new Dictionary<Type, Tru>();
|
||||
|
||||
public static TRU? FromType(Type type)
|
||||
public static Tru? FromType(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
return new TRU(TRUIdentifier.Void, true);
|
||||
return new Tru(TruIdentifier.Void, true);
|
||||
|
||||
if (_cache.ContainsKey(type))
|
||||
return _cache[type];
|
||||
@@ -287,33 +287,33 @@ namespace Esiur.Data
|
||||
nullable = true;
|
||||
}
|
||||
|
||||
TRU? tru = null;
|
||||
Tru? tru = null;
|
||||
|
||||
if (type == typeof(IResource))
|
||||
{
|
||||
return new TRU(TRUIdentifier.Resource, nullable);
|
||||
return new Tru(TruIdentifier.Resource, nullable);
|
||||
}
|
||||
else if (type == typeof(IRecord) || type == typeof(Record))
|
||||
{
|
||||
return new TRU(TRUIdentifier.Record, nullable);
|
||||
return new Tru(TruIdentifier.Record, nullable);
|
||||
}
|
||||
else if (type == typeof(Map<object, object>)
|
||||
|| type == typeof(Dictionary<object, object>))
|
||||
{
|
||||
return new TRU(TRUIdentifier.Map, nullable);
|
||||
return new Tru(TruIdentifier.Map, nullable);
|
||||
}
|
||||
else if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
{
|
||||
tru = new TRU(
|
||||
TRUIdentifier.TypedResource,
|
||||
tru = new Tru(
|
||||
TruIdentifier.TypedResource,
|
||||
nullable,
|
||||
TypeDef.GetTypeUUID(type)
|
||||
);
|
||||
}
|
||||
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
|
||||
{
|
||||
tru = new TRU(
|
||||
TRUIdentifier.TypedRecord,
|
||||
tru = new Tru(
|
||||
TruIdentifier.TypedRecord,
|
||||
nullable,
|
||||
TypeDef.GetTypeUUID(type)
|
||||
);
|
||||
@@ -329,7 +329,7 @@ namespace Esiur.Data
|
||||
var args = type.GetGenericArguments();
|
||||
if (args[0] == typeof(object))
|
||||
{
|
||||
tru = new TRU(TRUIdentifier.List, nullable);
|
||||
tru = new Tru(TruIdentifier.List, nullable);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -338,8 +338,8 @@ namespace Esiur.Data
|
||||
return null;
|
||||
|
||||
|
||||
tru = new TRU(TRUIdentifier.TypedList, nullable, null,
|
||||
new TRU[] { subType });
|
||||
tru = new Tru(TruIdentifier.TypedList, nullable, null,
|
||||
new Tru[] { subType });
|
||||
|
||||
}
|
||||
}
|
||||
@@ -349,7 +349,7 @@ namespace Esiur.Data
|
||||
var args = type.GetGenericArguments();
|
||||
if (args[0] == typeof(object) && args[1] == typeof(object))
|
||||
{
|
||||
tru = new TRU(TRUIdentifier.Map, nullable);
|
||||
tru = new Tru(TruIdentifier.Map, nullable);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -361,8 +361,8 @@ namespace Esiur.Data
|
||||
if (subType2 == null)
|
||||
return null;
|
||||
|
||||
tru = new TRU(TRUIdentifier.TypedMap, nullable, null,
|
||||
new TRU[] { subType1, subType2 });
|
||||
tru = new Tru(TruIdentifier.TypedMap, nullable, null,
|
||||
new Tru[] { subType1, subType2 });
|
||||
|
||||
}
|
||||
}
|
||||
@@ -375,7 +375,7 @@ namespace Esiur.Data
|
||||
else if (genericType == typeof(ValueTuple<,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
var subTypes = new TRU[args.Length];
|
||||
var subTypes = new Tru[args.Length];
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var t = FromType(args[i]);
|
||||
@@ -385,13 +385,13 @@ namespace Esiur.Data
|
||||
}
|
||||
|
||||
|
||||
tru = new TRU(TRUIdentifier.Tuple2, nullable, null, subTypes);
|
||||
tru = new Tru(TruIdentifier.Tuple2, nullable, null, subTypes);
|
||||
|
||||
}
|
||||
else if (genericType == typeof(ValueTuple<,,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
var subTypes = new TRU[args.Length];
|
||||
var subTypes = new Tru[args.Length];
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var t = FromType(args[i]);
|
||||
@@ -400,14 +400,14 @@ namespace Esiur.Data
|
||||
subTypes[i] = t;
|
||||
}
|
||||
|
||||
tru = new TRU(TRUIdentifier.Tuple3, nullable, null, subTypes);
|
||||
tru = new Tru(TruIdentifier.Tuple3, nullable, null, subTypes);
|
||||
|
||||
}
|
||||
else if (genericType == typeof(ValueTuple<,,,>))
|
||||
{
|
||||
|
||||
var args = type.GetGenericArguments();
|
||||
var subTypes = new TRU[args.Length];
|
||||
var subTypes = new Tru[args.Length];
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var t = FromType(args[i]);
|
||||
@@ -416,12 +416,12 @@ namespace Esiur.Data
|
||||
subTypes[i] = t;
|
||||
}
|
||||
|
||||
tru = new TRU(TRUIdentifier.Tuple4, nullable, null, subTypes);
|
||||
tru = new Tru(TruIdentifier.Tuple4, nullable, null, subTypes);
|
||||
}
|
||||
else if (genericType == typeof(ValueTuple<,,,,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
var subTypes = new TRU[args.Length];
|
||||
var subTypes = new Tru[args.Length];
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var t = FromType(args[i]);
|
||||
@@ -430,12 +430,12 @@ namespace Esiur.Data
|
||||
subTypes[i] = t;
|
||||
}
|
||||
|
||||
tru = new TRU(TRUIdentifier.Tuple5, nullable, null, subTypes);
|
||||
tru = new Tru(TruIdentifier.Tuple5, nullable, null, subTypes);
|
||||
}
|
||||
else if (genericType == typeof(ValueTuple<,,,,,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
var subTypes = new TRU[args.Length];
|
||||
var subTypes = new Tru[args.Length];
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var t = FromType(args[i]);
|
||||
@@ -444,12 +444,12 @@ namespace Esiur.Data
|
||||
subTypes[i] = t;
|
||||
}
|
||||
|
||||
tru = new TRU(TRUIdentifier.Tuple6, nullable, null, subTypes);
|
||||
tru = new Tru(TruIdentifier.Tuple6, nullable, null, subTypes);
|
||||
}
|
||||
else if (genericType == typeof(ValueTuple<,,,,,,>))
|
||||
{
|
||||
var args = type.GetGenericArguments();
|
||||
var subTypes = new TRU[args.Length];
|
||||
var subTypes = new Tru[args.Length];
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var t = FromType(args[i]);
|
||||
@@ -458,7 +458,7 @@ namespace Esiur.Data
|
||||
subTypes[i] = t;
|
||||
}
|
||||
|
||||
tru = new TRU(TRUIdentifier.Tuple7, nullable, null, subTypes);
|
||||
tru = new Tru(TruIdentifier.Tuple7, nullable, null, subTypes);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
@@ -467,7 +467,7 @@ namespace Esiur.Data
|
||||
{
|
||||
var elementType = type.GetElementType();
|
||||
if (elementType == typeof(object))
|
||||
tru = new TRU(TRUIdentifier.List, nullable);
|
||||
tru = new Tru(TruIdentifier.List, nullable);
|
||||
else
|
||||
{
|
||||
var subType = FromType(elementType);
|
||||
@@ -475,14 +475,14 @@ namespace Esiur.Data
|
||||
if (subType == null)
|
||||
return null;
|
||||
|
||||
tru = new TRU(TRUIdentifier.TypedList, nullable, null,
|
||||
new TRU[] { subType });
|
||||
tru = new Tru(TruIdentifier.TypedList, nullable, null,
|
||||
new Tru[] { subType });
|
||||
|
||||
}
|
||||
}
|
||||
else if (type.IsEnum)
|
||||
{
|
||||
tru = new TRU(TRUIdentifier.Enum, nullable, TypeDef.GetTypeUUID(type));
|
||||
tru = new Tru(TruIdentifier.Enum, nullable, TypeDef.GetTypeUUID(type));
|
||||
}
|
||||
else if (type.IsInterface)
|
||||
{
|
||||
@@ -503,30 +503,30 @@ namespace Esiur.Data
|
||||
// last check
|
||||
return type switch
|
||||
{
|
||||
_ when type == typeof(void) => new TRU(TRUIdentifier.Void, nullable),
|
||||
_ when type == typeof(object) => new TRU(TRUIdentifier.Dynamic, nullable),
|
||||
_ when type == typeof(bool) => new TRU(TRUIdentifier.Bool, nullable),
|
||||
_ when type == typeof(char) => new TRU(TRUIdentifier.Char, nullable),
|
||||
_ when type == typeof(byte) => new TRU(TRUIdentifier.UInt8, nullable),
|
||||
_ when type == typeof(sbyte) => new TRU(TRUIdentifier.Int8, nullable),
|
||||
_ when type == typeof(short) => new TRU(TRUIdentifier.Int16, nullable),
|
||||
_ when type == typeof(ushort) => new TRU(TRUIdentifier.UInt16, nullable),
|
||||
_ when type == typeof(int) => new TRU(TRUIdentifier.Int32, nullable),
|
||||
_ when type == typeof(uint) => new TRU(TRUIdentifier.UInt32, nullable),
|
||||
_ when type == typeof(long) => new TRU(TRUIdentifier.Int64, nullable),
|
||||
_ when type == typeof(ulong) => new TRU(TRUIdentifier.UInt64, nullable),
|
||||
_ when type == typeof(float) => new TRU(TRUIdentifier.Float32, nullable),
|
||||
_ when type == typeof(double) => new TRU(TRUIdentifier.Float64, nullable),
|
||||
_ when type == typeof(decimal) => new TRU(TRUIdentifier.Decimal, nullable),
|
||||
_ when type == typeof(string) => new TRU(TRUIdentifier.String, nullable),
|
||||
_ when type == typeof(DateTime) => new TRU(TRUIdentifier.DateTime, nullable),
|
||||
_ when type == typeof(ResourceLink) => new TRU(TRUIdentifier.Resource, nullable),
|
||||
_ when type == typeof(void) => new Tru(TruIdentifier.Void, nullable),
|
||||
_ when type == typeof(object) => new Tru(TruIdentifier.Dynamic, nullable),
|
||||
_ when type == typeof(bool) => new Tru(TruIdentifier.Bool, nullable),
|
||||
_ when type == typeof(char) => new Tru(TruIdentifier.Char, nullable),
|
||||
_ when type == typeof(byte) => new Tru(TruIdentifier.UInt8, nullable),
|
||||
_ when type == typeof(sbyte) => new Tru(TruIdentifier.Int8, nullable),
|
||||
_ when type == typeof(short) => new Tru(TruIdentifier.Int16, nullable),
|
||||
_ when type == typeof(ushort) => new Tru(TruIdentifier.UInt16, nullable),
|
||||
_ when type == typeof(int) => new Tru(TruIdentifier.Int32, nullable),
|
||||
_ when type == typeof(uint) => new Tru(TruIdentifier.UInt32, nullable),
|
||||
_ when type == typeof(long) => new Tru(TruIdentifier.Int64, nullable),
|
||||
_ when type == typeof(ulong) => new Tru(TruIdentifier.UInt64, nullable),
|
||||
_ when type == typeof(float) => new Tru(TruIdentifier.Float32, nullable),
|
||||
_ when type == typeof(double) => new Tru(TruIdentifier.Float64, nullable),
|
||||
_ when type == typeof(decimal) => new Tru(TruIdentifier.Decimal, nullable),
|
||||
_ when type == typeof(string) => new Tru(TruIdentifier.String, nullable),
|
||||
_ when type == typeof(DateTime) => new Tru(TruIdentifier.DateTime, nullable),
|
||||
_ when type == typeof(ResourceLink) => new Tru(TruIdentifier.Resource, nullable),
|
||||
_ => null
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public TRU(TRUIdentifier identifier, bool nullable, UUID? uuid = null, TRU[]? subTypes = null)
|
||||
public Tru(TruIdentifier identifier, bool nullable, Uuid? uuid = null, Tru[]? subTypes = null)
|
||||
{
|
||||
Nullable = nullable;
|
||||
Identifier = identifier;
|
||||
@@ -553,13 +553,13 @@ namespace Esiur.Data
|
||||
return rt.ToArray();
|
||||
}
|
||||
|
||||
public static (uint, TRU) Parse(byte[] data, uint offset)
|
||||
public static (uint, Tru) Parse(byte[] data, uint offset)
|
||||
{
|
||||
var oOffset = offset;
|
||||
|
||||
var header = data[offset++];
|
||||
bool nullable = (header & 0x80) > 0;
|
||||
var identifier = (TRUIdentifier)(header & 0x7F);
|
||||
var identifier = (TruIdentifier)(header & 0x7F);
|
||||
|
||||
|
||||
if ((header & 0x40) > 0)
|
||||
@@ -568,7 +568,7 @@ namespace Esiur.Data
|
||||
var hasUUID = (header & 0x4) > 0;
|
||||
var subsCount = (header >> 3) & 0x7;
|
||||
|
||||
UUID? uuid = null;
|
||||
Uuid? uuid = null;
|
||||
|
||||
if (hasUUID)
|
||||
{
|
||||
@@ -576,19 +576,19 @@ namespace Esiur.Data
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
var subs = new TRU[subsCount];
|
||||
var subs = new Tru[subsCount];
|
||||
|
||||
for (var i = 0; i < subsCount; i++)
|
||||
{
|
||||
(var len, subs[i]) = TRU.Parse(data, offset);
|
||||
(var len, subs[i]) = Tru.Parse(data, offset);
|
||||
offset += len;
|
||||
}
|
||||
|
||||
return (offset - oOffset, new TRU(identifier, nullable, uuid, subs));
|
||||
return (offset - oOffset, new Tru(identifier, nullable, uuid, subs));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (1, new TRU(identifier, nullable));
|
||||
return (1, new Tru(identifier, nullable));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
|
||||
namespace Esiur.Data
|
||||
{
|
||||
public enum TRUIdentifier
|
||||
public enum TruIdentifier
|
||||
{
|
||||
Void = 0x0,
|
||||
Dynamic = 0x1,
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ArgumentDef
|
||||
|
||||
public bool Optional { get; set; }
|
||||
|
||||
public TRU Type { get; set; }
|
||||
public Tru Type { get; set; }
|
||||
|
||||
public ParameterInfo ParameterInfo { get; set; }
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ArgumentDef
|
||||
var cs = (uint)data[offset++];
|
||||
var name = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
var (size, type) = TRU.Parse(data, offset);
|
||||
var (size, type) = Tru.Parse(data, offset);
|
||||
|
||||
offset += size;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class ConstantDef : MemberDef
|
||||
public object Value { get; set; }
|
||||
|
||||
public Map<string, string> Annotations { get; set; }
|
||||
public TRU ValueType { get; set; }
|
||||
public Tru ValueType { get; set; }
|
||||
|
||||
public FieldInfo FieldInfo { get; set; }
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ConstantDef : MemberDef
|
||||
var name = data.GetString(offset + 1, data[offset]);
|
||||
offset += (uint)data[offset] + 1;
|
||||
|
||||
var (dts, valueType) = TRU.Parse(data, offset);
|
||||
var (dts, valueType) = Tru.Parse(data, offset);
|
||||
|
||||
offset += dts;
|
||||
|
||||
@@ -100,7 +100,7 @@ public class ConstantDef : MemberDef
|
||||
{
|
||||
var annotationAttrs = ci.GetCustomAttributes<AnnotationAttribute>(true);
|
||||
|
||||
var valueType = TRU.FromType(ci.FieldType);
|
||||
var valueType = Tru.FromType(ci.FieldType);
|
||||
|
||||
if (valueType == null)
|
||||
throw new Exception($"Unsupported type `{ci.FieldType}` in constant `{type.Name}.{ci.Name}`");
|
||||
|
||||
@@ -29,7 +29,7 @@ public class EventDef : MemberDef
|
||||
|
||||
public EventInfo EventInfo { get; set; }
|
||||
|
||||
public TRU ArgumentType { get; set; }
|
||||
public Tru ArgumentType { get; set; }
|
||||
|
||||
|
||||
public static (uint, EventDef) Parse(byte[] data, uint offset, byte index, bool inherited)
|
||||
@@ -42,7 +42,7 @@ public class EventDef : MemberDef
|
||||
var name = data.GetString(offset + 1, data[offset]);
|
||||
offset += (uint)data[offset] + 1;
|
||||
|
||||
var (dts, argType) = TRU.Parse(data, offset);
|
||||
var (dts, argType) = Tru.Parse(data, offset);
|
||||
|
||||
offset += dts;
|
||||
|
||||
@@ -116,7 +116,7 @@ public class EventDef : MemberDef
|
||||
|
||||
|
||||
var argType = ei.EventHandlerType.GenericTypeArguments[0];
|
||||
var evtType = TRU.FromType(argType);
|
||||
var evtType = Tru.FromType(argType);
|
||||
|
||||
if (evtType == null)
|
||||
throw new Exception($"Unsupported type `{argType}` in event `{type.Name}.{ei.Name}`");
|
||||
|
||||
@@ -27,7 +27,7 @@ public class FunctionDef : MemberDef
|
||||
// set;
|
||||
//}
|
||||
|
||||
public TRU ReturnType { get; set; }
|
||||
public Tru ReturnType { get; set; }
|
||||
|
||||
public bool IsStatic { get; set; }
|
||||
|
||||
@@ -52,7 +52,7 @@ public class FunctionDef : MemberDef
|
||||
offset += (uint)data[offset] + 1;
|
||||
|
||||
// return type
|
||||
var (rts, returnType) = TRU.Parse(data, offset);
|
||||
var (rts, returnType) = Tru.Parse(data, offset);
|
||||
offset += rts;
|
||||
|
||||
// arguments count
|
||||
@@ -124,27 +124,27 @@ public class FunctionDef : MemberDef
|
||||
|
||||
var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null;
|
||||
|
||||
TRU rtType;
|
||||
Tru rtType;
|
||||
|
||||
if (genericRtType == typeof(AsyncReply<>))
|
||||
{
|
||||
rtType = TRU.FromType(mi.ReturnType.GetGenericArguments()[0]);
|
||||
rtType = Tru.FromType(mi.ReturnType.GetGenericArguments()[0]);
|
||||
}
|
||||
else if (genericRtType == typeof(Task<>))
|
||||
{
|
||||
rtType = TRU.FromType(mi.ReturnType.GetGenericArguments()[0]);
|
||||
rtType = Tru.FromType(mi.ReturnType.GetGenericArguments()[0]);
|
||||
}
|
||||
else if (genericRtType == typeof(IEnumerable<>) || genericRtType == typeof(IAsyncEnumerable<>))
|
||||
{
|
||||
// get export
|
||||
rtType = TRU.FromType(mi.ReturnType.GetGenericArguments()[0]);
|
||||
rtType = Tru.FromType(mi.ReturnType.GetGenericArguments()[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mi.ReturnType == typeof(Task))
|
||||
rtType = TRU.FromType(null);
|
||||
rtType = Tru.FromType(null);
|
||||
else
|
||||
rtType = TRU.FromType(mi.ReturnType);
|
||||
rtType = Tru.FromType(mi.ReturnType);
|
||||
}
|
||||
|
||||
if (rtType == null)
|
||||
@@ -214,7 +214,7 @@ public class FunctionDef : MemberDef
|
||||
|
||||
var arguments = args.Select(x =>
|
||||
{
|
||||
var argType = TRU.FromType(x.ParameterType);
|
||||
var argType = Tru.FromType(x.ParameterType);
|
||||
|
||||
if (argType == null)
|
||||
throw new Exception($"Unsupported type `{x.ParameterType}` in method `{type.Name}.{mi.Name}` parameter `{x.Name}`");
|
||||
|
||||
@@ -24,7 +24,7 @@ public class PropertyDef : MemberDef
|
||||
set;
|
||||
}
|
||||
|
||||
public TRU ValueType { get; set; }
|
||||
public Tru ValueType { get; set; }
|
||||
|
||||
|
||||
/*
|
||||
@@ -93,7 +93,7 @@ public class PropertyDef : MemberDef
|
||||
|
||||
offset += (uint)data[offset] + 1;
|
||||
|
||||
var (dts, valueType) = TRU.Parse(data, offset);
|
||||
var (dts, valueType) = Tru.Parse(data, offset);
|
||||
|
||||
offset += dts;
|
||||
|
||||
@@ -200,8 +200,8 @@ public class PropertyDef : MemberDef
|
||||
var genericPropType = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericTypeDefinition() : null;
|
||||
|
||||
var propType = genericPropType == typeof(PropertyContext<>) ?
|
||||
TRU.FromType(pi.PropertyType.GetGenericArguments()[0]) :
|
||||
TRU.FromType(pi.PropertyType);
|
||||
Tru.FromType(pi.PropertyType.GetGenericArguments()[0]) :
|
||||
Tru.FromType(pi.PropertyType);
|
||||
|
||||
if (propType == null)
|
||||
throw new Exception($"Unsupported type `{pi.PropertyType}` in property `{type.Name}.{pi.Name}`");
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace Esiur.Data.Types;
|
||||
public class TypeDef
|
||||
{
|
||||
|
||||
protected UUID typeId;
|
||||
protected UUID? parentId;
|
||||
protected Uuid typeId;
|
||||
protected Uuid? parentId;
|
||||
|
||||
public Map<string, string> Annotations { get; set; }
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TypeDef
|
||||
|
||||
protected byte[] content;
|
||||
|
||||
public UUID? ParentId => parentId;
|
||||
public Uuid? ParentId => parentId;
|
||||
|
||||
public byte[] Content
|
||||
{
|
||||
@@ -110,7 +110,7 @@ public class TypeDef
|
||||
return null;
|
||||
}
|
||||
|
||||
public UUID Id
|
||||
public Uuid Id
|
||||
{
|
||||
get { return typeId; }
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public class TypeDef
|
||||
|
||||
}
|
||||
|
||||
public static UUID GetTypeUUID(Type type)
|
||||
public static Uuid GetTypeUUID(Type type)
|
||||
{
|
||||
var attr = type.GetCustomAttribute<TypeIdAttribute>();
|
||||
if (attr != null)
|
||||
@@ -153,7 +153,7 @@ public class TypeDef
|
||||
hash[6] = (byte)((hash[6] & 0xF) | 0x80);
|
||||
hash[8] = (byte)((hash[8] & 0xF) | 0x80);
|
||||
|
||||
var rt = new UUID(hash);
|
||||
var rt = new Uuid(hash);
|
||||
return rt;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Text;
|
||||
namespace Esiur.Data
|
||||
{
|
||||
//[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct UUID
|
||||
public struct Uuid
|
||||
{
|
||||
//4e7db2d8-a785-1b99-1854-4b4018bc5677
|
||||
//byte a1;
|
||||
@@ -32,7 +32,7 @@ namespace Esiur.Data
|
||||
public byte[] Data { get; private set; }
|
||||
|
||||
|
||||
public UUID(byte[] data, uint offset)
|
||||
public Uuid(byte[] data, uint offset)
|
||||
{
|
||||
if (offset + 16 > data.Length)
|
||||
throw new Exception("UUID data size must be at least 16 bytes");
|
||||
@@ -74,7 +74,7 @@ namespace Esiur.Data
|
||||
|
||||
}
|
||||
|
||||
public UUID(byte[] data) {
|
||||
public Uuid(byte[] data) {
|
||||
|
||||
if (data.Length != 16)
|
||||
throw new Exception("UUID data size must be 16 bytes");
|
||||
@@ -107,13 +107,13 @@ namespace Esiur.Data
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is UUID b)
|
||||
if (obj is Uuid b)
|
||||
return Data.SequenceEqual(b.Data);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator == (UUID a, UUID b)
|
||||
public static bool operator == (Uuid a, Uuid b)
|
||||
{
|
||||
return a.Data.SequenceEqual(b.Data);
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace Esiur.Data
|
||||
// && a.e6 == b.e6;
|
||||
}
|
||||
|
||||
public static bool operator !=(UUID a, UUID b)
|
||||
public static bool operator !=(Uuid a, Uuid b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user