Example #1
0
        /// <summary>
        /// Adds a element segment to this module's element section, defining
        /// a new element section if one doesn't exist already.
        /// </summary>
        /// <param name="segment">The element segment to add.</param>
        /// <returns>The index in the element section of the newly added element segment.</returns>
        public uint AddElementSegment(ElementSegment segment)
        {
            var elements = GetFirstSectionOrNull <ElementSection>();

            if (elements == null)
            {
                InsertSection(elements = new ElementSection());
            }
            elements.Segments.Add(segment);
            return((uint)elements.Segments.Count - 1);
        }
Example #2
0
        /// <summary>
        /// Reads the element section with the given header.
        /// </summary>
        /// <param name="Header">The section header.</param>
        /// <param name="Reader">A reader for a binary WebAssembly file.</param>
        /// <returns>The parsed section.</returns>
        public static ElementSection ReadSectionPayload(
            SectionHeader Header, BinaryWasmReader Reader)
        {
            long startPos = Reader.Position;
            // Read the element segments.
            uint count    = Reader.ReadVarUInt32();
            var  segments = new List <ElementSegment>();

            for (uint i = 0; i < count; i++)
            {
                segments.Add(ElementSegment.ReadFrom(Reader));
            }

            // Skip any remaining bytes.
            var extraPayload = Reader.ReadRemainingPayload(startPos, Header);

            return(new ElementSection(segments, extraPayload));
        }