public void Write(ITreeWriter writer)
        {
            Trim();

            writer.WriteStartObject();

            if (Count > 0)
            {
                int nullValueCount = IsNull.CountTrue;

                if (nullValueCount == Count)
                {
                    // If all null, write IsNull only (default is already all null)
                    writer.Write(Names.IsNull, IsNull);
                }
                else if (nullValueCount == 0)
                {
                    // If no nulls, write values only (will infer situation on read)
                    writer.Write(Names.Values, Values);
                }
                else
                {
                    // If there are some nulls and some values, we must write both
                    writer.Write(Names.IsNull, IsNull);
                    writer.Write(Names.Values, Values);
                }
            }

            writer.WriteEndObject();
        }
Exemple #2
0
 public void Write(ITreeWriter writer)
 {
     writer.WriteStartObject();
     writer.Write(Names.Count, Count);
     writer.WriteBlockArray(Names.Array, _array, 0, UsedArrayLength);
     writer.WriteEndObject();
 }
        public void Write(ITreeWriter writer)
        {
            // Merge changed small values under cutoff into SmallValueArray
            Trim();

            writer.WriteStartObject();

            if (_smallValueArray?.Length > 0)
            {
                // If there are any non-empty values, write the text and end positions
                writer.WriteBlockArray(Names.ValueEnd, _valueEndInPage);
                writer.WriteBlockArray(Names.SmallValues, _smallValueArray);

                // If there is more than one page, write page starts
                int pages = (Count / PageRowCount) + 1;
                if (pages > 1)
                {
                    writer.WriteBlockArray(Names.PageStart, _pageStartInChapter);
                }
            }
            else if (Count > 0)
            {
                // If there is no text but a non-zero count, we must preserve the count
                writer.Write(Names.Count, Count);
            }

            // If there are any large values, write them
            if (_largeValueDictionary?.Count > 0)
            {
                writer.WritePropertyName(Names.LargeValues);
                writer.WriteDictionary(_largeValueDictionary);
            }

            writer.WriteEndObject();
        }
Exemple #4
0
        public void Write(ITreeWriter writer)
        {
            writer.WriteStartObject();

            if (DefaultValue == false && Count == 0)
            {
                // If all values are default false, only write Capacity; Count defaults back to zero on read
                writer.Write(Names.Capacity, Capacity);
            }
            else if (DefaultValue == true && Count == Capacity)
            {
                // If all values are default true, only write Count+Capacity (Array will be re-created with all default)
                writer.Write(Names.Count, Count);
                writer.Write(Names.Capacity, Capacity);
            }
            else if (Capacity > 0)
            {
                writer.Write(Names.Count, Count);
                writer.Write(Names.Capacity, Capacity);
                writer.WritePropertyName(Names.Array);
                writer.WriteBlockArray(Array, 0, Math.Min(Array.Length, (Capacity + 31) >> 5));
            }

            writer.WriteEndObject();
        }
Exemple #5
0
 public void Write(ITreeWriter writer)
 {
     writer.WriteStartObject();
     writer.Write(Names.Indices, _indices);
     writer.Write(Names.Values, _values);
     writer.WriteEndObject();
 }
Exemple #6
0
 public void Write(ITreeWriter writer)
 {
     writer.WriteStartObject();
     writer.Write(Names.Keys, _keys);
     writer.Write(Names.Values, _values);
     writer.Write(Names.Pairs, _pairs);
     writer.WriteEndObject();
 }
Exemple #7
0
        public void Write(ITreeWriter writer)
        {
            writer.WriteStartObject();

            writer.Write(Names.Count, Count);

            // Write non-empty columns only
            writer.WritePropertyName(Names.Columns);
            writer.WriteStartObject();

            foreach (var pair in Columns)
            {
                if (pair.Value.Count > 0)
                {
                    writer.Write(pair.Key, pair.Value);
                }
            }

            writer.WriteEndObject();

            writer.WriteEndObject();
        }
 public void Write(ITreeWriter writer)
 {
     writer.WriteStartObject();
     writer.Write(nameof(IsActive), IsActive);
     writer.Write(nameof(Name), Name);
     writer.Write(nameof(Position), Position);
     writer.Write(nameof(Age), Age);
     writer.Write(nameof(Type), Type);
     writer.Write(nameof(Count), Count);
     writer.Write(nameof(When), When);
     writer.Write(nameof(Guid), Guid);
     writer.WriteEndObject();
 }
        public void Write(ITreeWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(List));
            writer.WriteList(List);

            writer.WritePropertyName(nameof(StringDictionary));
            writer.WriteDictionary(StringDictionary);

            writer.WritePropertyName(nameof(IntDictionary));
            writer.WriteDictionary(IntDictionary);

            writer.WriteEndObject();
        }
Exemple #10
0
        public void Write(ITreeWriter writer)
        {
            // Write non-empty tables only
            writer.WriteStartObject();

            foreach (var pair in Tables)
            {
                if (pair.Value.Count > 0)
                {
                    writer.WritePropertyName(pair.Key);
                    pair.Value.Write(writer);
                }
            }

            writer.WriteEndObject();
        }
Exemple #11
0
        public static void WriteDictionary <T>(this ITreeWriter writer, IReadOnlyDictionary <string, T> dictionary) where T : ITreeSerializable
        {
            if (dictionary == null)
            {
                writer.WriteNull(); return;
            }

            writer.WriteStartObject();

            foreach (var item in dictionary)
            {
                writer.WritePropertyName(item.Key);
                item.Value.Write(writer);
            }

            writer.WriteEndObject();
        }
 public void Write(ITreeWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteEndObject();
 }
 public void Write(ITreeWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteObject(nameof(Item), this.Item);
     writer.WriteEndObject();
 }