Closed acruikshank closed 4 years ago
I think I agree with @Stebalien , this value should always be set and never should be serialized as nil.
Fix for byte arrays: https://github.com/whyrusleeping/cbor-gen/pull/29
Fix merged.
Fix pushed. Could you take a look at this @whyrusleeping and @acruikshank?
closes #18
Motivation
Actions like calling
ForEach
or adding and removing elements put an empty AMT into a state that causes it to be serialized differently even though it is still the empty array. This is because these actions causeexpVals
to be expanded in the node from a nil value to a slice with nil values. WhileexpVals
isn't itself serialized, The fact that it is non-nil causes the node'sBmap
value to be initialized from a nil value to[]byte{0}
inFlush
, and that does serialize differently.Proposed Changes
Node.Bmap
lazily inFlush
.This is probably the simplest solution that fixes the problem. It leaves open a bigger question about whether empty nodes should be structurally different when serialized from nodes containing one or more elements. I find it a little surprising, but not really wrong.