Flat COI binary representation

This commit is contained in:
2025-08-07 19:14:17 +03:00
parent 89a2bee8d2
commit 0f355b9df3
2 changed files with 24 additions and 20 deletions
+24 -14
View File
@@ -115,6 +115,11 @@ namespace mROA.Cbor
return new RequestId((byte[])nonCasted);
}
if (type.IsInterface)
{
return ReadSharedShell(type, context, (ulong)nonCasted);
}
return Convert.ChangeType(nonCasted, type);
}
@@ -235,9 +240,7 @@ namespace mROA.Cbor
Activator.CreateInstance(sharedShell, obj, context) as
ISharedObjectShell;
writer.WriteStartArray(1);
writer.WriteUInt64(so.Identifier.Flat);
writer.WriteEndArray();
return;
}
@@ -267,7 +270,10 @@ namespace mROA.Cbor
return reader.ReadInt64();
if (type == typeof(uint))
return reader.ReadUInt32();
if (type.IsInterface)
{
return ReadSharedShell(type, context, reader.ReadUInt64());
}
return reader.ReadUInt64();
case CborReaderState.ByteString:
if (type == typeof(RequestId))
@@ -378,19 +384,9 @@ namespace mROA.Cbor
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();
reader.ReadEndArray();
so.Identifier = ComplexObjectIdentifier.FromFlat(identifier);
return so.UniversalValue;
return ReadSharedShell(type, context, identifier);
}
var instance = Activator.CreateInstance(type)!;
@@ -400,6 +396,20 @@ namespace mROA.Cbor
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)
{
var sharedObject = (Activator.CreateInstance(type) as ISharedObjectShell)!;
-6
View File
@@ -21,9 +21,7 @@ namespace mROA.Cbor
v.Id.WriteToCborInline(writer);
// writer.WriteByteString(v.Id.ToByteArray());
writer.WriteInt32(v.CommandId);
writer.WriteStartArray(1);
writer.WriteUInt64(v.ObjectId.Flat);
writer.WriteEndArray();
serialization.WriteData(v.Parameters, writer, context);
writer.WriteEndArray();
}
@@ -48,16 +46,12 @@ namespace mROA.Cbor
public static readonly ComplexObjectIdentifierParser Instance = new();
public void Write(CborWriter writer, object value, IEndPointContext context, CborSerializationToolkit serialization)
{
writer.WriteStartArray(1);
writer.WriteUInt64(((ComplexObjectIdentifier)value).Flat);
writer.WriteEndArray();
}
public object Read(CborReader reader, IEndPointContext context, CborSerializationToolkit serialization)
{
reader.ReadStartArray();
var value = new ComplexObjectIdentifier { Flat = reader.ReadUInt64() };
reader.ReadEndArray();
return value;
}
}