commit 1ac9efb: [Minor] Lua_tensor: Implement serialisation

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Aug 6 13:49:07 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-08-06 14:18:47 +0100
URL: https://github.com/rspamd/rspamd/commit/1ac9efbac6cd81dd7afb8bfb5672d5d7592af26d

[Minor] Lua_tensor: Implement serialisation

---
 src/lua/lua_tensor.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/lua/lua_tensor.c b/src/lua/lua_tensor.c
index 85aaa2e95..9b85779d7 100644
--- a/src/lua/lua_tensor.c
+++ b/src/lua/lua_tensor.c
@@ -236,7 +236,20 @@ lua_tensor_save (lua_State *L)
 	struct rspamd_lua_tensor *t = lua_check_tensor (L, 1);
 
 	if (t) {
+		gsize sz = sizeof (gint) * 4 + t->size * sizeof (rspamd_tensor_num_t);
+		guchar *data;
 
+		struct rspamd_lua_text *out = lua_new_text (L, NULL, 0, TRUE);
+
+		data = g_malloc (sz);
+		memcpy (data, &t->ndims, sizeof (int));
+		memcpy (data + sizeof (int), &t->size, sizeof (int));
+		memcpy (data + 2 * sizeof (int), t->dim, sizeof (int) * 2);
+		memcpy (data + 4 * sizeof (int), t->data,
+				t->size * sizeof (rspamd_tensor_num_t));
+
+		out->start = (const gchar *)data;
+		out->len = sz;
 	}
 	else {
 		return luaL_error (L, "invalid arguments");


More information about the Commits mailing list