diff --git a/GoRules.Zen/FFI/ZenFfi.g.cs b/GoRules.Zen/FFI/ZenFfi.g.cs
index 1e2d926..a6a3e1b 100644
--- a/GoRules.Zen/FFI/ZenFfi.g.cs
+++ b/GoRules.Zen/FFI/ZenFfi.g.cs
@@ -17,72 +17,93 @@ internal static unsafe partial class ZenFfi
[DllImport("libc", EntryPoint = "free", SetLastError = false)]
public static extern void free(IntPtr ptr);
- /// Frees ZenDecision
+ ///
+ /// Frees ZenDecision
+ ///
[DllImport(__DllName, EntryPoint = "zen_decision_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void zen_decision_free(ZenDecisionStruct* decision);
+ internal static extern void zen_decision_free(ZenDecisionStruct* decision);
- /// Evaluates ZenDecision Caller is responsible for freeing context and ZenResult.
+ ///
+ /// Evaluates ZenDecision
+ /// Caller is responsible for freeing context and ZenResult.
+ ///
[DllImport(__DllName, EntryPoint = "zen_decision_evaluate", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenResult zen_decision_evaluate(ZenDecisionStruct* decision, byte* context_ptr, ZenEngineEvaluationOptions options);
+ internal static extern ZenResult zen_decision_evaluate(ZenDecisionStruct* decision, byte* context_ptr, ZenEngineEvaluationOptions options);
- /// Creates a new GoRules.Zen instance with loader, caller is responsible for freeing the returned reference by calling zen_engine_free.
- [DllImport(__DllName, EntryPoint = "zen_engine_new_with_native_loader", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenEngineStruct* zen_engine_new_with_native_loader(delegate* unmanaged[Cdecl] callback);
-
- /// Creates a DecisionEngine for using GoLang handler (optional). Caller is responsible for freeing DecisionEngine.
- [DllImport(__DllName, EntryPoint = "zen_engine_new_with_go_loader", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenEngineStruct* zen_engine_new_with_go_loader(nuint* maybe_loader);
-
- /// Evaluate expression, responsible for freeing expression and context
- [DllImport(__DllName, EntryPoint = "zen_evaluate_expression", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenResult zen_evaluate_expression(byte* expression, byte* context);
-
- /// Evaluate unary expression, responsible for freeing expression and context True = 1 False = 0
- [DllImport(__DllName, EntryPoint = "zen_evaluate_unary_expression", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenResult zen_evaluate_unary_expression(byte* expression, byte* context);
-
- /// Create a new GoRules.Zen instance, caller is responsible for freeing the returned reference by calling zen_engine_free.
+ ///
+ /// Create a new ZenEngine instance, caller is responsible for freeing the returned reference
+ /// by calling zen_engine_free.
+ ///
[DllImport(__DllName, EntryPoint = "zen_engine_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenEngineStruct* zen_engine_new();
+ internal static extern ZenEngineStruct* zen_engine_new();
- /// Frees the GoRules.Zen instance reference from the memory
+ ///
+ /// Frees the ZenEngine instance reference from the memory
+ ///
[DllImport(__DllName, EntryPoint = "zen_engine_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void zen_engine_free(ZenEngineStruct* engine);
+ internal static extern void zen_engine_free(ZenEngineStruct* engine);
- /// Creates a Decision using a reference of DecisionEngine and content (JSON) Caller is responsible for freeing content and ZenResult.
+ ///
+ /// Creates a Decision using a reference of DecisionEngine and content (JSON)
+ /// Caller is responsible for freeing content and ZenResult.
+ ///
[DllImport(__DllName, EntryPoint = "zen_engine_create_decision", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenResult zen_engine_create_decision(ZenEngineStruct* engine, byte* content);
+ internal static extern ZenResult zen_engine_create_decision(ZenEngineStruct* engine, byte* content);
- /// Evaluates rules engine using a DecisionEngine reference via loader Caller is responsible for freeing: key, context and ZenResult.
+ ///
+ /// Evaluates rules engine using a DecisionEngine reference via loader
+ /// Caller is responsible for freeing: key, context and ZenResult.
+ ///
[DllImport(__DllName, EntryPoint = "zen_engine_evaluate", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenResult zen_engine_evaluate(ZenEngineStruct* engine, byte* key, byte* context, ZenEngineEvaluationOptions options);
+ internal static extern ZenResult zen_engine_evaluate(ZenEngineStruct* engine, byte* key, byte* context, ZenEngineEvaluationOptions options);
- /// Loads a Decision through DecisionEngine Caller is responsible for freeing: key and ZenResult.
+ ///
+ /// Loads a Decision through DecisionEngine
+ /// Caller is responsible for freeing: key and ZenResult.
+ ///
[DllImport(__DllName, EntryPoint = "zen_engine_get_decision", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ZenResult zen_engine_get_decision(ZenEngineStruct* engine, byte* key);
+ internal static extern ZenResult zen_engine_get_decision(ZenEngineStruct* engine, byte* key);
+ [DllImport(__DllName, EntryPoint = "zen_evaluate_expression", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ internal static extern ZenResult zen_evaluate_expression(byte* expression, byte* context);
+
+ ///
+ /// Evaluate unary expression, responsible for freeing expression and context
+ /// True = 1
+ /// False = 0
+ ///
+ [DllImport(__DllName, EntryPoint = "zen_evaluate_unary_expression", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ internal static extern ZenResult zen_evaluate_unary_expression(byte* expression, byte* context);
+
+ ///
+ /// Evaluate unary expression, responsible for freeing expression and context
+ /// True = 1
+ /// False = 0
+ ///
+ [DllImport(__DllName, EntryPoint = "zen_evaluate_template", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ internal static extern ZenResult zen_evaluate_template(byte* template, byte* context);
+
+ ///
+ /// Creates a new ZenEngine instance with loader, caller is responsible for freeing the returned reference
+ /// by calling zen_engine_free.
+ ///
+ [DllImport(__DllName, EntryPoint = "zen_engine_new_native", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ internal static extern ZenEngineStruct* zen_engine_new_native(delegate* unmanaged[Cdecl] loader_callback, delegate* unmanaged[Cdecl] custom_node_callback);
- }
- [StructLayout(LayoutKind.Sequential)]
- internal unsafe partial struct ZenDecisionStruct
- {
- public fixed byte _data[1];
}
[StructLayout(LayoutKind.Sequential)]
- internal unsafe partial struct ZenDecisionLoaderResult
+ internal unsafe partial struct ZenCustomNodeResult
{
public byte* content;
public byte* error;
}
[StructLayout(LayoutKind.Sequential)]
- internal unsafe partial struct ZenResult
+ internal unsafe partial struct ZenDecisionStruct
{
- public T* result;
- public byte error;
- public byte* details;
+ public fixed byte _data[1];
}
[StructLayout(LayoutKind.Sequential)]
@@ -98,7 +119,24 @@ internal unsafe partial struct ZenEngineEvaluationOptions
public byte max_depth;
}
+ [StructLayout(LayoutKind.Sequential)]
+ internal unsafe partial struct ZenDecisionLoaderResult
+ {
+ public byte* content;
+ public byte* error;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal unsafe partial struct ZenResult
+ {
+ public T* result;
+ public byte error;
+ public byte* details;
+ }
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal unsafe delegate ZenDecisionLoaderResult ZenEngineLoaderDelegate(byte* data);
+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal unsafe delegate ZenDecisionLoaderResult ZenEngineCallbackDelegate(byte* data);
+ internal unsafe delegate ZenDecisionLoaderResult ZenEngineCustomNodeDelegate(byte* data);
}
-
\ No newline at end of file
diff --git a/GoRules.Zen/GoRules.Zen.csproj b/GoRules.Zen/GoRules.Zen.csproj
index 2d67552..7ad2111 100644
--- a/GoRules.Zen/GoRules.Zen.csproj
+++ b/GoRules.Zen/GoRules.Zen.csproj
@@ -3,7 +3,6 @@
Business rules engine
GoRules.Zen
- net7.0
enable
enable
true
@@ -12,7 +11,7 @@
false
false
gorules;bre;business;rules;engine;aspnet;aspnetcore
- net6.0;net7.0;net8.0
+ net7.0;net8.0
diff --git a/GoRules.Zen/Interop/ZenEngine.cs b/GoRules.Zen/Interop/ZenEngine.cs
index d925033..c029fde 100644
--- a/GoRules.Zen/Interop/ZenEngine.cs
+++ b/GoRules.Zen/Interop/ZenEngine.cs
@@ -28,7 +28,7 @@ public ZenEngine(ZenEngineOptions? options = null)
{
_callbackHandle = GCHandle.Alloc(loaderDelegate);
IntPtr pCallback = Marshal.GetFunctionPointerForDelegate(loaderDelegate);
- _internalReference = ZenFfi.zen_engine_new_with_native_loader((delegate* unmanaged[Cdecl])pCallback);
+ _internalReference = ZenFfi.zen_engine_new_native((delegate* unmanaged[Cdecl])pCallback, null);
}
}
diff --git a/GoRules.Zen/Libs/libzen_ffi.dylib b/GoRules.Zen/Libs/libzen_ffi.dylib
old mode 100644
new mode 100755
index 1b89bf9..5cb7cdc
Binary files a/GoRules.Zen/Libs/libzen_ffi.dylib and b/GoRules.Zen/Libs/libzen_ffi.dylib differ
diff --git a/GoRules.Zen/Models/ZenEngineOptions.cs b/GoRules.Zen/Models/ZenEngineOptions.cs
index 24cbdb3..3343fa5 100644
--- a/GoRules.Zen/Models/ZenEngineOptions.cs
+++ b/GoRules.Zen/Models/ZenEngineOptions.cs
@@ -5,8 +5,9 @@ namespace GoRules.Zen;
public record ZenEngineOptions
{
public Func>? Loader;
+ public Func? CustomNode; // TODO
- internal unsafe ZenEngineCallbackDelegate? GetLoaderDelegate()
+ internal unsafe ZenEngineLoaderDelegate? GetLoaderDelegate()
{
if (Loader is null)
return null;