From 4ac38a7598fc1c15f578129e7ca1d673ed4fe610 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Wed, 11 Nov 2020 00:45:59 +0100 Subject: [PATCH] Unmapped values are taken into account in the object mapping size. --- src/cbor/serializable.cr | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cbor/serializable.cr b/src/cbor/serializable.cr index 77d0689..b1fe894 100644 --- a/src/cbor/serializable.cr +++ b/src/cbor/serializable.cr @@ -244,6 +244,10 @@ module CBOR raise ::CBOR::SerializationError.new("Unknown CBOR attribute: #{key}", self.class.to_s, nil) end + protected def get_cbor_unmapped + {} of String => ::CBOR::Type + end + protected def on_to_cbor(cbor : ::CBOR::Encoder) end @@ -283,6 +287,7 @@ module CBOR {% end %} # macro unless value[:emit_null] {% end %} # macro for properties + nb_properties_to_serialize += get_cbor_unmapped.size {% if properties.size > 0 %} @@ -329,6 +334,10 @@ module CBOR end end + protected def get_cbor_unmapped + cbor_unmapped + end + protected def on_to_cbor(cbor : ::CBOR::Encoder) cbor_unmapped.each do |key, value| cbor.write(key)