Skip to content

Commit

Permalink
fix stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkRRb committed Oct 28, 2024
1 parent d0ecb82 commit c283dc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Lagrange.OneBot/LagrangeAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ public LagrangeAppBuilder ConfigureOneBot()
BsonMapper.Global.EmptyStringToNull = false;
// Specify ctor for some classes
BsonMapper.Global.RegisterType(BsonMapper.Global.Serialize, LiteDbUtility.IMessageEntityDeserialize);
BsonMapper.Global.RegisterType(
LiteDbUtility.IMessageEntitySerialize,
LiteDbUtility.IMessageEntityDeserialize
);
string path = Configuration["ConfigPath:Database"] ?? $"lagrange-{Configuration["Account:Uin"]}.db";
Expand Down
9 changes: 9 additions & 0 deletions Lagrange.OneBot/Utility/LiteDbUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ namespace Lagrange.OneBot.Utility;

public static class LiteDbUtility
{
public static BsonValue IMessageEntitySerialize(IMessageEntity entity)
{
var type = entity.GetType();
var result = BsonMapper.Global.Serialize(type, entity);
result["_type"] = new BsonValue(DefaultTypeNameBinder.Instance.GetName(type));
return result;
}

public static IMessageEntity IMessageEntityDeserialize(BsonValue bson)
{
if (!bson.IsDocument) throw new Exception("bson not BsonDocument");
Expand All @@ -17,6 +25,7 @@ public static IMessageEntity IMessageEntityDeserialize(BsonValue bson)
}

var type = DefaultTypeNameBinder.Instance.GetType(typeBson.AsString);

if (type == typeof(MarkdownEntity)) return MarkdownEntityDeserialize(doc);

return (IMessageEntity)BsonMapper.Global.Deserialize(type, bson);
Expand Down

0 comments on commit c283dc3

Please sign in to comment.