[#126] extend-freeze: include id collision odds in docstring

This commit is contained in:
Peter Taoussanis 2020-07-25 12:54:50 +02:00
parent cf84a441f4
commit 040da54936

View file

@ -1635,6 +1635,7 @@
;; Make sure hash ids can't collide with byte ids (unlikely anyway):
(assert (not (<= -128 short-hash-id -1))
"Custom type id hash collision; please choose a different id")
(int short-hash-id))))
(comment (coerce-custom-type-id 77)
@ -1643,8 +1644,9 @@
(defmacro extend-freeze
"Extends Nippy to support freezing of a custom type (ideally concrete) with
given id of form:
* Keyword - 2 byte overhead, resistent to id collisions
* Integer [1, 128] - no overhead, subject to id collisions
* Keyword - 2 byte overhead, keywords hashed to 16 bit id
* [1, 128] - 0 byte overhead
NB: be careful about extending to interfaces, Ref. http://goo.gl/6gGRlU.
@ -1654,6 +1656,7 @@
;; or
(extend-freeze MyRec 1 [x data-output] ; Byte id
(.writeUTF [data-output] (:data x)))"
[type custom-type-id [x out] & body]
(assert-custom-type-id custom-type-id)
(let [write-id-form