Esempio n. 1
0
        private void ConnectPage(PageObject page, BBeB book)
        {
            Debug.WriteLineIf(s_bDebugMode, "Connecting page: " + page.ID);

            UInt32ArrayTag childIDs = (UInt32ArrayTag)page.FindFirstTag(TagId.PageObjectIds);

            if (childIDs != null)
            {
                foreach (uint id in childIDs.Value)
                {
                    BBeBObject child = book.FindObject((ushort)id);
                    if (child == null)
                    {
                        throw new InvalidBookException("Can't find object id " + id);
                    }

                    Debug.Assert(child.ID == id);

                    Debug.WriteLineIf(s_bDebugMode, "   Child: " + child.GetType().ToString() + " - id:" + child.ID);
                    page.Children.Add(child);
                }
            }

            UInt32Tag objInfoTag = (UInt32Tag)page.FindFirstTag(TagId.ObjectInfoLink);

            if (objInfoTag != null)
            {
                page.InfoObj = book.FindObject((ushort)objInfoTag.Value);
                if (page.InfoObj == null)
                {
                    throw new InvalidBookException("Can't find info object id " + objInfoTag.Value);
                }
            }

            StreamTagGroup stream = (StreamTagGroup)page.FindFirstTag(TagId.StreamGroup);

            if (stream != null)
            {
                BBeBObject tempObj = new BBeBObject(0x0);

                page.StreamTags = BBeBTagFactory.ParseAllTags(tempObj, stream.Data);
            }

            UInt32Tag linkTag = (UInt32Tag)page.FindFirstTag(TagId.Link);

            if (linkTag != null)
            {
                BBeBObject linkedObj = book.FindObject((ushort)linkTag.Value);
                if (linkedObj == null)
                {
                    throw new InvalidBookException("Can't find object id " + linkTag.Value);
                }
                page.LinkObj = linkedObj;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Read a group of stream tags (which all come in order) from the BBeB reader.
        /// </summary>
        /// <param name="tagReader">The reader to do the reading with</param>
        /// <returns>A new tag representing the uncompressed data in the stream.</returns>
        public static StreamTagGroup Deserialize(BBeBinaryReader tagReader, ObjectType eObjectType)
        {
            ushort wFlags = tagReader.ReadUInt16();

            StreamFormatFlags eStreamFlags = (StreamFormatFlags)(wFlags & 0xff00);
            StreamContents    eContents    = (StreamContents)(wFlags & 0x00ff);

            TagId eTagId = tagReader.ReadTag();

            if (eTagId != TagId.StreamSize)
            {
                throw new UnexpectedTagException("Expected a StreamSize tag: " + eTagId.ToString());
            }

            uint dwStreamSize = tagReader.ReadUInt32();

            eTagId = tagReader.ReadTag();
            if (eTagId != TagId.StreamStart)
            {
                throw new UnexpectedTagException("Expected a StreamStart tag: " + eTagId.ToString());
            }

            byte[] streamData = tagReader.ReadBytes((int)dwStreamSize);

            try
            {
                eTagId = tagReader.ReadTag();
            }
            catch (InvalidTagException ex)
            {
                Debug.WriteLineIf(s_bDebugMode, "Not a tag at end of stream: 0x" + ex.Value.ToString("x"));
                // dataTag.AppendShort(ex.Value);

                // Temporarily
                eTagId = TagId.StreamEnd;
            }
            if (eTagId != TagId.StreamEnd)
            {
                throw new UnexpectedTagException("Expected a StreamEnd tag: " + eTagId.ToString());
            }

            StreamTagGroup tag = new StreamTagGroup();

            tag.Contents = eContents;

            StreamTagSerializer streamTagSerializer = new StreamTagSerializer();

            tag.Data = streamTagSerializer.Convert(streamData, eStreamFlags,
                                                   StreamFormatFlags.None, eObjectType);

            return(tag);
        }
Esempio n. 3
0
        public static void Serialize(BBeBinaryWriter writer, StreamTagGroup tagGroup)
        {
            writer.Write(TagId.StreamFlags);

            ushort wFlags = (ushort)((ushort)(tagGroup.Contents) | (ushort)(StreamFormatFlags.None));

            writer.Write(wFlags);

            writer.Write(TagId.StreamSize);
            writer.Write((uint)tagGroup.Data.Length);

            writer.Write(TagId.StreamStart);

            writer.Write(tagGroup.Data);

            writer.Write(TagId.StreamEnd);
        }