Flat COI binary representation
This commit is contained in:
@@ -115,6 +115,11 @@ namespace mROA.Cbor
|
|||||||
return new RequestId((byte[])nonCasted);
|
return new RequestId((byte[])nonCasted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type.IsInterface)
|
||||||
|
{
|
||||||
|
return ReadSharedShell(type, context, (ulong)nonCasted);
|
||||||
|
}
|
||||||
|
|
||||||
return Convert.ChangeType(nonCasted, type);
|
return Convert.ChangeType(nonCasted, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +240,7 @@ namespace mROA.Cbor
|
|||||||
Activator.CreateInstance(sharedShell, obj, context) as
|
Activator.CreateInstance(sharedShell, obj, context) as
|
||||||
ISharedObjectShell;
|
ISharedObjectShell;
|
||||||
|
|
||||||
writer.WriteStartArray(1);
|
|
||||||
writer.WriteUInt64(so.Identifier.Flat);
|
writer.WriteUInt64(so.Identifier.Flat);
|
||||||
writer.WriteEndArray();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -267,7 +270,10 @@ namespace mROA.Cbor
|
|||||||
return reader.ReadInt64();
|
return reader.ReadInt64();
|
||||||
if (type == typeof(uint))
|
if (type == typeof(uint))
|
||||||
return reader.ReadUInt32();
|
return reader.ReadUInt32();
|
||||||
|
if (type.IsInterface)
|
||||||
|
{
|
||||||
|
return ReadSharedShell(type, context, reader.ReadUInt64());
|
||||||
|
}
|
||||||
return reader.ReadUInt64();
|
return reader.ReadUInt64();
|
||||||
case CborReaderState.ByteString:
|
case CborReaderState.ByteString:
|
||||||
if (type == typeof(RequestId))
|
if (type == typeof(RequestId))
|
||||||
@@ -378,19 +384,9 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
if (type.IsInterface)
|
if (type.IsInterface)
|
||||||
{
|
{
|
||||||
var sharedShell = typeof(SharedObjectShellShell<>).MakeGenericType(type);
|
|
||||||
var so =
|
|
||||||
Activator.CreateInstance(sharedShell) as
|
|
||||||
ISharedObjectShell;
|
|
||||||
if (context != null)
|
|
||||||
so.EndPointContext = context;
|
|
||||||
|
|
||||||
reader.ReadStartArray();
|
|
||||||
var identifier = reader.ReadUInt64();
|
var identifier = reader.ReadUInt64();
|
||||||
reader.ReadEndArray();
|
|
||||||
|
|
||||||
so.Identifier = ComplexObjectIdentifier.FromFlat(identifier);
|
return ReadSharedShell(type, context, identifier);
|
||||||
return so.UniversalValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var instance = Activator.CreateInstance(type)!;
|
var instance = Activator.CreateInstance(type)!;
|
||||||
@@ -400,6 +396,20 @@ namespace mROA.Cbor
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static object ReadSharedShell(Type type, IEndPointContext? context, ulong identifier)
|
||||||
|
{
|
||||||
|
var sharedShell = typeof(SharedObjectShellShell<>).MakeGenericType(type);
|
||||||
|
var so =
|
||||||
|
Activator.CreateInstance(sharedShell) as
|
||||||
|
ISharedObjectShell;
|
||||||
|
if (context != null)
|
||||||
|
so.EndPointContext = context;
|
||||||
|
|
||||||
|
|
||||||
|
so.Identifier = ComplexObjectIdentifier.FromFlat(identifier);
|
||||||
|
return so.UniversalValue;
|
||||||
|
}
|
||||||
|
|
||||||
private ISharedObjectShell ReadSharedObject(CborReader reader, Type type, IEndPointContext? context)
|
private ISharedObjectShell ReadSharedObject(CborReader reader, Type type, IEndPointContext? context)
|
||||||
{
|
{
|
||||||
var sharedObject = (Activator.CreateInstance(type) as ISharedObjectShell)!;
|
var sharedObject = (Activator.CreateInstance(type) as ISharedObjectShell)!;
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ namespace mROA.Cbor
|
|||||||
v.Id.WriteToCborInline(writer);
|
v.Id.WriteToCborInline(writer);
|
||||||
// writer.WriteByteString(v.Id.ToByteArray());
|
// writer.WriteByteString(v.Id.ToByteArray());
|
||||||
writer.WriteInt32(v.CommandId);
|
writer.WriteInt32(v.CommandId);
|
||||||
writer.WriteStartArray(1);
|
|
||||||
writer.WriteUInt64(v.ObjectId.Flat);
|
writer.WriteUInt64(v.ObjectId.Flat);
|
||||||
writer.WriteEndArray();
|
|
||||||
serialization.WriteData(v.Parameters, writer, context);
|
serialization.WriteData(v.Parameters, writer, context);
|
||||||
writer.WriteEndArray();
|
writer.WriteEndArray();
|
||||||
}
|
}
|
||||||
@@ -48,16 +46,12 @@ namespace mROA.Cbor
|
|||||||
public static readonly ComplexObjectIdentifierParser Instance = new();
|
public static readonly ComplexObjectIdentifierParser Instance = new();
|
||||||
public void Write(CborWriter writer, object value, IEndPointContext context, CborSerializationToolkit serialization)
|
public void Write(CborWriter writer, object value, IEndPointContext context, CborSerializationToolkit serialization)
|
||||||
{
|
{
|
||||||
writer.WriteStartArray(1);
|
|
||||||
writer.WriteUInt64(((ComplexObjectIdentifier)value).Flat);
|
writer.WriteUInt64(((ComplexObjectIdentifier)value).Flat);
|
||||||
writer.WriteEndArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Read(CborReader reader, IEndPointContext context, CborSerializationToolkit serialization)
|
public object Read(CborReader reader, IEndPointContext context, CborSerializationToolkit serialization)
|
||||||
{
|
{
|
||||||
reader.ReadStartArray();
|
|
||||||
var value = new ComplexObjectIdentifier { Flat = reader.ReadUInt64() };
|
var value = new ComplexObjectIdentifier { Flat = reader.ReadUInt64() };
|
||||||
reader.ReadEndArray();
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user