Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialiser_Engine: Deserialisation of nested lists #3160

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Serialiser_Engine/Compute/Deserialise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ private static object IDeserialise(this BsonValue bson, string version, bool isU
if (bson.IsBsonNull)
return null;
else if (bson.IsBsonArray)
return bson.DeserialiseList(new List<object>(), version, isUpgraded);
{
if (IsNestedList(bson))
return bson.DeserialiseNestedList(new List<List<object>>(), version, isUpgraded);
else
return bson.DeserialiseList(new List<object>(), version, isUpgraded);
}
else if (bson.IsBsonDocument)
{
BsonDocument doc = bson.AsBsonDocument;
Expand Down
34 changes: 34 additions & 0 deletions Serialiser_Engine/Compute/Deserialise/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,39 @@ private static List<T> DeserialiseList<T>(this BsonValue bson, List<T> value, st
}

/*******************************************/

private static List<List<T>> DeserialiseNestedList<T>(this BsonValue bson, List<List<T>> value, string version, bool isUpgraded)
{
bson = ExtractValue(bson);

if (!bson.IsBsonArray)
{
BH.Engine.Base.Compute.RecordError("Expected to deserialise a List and received " + bson.ToString() + " instead.");
return value;
}

if (value == null)
value = new List<List<T>>();

foreach (BsonValue item in bson.AsBsonArray)
value.Add((List<T>)item.DeserialiseList(new List<T>(), version, isUpgraded));

return value;
}

/*******************************************/

private static bool IsNestedList(this BsonValue bson)
{
int nest = 0;

while(bson.IsBsonArray)
{
nest++;
bson = bson[0];
}

return nest > 1;
}
}
}