public static void WriteDictionaryTree <TKey, TValue>(this BitStream stream, DTree <TKey, TValue> tree,
                                                              Action <Stream, KeyValuePair <TKey, TValue> > writeValue)
        {
            var ie = tree.GetBreadthFirstEnumerator();

            while (ie.MoveNext())
            {
                var node = ie.Current;
                if (node == null)
                {
                    stream.WriteBit(true);
                }
                else
                {
                    stream.WriteBit(false);
                    var isValueNull = (node.Value.Key == null && node.Value.Value == null);
                    stream.WriteBit(isValueNull);
                    if (node.Children == null)
                    {
                        stream.WriteDeltaCode(0);
                    }
                    else
                    {
                        stream.WriteDeltaCode(node.Children.Count);
                    }
                    if (!isValueNull)
                    {
                        writeValue(stream, node.Value);
                    }
                }
            }
        }
        public static void WriteDictionaryTree <TKey, TValue>(this Stream stream, DTree <TKey, TValue> tree,
                                                              Action <Stream, KeyValuePair <TKey, TValue> > writeValue)
        {
            var ie = tree.GetBreadthFirstEnumerator();

            while (ie.MoveNext())
            {
                var node = ie.Current;
                if (node == null)
                {
                    stream.WriteByte(1);
                }
                else
                {
                    byte tag         = 0;
                    var  isValueNull = (node.Value.Key == null && node.Value.Value == null);
                    tag = tag.SetBit(1, isValueNull);
                    stream.WriteByte(tag);
                    if (node.Children == null)
                    {
                        stream.WriteInt32(0);
                    }
                    else
                    {
                        stream.WriteInt32(node.Children.Count);
                    }
                    if (!isValueNull)
                    {
                        writeValue(stream, node.Value);
                    }
                }
            }
        }