diff --git a/src/octet/spec.cljc b/src/octet/spec.cljc index f315939..0fe2802 100644 --- a/src/octet/spec.cljc +++ b/src/octet/spec.cljc @@ -73,9 +73,9 @@ (size* [_ data] (reduce (fn [acc [field data]] (let [type (field dict)] - (if (satisfies? ISpecSize type) - (+ acc (size type)) - (+ acc (size* type data))))) + (if (satisfies? ISpecDynamicSize type) + (+ acc (size* type data)) + (+ acc (size type))))) 0 (into [] data))) diff --git a/test/octet/tests/core.cljc b/test/octet/tests/core.cljc index 556fd75..c561a71 100644 --- a/test/octet/tests/core.cljc +++ b/test/octet/tests/core.cljc @@ -466,6 +466,16 @@ (t/is (= readed 24)) (t/is (= data [1 2 3 4 5]))))) +(t/deftest spec-associative-nested-dynamic + (let [spec (buf/spec :outer (buf/spec :inner (buf/vector* buf/int32))) + buffer (buf/into (buf/spec :outer (buf/spec :inner (buf/vector* buf/int32))) {:outer {:inner [1]}}) + written (impl/get-capacity buffer)] + (t/is (= written 8)) + + (let [[readed data] (buf/read* buffer spec)] + (t/is (= readed 8) + (t/is (= data {:outer {:inner [1]}})))))) + #?(:cljs (do (enable-console-print!)