Пример #1
0
        /// <summary>
        /// Reads the memory section with the given header.
        /// </summary>
        /// <param name="Header">The section header.</param>
        /// <param name="Reader">The WebAssembly file reader.</param>
        /// <returns>The parsed section.</returns>
        public static MemorySection ReadSectionPayload(SectionHeader Header, BinaryWasmReader Reader)
        {
            long startPos = Reader.Position;
            // Read the resizable limits.
            uint count  = Reader.ReadVarUInt32();
            var  limits = new List <MemoryType>();

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

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

            return(new MemorySection(limits, extraPayload));
        }
Пример #2
0
        /// <summary>
        /// Reads an imported value from the given binary WebAssembly reader.
        /// </summary>
        /// <param name="Reader">The WebAssembly reader.</param>
        /// <returns>The imported value that was read.</returns>
        public static ImportedValue ReadFrom(BinaryWasmReader Reader)
        {
            string moduleName = Reader.ReadString();
            string fieldName  = Reader.ReadString();
            var    kind       = (ExternalKind)Reader.ReadByte();

            switch (kind)
            {
            case ExternalKind.Function:
                return(new ImportedFunction(moduleName, fieldName, Reader.ReadVarUInt32()));

            case ExternalKind.Global:
                return(new ImportedGlobal(moduleName, fieldName, GlobalType.ReadFrom(Reader)));

            case ExternalKind.Memory:
                return(new ImportedMemory(moduleName, fieldName, MemoryType.ReadFrom(Reader)));

            case ExternalKind.Table:
                return(new ImportedTable(moduleName, fieldName, TableType.ReadFrom(Reader)));

            default:
                throw new WasmException("Unknown imported value kind: " + kind);
            }
        }