Function: nrepl--bencode-dict

nrepl--bencode-dict is a byte-compiled function defined in nrepl-bencode.el.

Signature

(nrepl--bencode-dict DICT)

Documentation

Encode DICT with bencode.

According to the Bittorrent protocol specification[1], when bencoding dictionaries, keys must be strings and appear in sorted order (sorted as raw strings, not alphanumerics).

Entries whose value is nil are left out: bencode has no nil, and an absent key is how the protocol says "not set". Pass an empty vector when an empty list is really meant.

[1] https://www.bittorrent.org/beps/bep_0003.html#bencoding

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20261106.1225/nrepl-bencode.el
;;; Encoding

(defun nrepl--bencode-dict (dict)
  "Encode DICT with bencode.
According to the Bittorrent protocol specification[1], when bencoding
dictionaries, keys must be strings and appear in sorted order (sorted as
raw strings, not alphanumerics).

Entries whose value is nil are left out: bencode has no nil, and an
absent key is how the protocol says \"not set\".  Pass an empty vector
when an empty list is really meant.

[1] https://www.bittorrent.org/beps/bep_0003.html#bencoding"
  (mapconcat (lambda (k)
               (let ((v (nrepl-dict-get dict k)))
                 (if v
                     (concat (nrepl-bencode k) (nrepl-bencode v))
                   "")))
             (sort (nrepl-dict-keys dict) #'string<)
             ""))