diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-08-06 14:18:47 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-08-06 14:18:47 +0100 |
commit | 1ac9efbac6cd81dd7afb8bfb5672d5d7592af26d (patch) | |
tree | c350a01c581d2f8008deb14b275621449f91cbf2 /src/lua/lua_tensor.c | |
parent | 24e4be3ec08c4d0bd4bf23f3366817e71fc4f365 (diff) | |
download | rspamd-1ac9efbac6cd81dd7afb8bfb5672d5d7592af26d.tar.gz rspamd-1ac9efbac6cd81dd7afb8bfb5672d5d7592af26d.zip |
[Minor] Lua_tensor: Implement serialisation
Diffstat (limited to 'src/lua/lua_tensor.c')
-rw-r--r-- | src/lua/lua_tensor.c | 13 |
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"); |