返回值类型
+ * @since 3.1.0
+ */
+@FunctionalInterface
+public interface Func extends Serializable {
+ /**
+ * 执行函数
+ *
+ * @param parameters 参数列表
+ * @return 函数执行结果
+ * @throws Exception 自定义异常
+ */
+ @SuppressWarnings("unchecked")
+ R call(P... parameters) throws Exception;
+
+ /**
+ * 执行函数,异常包装为RuntimeException
+ *
+ * @param parameters 参数列表
+ * @return 函数执行结果
+ */
+ @SuppressWarnings("unchecked")
+ default R callWithRuntimeException(P... parameters){
+ try {
+ return call(parameters);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/storage/src/main/java/com/zfoo/storage/util/function/Func0.java b/storage/src/main/java/com/zfoo/storage/util/function/Func0.java
new file mode 100644
index 00000000..dad2f4d9
--- /dev/null
+++ b/storage/src/main/java/com/zfoo/storage/util/function/Func0.java
@@ -0,0 +1,39 @@
+package com.zfoo.storage.util.function;
+
+import java.io.Serializable;
+
+/**
+ * 无参数的函数对象
+ * 接口灵感来自于ActFramework
+ * 一个函数接口代表一个一个函数,用于包装一个函数为对象
+ * 在JDK8之前,Java的函数并不能作为参数传递,也不能作为返回值存在,此接口用于将一个函数包装成为一个对象,从而传递对象
+ *
+ * @author Looly
+ *
+ * @param 返回值类型
+ * @since 4.5.2
+ */
+@FunctionalInterface
+public interface Func0 extends Serializable {
+ /**
+ * 执行函数
+ *
+ * @return 函数执行结果
+ * @throws Exception 自定义异常
+ */
+ R call() throws Exception;
+
+ /**
+ * 执行函数,异常包装为RuntimeException
+ *
+ * @return 函数执行结果
+ * @since 5.3.6
+ */
+ default R callWithRuntimeException(){
+ try {
+ return call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/storage/src/main/java/com/zfoo/storage/util/function/Func1.java b/storage/src/main/java/com/zfoo/storage/util/function/Func1.java
new file mode 100644
index 00000000..bd38f112
--- /dev/null
+++ b/storage/src/main/java/com/zfoo/storage/util/function/Func1.java
@@ -0,0 +1,43 @@
+package com.zfoo.storage.util.function;
+
+import java.io.Serializable;
+
+/**
+ * 只有一个参数的函数对象
+ * 接口灵感来自于ActFramework
+ * 一个函数接口代表一个一个函数,用于包装一个函数为对象
+ * 在JDK8之前,Java的函数并不能作为参数传递,也不能作为返回值存在,此接口用于将一个函数包装成为一个对象,从而传递对象
+ *
+ * @author Looly
+ *
+ * @param 参数类型
+ * @param 返回值类型
+ * @since 4.2.2
+ */
+@FunctionalInterface
+public interface Func1 extends Serializable {
+
+ /**
+ * 执行函数
+ *
+ * @param parameter 参数
+ * @return 函数执行结果
+ * @throws Exception 自定义异常
+ */
+ R call(P parameter) throws Exception;
+
+ /**
+ * 执行函数,异常包装为RuntimeException
+ *
+ * @param parameter 参数
+ * @return 函数执行结果
+ * @since 5.3.6
+ */
+ default R callWithRuntimeException(P parameter){
+ try {
+ return call(parameter);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/storage/src/main/java/com/zfoo/storage/util/support/SerializableFunction.java b/storage/src/main/java/com/zfoo/storage/util/support/SerializableFunction.java
deleted file mode 100644
index eac5f769..00000000
--- a/storage/src/main/java/com/zfoo/storage/util/support/SerializableFunction.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.zfoo.storage.util.support;
-
-import java.io.Serializable;
-import java.util.function.Function;
-
-/**
- * 支持序列化的 Function
- *
- * @author veione
- */
-@FunctionalInterface
-public interface SerializableFunction extends Function, Serializable {
-}
diff --git a/storage/src/test/java/com/zfoo/storage/TestLambdaFunctionCache.java b/storage/src/test/java/com/zfoo/storage/TestLambdaFunctionCache.java
new file mode 100644
index 00000000..5bbd9e36
--- /dev/null
+++ b/storage/src/test/java/com/zfoo/storage/TestLambdaFunctionCache.java
@@ -0,0 +1,20 @@
+package com.zfoo.storage;
+
+import com.zfoo.storage.resource.StudentResource;
+import com.zfoo.storage.util.LambdaUtils;
+import com.zfoo.storage.util.function.Func1;
+import org.junit.Test;
+
+/**
+ * @author veione
+ * @version 1.0.0
+ */
+public class TestLambdaFunctionCache {
+
+ @Test
+ public void testFunctionCache() {
+ Func1 nameFunc = StudentResource::getName;
+ System.out.println(LambdaUtils.getMethodName(nameFunc));
+ System.out.println(LambdaUtils.getMethodName(nameFunc));
+ }
+}
diff --git a/storage/src/test/java/com/zfoo/storage/TestPropertyNamer.java b/storage/src/test/java/com/zfoo/storage/TestPropertyNamer.java
new file mode 100644
index 00000000..5ff48294
--- /dev/null
+++ b/storage/src/test/java/com/zfoo/storage/TestPropertyNamer.java
@@ -0,0 +1,28 @@
+package com.zfoo.storage;
+
+import com.zfoo.storage.util.PropertyNamer;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author veione
+ * @version 1.0.0
+ */
+public class TestPropertyNamer {
+
+ @Test
+ public void testPropertyName() {
+ //前三种主要用于普通的POJO,第四种用于是record类型,方法名就是属性名
+ String getName = PropertyNamer.methodToProperty("getName");
+ assertEquals(getName, "name");
+ String setName = PropertyNamer.methodToProperty("setName");
+ assertEquals(setName, "name");
+ String isName = PropertyNamer.methodToProperty("isName");
+ assertEquals(isName, "name");
+ String name = PropertyNamer.methodToProperty("name");
+ assertEquals(name, "name");
+ name = PropertyNamer.methodToProperty("Name");
+ assertEquals(name, "name");
+ }
+}
diff --git a/storage/src/test/java/com/zfoo/storage/export/ExportBinaryTesting.java b/storage/src/test/java/com/zfoo/storage/export/ExportBinaryTesting.java
index e5e197f3..0f541916 100644
--- a/storage/src/test/java/com/zfoo/storage/export/ExportBinaryTesting.java
+++ b/storage/src/test/java/com/zfoo/storage/export/ExportBinaryTesting.java
@@ -16,7 +16,6 @@ import com.zfoo.protocol.ProtocolManager;
import com.zfoo.protocol.buffer.ByteBufUtils;
import com.zfoo.protocol.generate.GenerateOperation;
import com.zfoo.protocol.serializer.CodeLanguage;
-import com.zfoo.protocol.util.ClassUtils;
import com.zfoo.protocol.util.FileUtils;
import com.zfoo.protocol.util.JsonUtils;
import com.zfoo.storage.anno.AliasFieldName;
@@ -28,7 +27,8 @@ import com.zfoo.storage.manager.StorageInt;
import com.zfoo.storage.manager.StorageManager;
import com.zfoo.storage.util.ExportUtils;
import com.zfoo.storage.util.LambdaUtils;
-import com.zfoo.storage.util.support.SerializableFunction;
+import com.zfoo.storage.util.PropertyNamer;
+import com.zfoo.storage.util.function.Func1;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.UnpooledHeapByteBuf;
import org.junit.Ignore;
@@ -96,7 +96,7 @@ public class ExportBinaryTesting {
storageManager.initBefore();
storageManager.initAfter();
- // 生成协议 TODO 协议
+ // 生成协议
var protocols = new HashSet>();
protocols.add(ResourceData.class);
protocols.addAll(storageManager.storageMap().keySet());
@@ -112,11 +112,13 @@ public class ExportBinaryTesting {
var bytes = ByteBufUtils.readAllBytes(buffer);
FileUtils.writeInputStreamToFile(new File("D:/github/godot-bird/binary_data.cfg"), new ByteArrayInputStream(bytes));
- String methodName = LambdaUtils.extract(StudentResource::age).getImplMethodName();
- String fieldName = ClassUtils.getFieldName(methodName);
+ Func1 ageFunc = StudentResource::age;
+ String methodName = LambdaUtils.extract(ageFunc).getImplMethodName();
+ String fieldName = PropertyNamer.methodToProperty(methodName);
System.out.println(methodName);
System.out.println(fieldName);
+
//获取storage对象
var storage = storageManager.getStorage(StudentResource.class);
//获取唯一索引的对象