Package io.github.eutro.jwasm
Class ModuleReader<E extends Exception>
java.lang.Object
io.github.eutro.jwasm.ModuleReader<E>
- Type Parameters:
E- The exception that may be thrown on read errors byaccept(ModuleVisitor).
A parser that makes a
ModuleVisitor visit a WebAssembly module structure.
This class parses a binary module's contents, calling the appropriate visit methods
of the ModuleVisitor and any other relevant *Visitors it returns.
-
Constructor Summary
ConstructorsConstructorDescriptionModuleReader(Supplier<ByteInputStream<E>> source) Construct aModuleReaderwith the given source of bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(ModuleVisitor mv) Make the givenModuleVisitorvisit the structure of the module.static ModuleReader<RuntimeException>fromBytes(byte[] b) Construct aModuleReaderthat reads from the given byte array.static ModuleReader<RuntimeException>fromBytes(byte[] b, int offset, int len) Construct aModuleReaderthat reads from a subarray of the given byte array, starting atoffsetwith a length oflenbytes.static ModuleReader<IOException>Construct aModuleReaderthat reads from the given input stream.
-
Constructor Details
-
ModuleReader
Construct aModuleReaderwith the given source of bytes.- Parameters:
source- The supplier ofByteInputStreams to read the module from.
-
-
Method Details
-
fromBytes
Construct aModuleReaderthat reads from the given byte array.- Parameters:
b- The byte array to read from.- Returns:
- The new
ModuleReader.
-
fromBytes
Construct aModuleReaderthat reads from a subarray of the given byte array, starting atoffsetwith a length oflenbytes.- Parameters:
b- The byte array to read from.offset- The offset of the subarray to use.len- The length of the subarray to use.- Returns:
- The new
ModuleReader.
-
fromInputStream
Construct aModuleReaderthat reads from the given input stream.The
accept(ModuleVisitor)method of the returnedModuleReadercan only be called once, or anIllegalStateExceptionwill be thrown.- Parameters:
is- The input stream to read from.- Returns:
- The new
ModuleReader.
-
accept
Make the givenModuleVisitorvisit the structure of the module.- Parameters:
mv- TheModuleVisitor.- Throws:
E- If theByteInputStreamthrows an error while reading.ValidationException- If the bytes represent an invalid module file that inhibits the parsing of the file. Not all invalid modules will cause this method to throw this exception, only those errors that prevent the parsing.
-