about summary refs log tree commit diff
path: root/nix/netstring/fromString.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nix/netstring/fromString.nix')
-rw-r--r--nix/netstring/fromString.nix10
1 files changed, 10 insertions, 0 deletions
diff --git a/nix/netstring/fromString.nix b/nix/netstring/fromString.nix
new file mode 100644
index 0000000000..dcd688a8b0
--- /dev/null
+++ b/nix/netstring/fromString.nix
@@ -0,0 +1,10 @@
+{ ... }:
+# convert any nix string into a netstring
+# (prefixed by its length) according to https://en.wikipedia.org/wiki/Netstring
+#
+# Examples:
+#   netstring.fromString "foo"
+#   => "3:foo,"
+#   netstring.fromString ""
+#   => "0:,"
+s: "${toString (builtins.stringLength s)}:${s},"