Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
 public void Write(ITreeWriter writer)
 {
     writer.WriteStartObject();
     writer.Write(Names.Count, Count);
     writer.WriteBlockArray(Names.Array, _array, 0, UsedArrayLength);
     writer.WriteEndObject();
 }
Ejemplo n.º 4
0
        public static void WriteDictionary <T>(this ITreeWriter writer, IReadOnlyDictionary <int, T> dictionary) where T : ITreeSerializable
        {
            if (dictionary == null)
            {
                writer.WriteNull(); return;
            }

            writer.WriteStartArray();

            int[] keys = dictionary.Keys.ToArray();
            writer.WriteBlockArray(keys);

            writer.WriteStartArray();

            for (int i = 0; i < keys.Length; ++i)
            {
                dictionary[keys[i]].Write(writer);
            }

            writer.WriteEndArray();

            writer.WriteEndArray();
        }
Ejemplo n.º 5
0
 public void Write(ITreeWriter writer)
 {
     writer.WriteBlockArray(Array, Index, Count);
 }
 public void Write(ITreeWriter writer)
 {
     writer.WriteBlockArray(Array);
 }
Ejemplo n.º 7
0
 public static void WriteBlockArray <T>(this ITreeWriter writer, string name, T[] array, int index = 0, int count = -1) where T : unmanaged
 {
     writer.WritePropertyName(name);
     writer.WriteBlockArray <T>(array, index, count);
 }