コード例 #1
0
        public byte[] Serialize()
        {
            MemoryStream    stream = new MemoryStream();
            BBeBinaryWriter writer = new BBeBinaryWriter(stream);

            writer.Write(TagId.KomaPlot);
            writer.Write(m_wHeight);
            writer.Write(m_wWidth);
            writer.Write(m_dwRefObj);
            writer.Write(m_dwUnknown);
            writer.Flush();

            byte[] data = new byte[stream.Position];
            Array.Copy(stream.GetBuffer(), data, stream.Position);

            return(data);
        }
コード例 #2
0
ファイル: TocObject.cs プロジェクト: koson/reader
        /// <summary>
        /// Serialize the list of TOC entries into a stream, and add that stream
        /// as a tag (really 3 tags) to this objects tags list.
        /// </summary>
        public void Serialize()
        {
            Tags.Add(new UInt16Tag(TagId.StreamFlags, (ushort)StreamContents.TableOfContents));

            Debug.Assert(FindFirstTag(TagId.StreamStart) == null);

            MemoryStream    stream = new MemoryStream();
            BBeBinaryWriter writer = new BBeBinaryWriter(stream);

            writer.Write((uint)m_Entries.Count);

            uint[] offsets = new uint[m_Entries.Count];

            // Now write out the entry offsets which we don't know yet
            // We'll come back later and overwrite
            foreach (uint offset in offsets)
            {
                writer.Write(offset);
            }

            writer.Flush();
            long dwEndOfTablePos = writer.BaseStream.Position;

            uint idx = 0;

            foreach (TocLabelEntry entry in m_Entries)
            {
                writer.Flush();
                offsets[idx] = (uint)(writer.Position - dwEndOfTablePos);

                writer.Write(entry.RefPage);
                writer.Write(entry.RefObj);
                writer.Write(entry.Text);

                idx++;
            }

            writer.Flush();
            long endPos = writer.Position;

            // Now go back and overwrite the offset table
            writer.Position = sizeof(uint);

            foreach (uint offset in offsets)
            {
                writer.Write(offset);
            }

            writer.Close();

            byte[] data = new byte[endPos];
            Array.Copy(stream.GetBuffer(), data, endPos);

            Tags.Add(new UInt32Tag(TagId.StreamSize, (uint)endPos));
            Tags.Add(new ByteArrayTag(TagId.StreamStart, data));
            Tags.Add(new IDOnlyTag(TagId.StreamEnd));
        }