Changeset

4818:d66162e850cd

mod_export_skeletons: Generate ids based on log2 of the original length
author Kim Alvefur <zash@zash.se>
date Fri, 10 Dec 2021 00:14:12 +0100
parents 4817:e8e0cb97c480
children 4819:b1882a40c246
files mod_export_skeletons/README.md mod_export_skeletons/mod_export_skeletons.lua
diffstat 2 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_export_skeletons/README.md	Fri Dec 10 00:04:56 2021 +0100
+++ b/mod_export_skeletons/README.md	Fri Dec 10 00:14:12 2021 +0100
@@ -35,7 +35,8 @@
 Top level attributes are given special treatment since they carry
 protocol semantics. Notably the `@to` and `@from` JIDs are replaced by
 symbolic labels to convey what form (bare, full or host) they had. The
-`@id` attribute is replaced with a string of the same length.
+`@id` attribute is replaced with a string with the length based on log2
+of the original length.
 
 ## Example
 
--- a/mod_export_skeletons/mod_export_skeletons.lua	Fri Dec 10 00:04:56 2021 +0100
+++ b/mod_export_skeletons/mod_export_skeletons.lua	Fri Dec 10 00:14:12 2021 +0100
@@ -61,7 +61,7 @@
 			-- Normalize top level attributes
 			clean.attr.type = item.attr.type;
 			if clean.attr.type == nil and clean.name == "message" then clean.attr.type = "normal"; end
-			clean.attr.id = string.rep("x", #(item.attr.id or "")); -- worth rounding to nearest power of two or so?
+			clean.attr.id = string.rep("x", math.floor(math.log(1+#(item.attr.id or ""), 2)));
 			clean.attr.from = classify_jid(item.attr.from);
 			clean.attr.to = classify_jid(item.attr.to);
 			print(clean);