aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-08-06 14:18:47 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-08-06 14:18:47 +0100
commit1ac9efbac6cd81dd7afb8bfb5672d5d7592af26d (patch)
treec350a01c581d2f8008deb14b275621449f91cbf2 /src/lua
parent24e4be3ec08c4d0bd4bf23f3366817e71fc4f365 (diff)
downloadrspamd-1ac9efbac6cd81dd7afb8bfb5672d5d7592af26d.tar.gz
rspamd-1ac9efbac6cd81dd7afb8bfb5672d5d7592af26d.zip
[Minor] Lua_tensor: Implement serialisation
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_tensor.c13
1 files changed, 13 insertions, 0 deletions
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");