mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-26 07:49:28 +01:00
add writeString()
This commit is contained in:
parent
a10d029e00
commit
3c2ec0f516
@ -22,6 +22,7 @@ import java.io.OutputStream;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import javax.annotation.Nonnegative;
|
import javax.annotation.Nonnegative;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import de.inetsoftware.jwebassembly.module.ValueType;
|
import de.inetsoftware.jwebassembly.module.ValueType;
|
||||||
|
|
||||||
@ -182,6 +183,20 @@ class WasmOutputStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a string as UTF8 encoded.
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* the string
|
||||||
|
* @throws IOException
|
||||||
|
* if any I/O error occur
|
||||||
|
*/
|
||||||
|
void writeString( @Nonnull String str ) throws IOException {
|
||||||
|
byte[] bytes = str.getBytes( StandardCharsets.UTF_8 );
|
||||||
|
writeVaruint32( bytes.length );
|
||||||
|
write( bytes );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a section with header and data.
|
* Write a section with header and data.
|
||||||
*
|
*
|
||||||
@ -203,9 +218,7 @@ class WasmOutputStream extends FilterOutputStream {
|
|||||||
writeVaruint32( type.ordinal() );
|
writeVaruint32( type.ordinal() );
|
||||||
writeVaruint32( size );
|
writeVaruint32( size );
|
||||||
if( type == SectionType.Custom ) {
|
if( type == SectionType.Custom ) {
|
||||||
byte[] bytes = name.getBytes( StandardCharsets.UTF_8 );
|
writeString( name );
|
||||||
writeVaruint32( bytes.length );
|
|
||||||
write( bytes );
|
|
||||||
}
|
}
|
||||||
baos.writeTo( this );
|
baos.writeTo( this );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user