Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the export 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 ExportSection ReadSectionPayload(
            SectionHeader header, BinaryWasmReader reader)
        {
            long startPos = reader.Position;
            // Read the function indices.
            uint count        = reader.ReadVarUInt32();
            var  exportedVals = new List <ExportedValue>();

            for (uint i = 0; i < count; i++)
            {
                exportedVals.Add(
                    new ExportedValue(
                        reader.ReadString(),
                        (ExternalKind)reader.ReadByte(),
                        reader.ReadVarUInt32()));
            }

            // Skip any remaining bytes.
            var extraPayload = reader.ReadRemainingPayload(startPos, header);

            return(new ExportSection(exportedVals, extraPayload));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Reads a module name entry's payload.
 /// </summary>
 /// <param name="Reader">The reader to read the name entry payload from.</param>
 /// <param name="Length">The length of the name entry's payload, in bytes.</param>
 /// <returns>A module name entry.</returns>
 public static ModuleNameEntry ReadPayload(BinaryWasmReader Reader, uint Length)
 {
     return(new ModuleNameEntry(Reader.ReadString()));
 }