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 *Visitor
s it returns.
-
Constructor Summary
ConstructorDescriptionModuleReader
(Supplier<ByteInputStream<E>> source) Construct aModuleReader
with the given source of bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(ModuleVisitor mv) Make the givenModuleVisitor
visit the structure of the module.static ModuleReader<RuntimeException>
fromBytes
(byte[] b) Construct aModuleReader
that reads from the given byte array.static ModuleReader<RuntimeException>
fromBytes
(byte[] b, int offset, int len) Construct aModuleReader
that reads from a subarray of the given byte array, starting atoffset
with a length oflen
bytes.static ModuleReader<IOException>
Construct aModuleReader
that reads from the given input stream.
-
Constructor Details
-
ModuleReader
Construct aModuleReader
with the given source of bytes.- Parameters:
source
- The supplier ofByteInputStream
s to read the module from.
-
-
Method Details
-
fromBytes
Construct aModuleReader
that reads from the given byte array.- Parameters:
b
- The byte array to read from.- Returns:
- The new
ModuleReader
.
-
fromBytes
Construct aModuleReader
that reads from a subarray of the given byte array, starting atoffset
with a length oflen
bytes.- 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 aModuleReader
that reads from the given input stream.The
accept(ModuleVisitor)
method of the returnedModuleReader
can only be called once, or anIllegalStateException
will be thrown.- Parameters:
is
- The input stream to read from.- Returns:
- The new
ModuleReader
.
-
accept
Make the givenModuleVisitor
visit the structure of the module.- Parameters:
mv
- TheModuleVisitor
.- Throws:
E
- If theByteInputStream
throws 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.
-