Example #1
0
        /// <summary>
        /// Serializes
        /// </summary>
        public void Serialize(BuildXLWriter writer)
        {
            Contract.Requires(writer != null);

            lock (m_pageStreams)
            {
                Serialize(writer, new SerializedState()
                {
                    Debug         = Debug,
                    PageStreams   = m_pageStreams,
                    ItemLocations = m_itemLocations,
                    LastId        = m_lastId,
                });
            }
        }
Example #2
0
        /// <summary>
        /// Serializes the StringTable
        /// </summary>
        /// <remarks>
        /// Not thread safe. The caller should ensure there are no concurrent accesses to the structure while serializing.
        /// </remarks>
        public void Serialize(BuildXLWriter writer)
        {
            Contract.Requires(writer != null);

            m_isSerializationInProgress = true;
            // Call a static method to do the actual serialization to ensure not state outside of SerializedState is used
            Serialize(
                writer,
                new SerializedState()
            {
                Count       = Count,
                NextId      = m_nextId,
                StringSet   = m_stringSet,
                ByteBuffers = m_byteBuffers,
            });
            m_isSerializationInProgress = false;
        }
Example #3
0
        private static void Serialize(BuildXLWriter writer, SerializedState state)
        {
            writer.Write(state.Debug);

            var count = state.PageStreams.Count;

            writer.Write(count);
            foreach (var stream in state.PageStreams)
            {
                writer.Write(stream.Length);
            }

            long position = writer.BaseStream.Position;

            // Serialize each stream and assign it an identifier that can be looked up later
            var pageStreamIdentifiers = new Dictionary <PageStreamBase, int>();

            for (int i = 0; i < count; i++)
            {
                pageStreamIdentifiers.Add(state.PageStreams[i], i);
                state.PageStreams[i].Serialize(writer);
                var expectedPosition = position + state.PageStreams[i].Length;
                Contract.Assert(expectedPosition == writer.BaseStream.Position);
                position = expectedPosition;
            }

            // Serialize the item location offsets
            writer.Write(state.LastId);
            for (uint i = 0; i < state.LastId; i++)
            {
                ItemLocation offset = state.ItemLocations[i + 1];
                var          id     = pageStreamIdentifiers[offset.PageStream];
                writer.Write(id);
                writer.Write(offset.Offset);
            }
        }
 /// <nodoc />
 public StreamBinaryWriter()
 {
     Buffer = new MemoryStream();
     Writer = BuildXLWriter.Create(Buffer);
 }
Example #5
0
 /// <summary>
 /// Serialzies this instance.
 /// </summary>
 public void Serialize(BuildXLWriter writer) => writer.Write(Value);
Example #6
0
 internal void Serialize(BuildXLWriter writer)
 {
     Contract.RequiresNotNull(writer);
     writer.WriteCompact(Line);
     writer.WriteCompact(Position);
 }