Function: nrepl-bencode

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

Signature

(nrepl-bencode OBJECT)

Documentation

Encode OBJECT with bencode.

Integers, lists, vectors and nrepl-dicts are treated according to bencode specification (vectors encode as lists, so [] is the way to spell an empty list where nil would be dropped from a dict). Everything else is coerced to a string via format and encoded as such.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20261106.1225/nrepl-bencode.el
(defun nrepl-bencode (object)
  "Encode OBJECT with bencode.
Integers, lists, vectors and nrepl-dicts are treated according to bencode
specification (vectors encode as lists, so [] is the way to spell an empty
list where nil would be dropped from a dict).  Everything else is coerced
to a string via `format' and encoded as such."
  (cond
   ((integerp object) (format "i%de" object))
   ((nrepl-dict-p object) (format "d%se" (nrepl--bencode-dict object)))
   ((or (listp object) (vectorp object))
    (format "l%se" (mapconcat #'nrepl-bencode object "")))
   (t (let ((s (if (stringp object) object (format "%s" object))))
        (format "%s:%s" (string-bytes s) s)))))