Interface LEB128Writer
-
public interface LEB128Writer
-
-
Field Summary
Fields Modifier and Type Field Description static long
COMPRESSED_INT_MASK
static int
EXT_BIT
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description int
capacity()
default byte[]
export()
Transfer the written data to a byte arrayvoid
export(Consumer<ByteBuffer> consumer)
Transfer the written data as a ByteBufferstatic LEB128Writer
getInstance()
Get a default LEB128Writer instanceint
length()
int
position()
void
reset()
Reset the writer.LEB128Writer
writeBoolean(boolean data)
Write Boolean data in default Java encodinglong
writeBoolean(long offset, boolean data)
Write Boolean data in default Java encoding at the given offsetLEB128Writer
writeByte(byte data)
Write Byte datalong
writeByte(long offset, byte data)
Write Byte data at the given offsetLEB128Writer
writeBytes(byte... data)
Write an array of Byte elementslong
writeBytes(long offset, byte... data)
Write an array of Byte elements at the given offsetLEB128Writer
writeChar(char data)
Write Character data in LEB128 encodinglong
writeChar(long offset, char data)
Write Character data in LEB128 encoding at the given offsetLEB128Writer
writeCompactUTF(byte[] utf8Data)
Write String byte array data in special encoding.long
writeCompactUTF(long offset, byte[] utf8Data)
Write String as a sequence of bytes representing UTF8 encoded string at the given offset.long
writeCompactUTF(long offset, String data)
Write String byte array data in special encoding at the given offset.LEB128Writer
writeCompactUTF(String data)
Write String in special encoding.LEB128Writer
writeDouble(double data)
Write Double data in default Java encodinglong
writeDouble(long offset, double data)
Write Double data in default Java encoding at the given offsetLEB128Writer
writeFloat(float data)
Write Float data in default Java encodinglong
writeFloat(long offset, float data)
Write Float data in default Java encoding at the given offsetLEB128Writer
writeInt(int data)
Write Integer data in LEB128 encodinglong
writeInt(long offset, int data)
Write Integer data in LEB128 encoding at the given offsetLEB128Writer
writeIntRaw(int data)
Write Integer data in default Java encodinglong
writeIntRaw(long offset, int data)
Write Integer data in default Java encoding at the given offsetLEB128Writer
writeLong(long data)
Write Long data in LEB128 encodinglong
writeLong(long offset, long data)
Write Long data in LEB128 encoding at the given offsetLEB128Writer
writeLongRaw(long data)
Write Long data in default Java encodinglong
writeLongRaw(long offset, long data)
Write Long data in default Java encoding at the given offsetlong
writeShort(long offset, short data)
Write Short data in LEB128 encoding at the given offsetLEB128Writer
writeShort(short data)
Write Short data in LEB128 encodinglong
writeShortRaw(long offset, short data)
Write Short data in default Java encoding at the given offsetLEB128Writer
writeShortRaw(short data)
Write Short data in default Java encodingLEB128Writer
writeUTF(byte[] utf8Data)
Write String byte array data as a sequence of bytes representing UTF8 encoded string.long
writeUTF(long offset, byte[] utf8Data)
Write String byte array data at the given offset.long
writeUTF(long offset, String data)
Write String as a sequence of bytes representing UTF8 encoded string at the given offset.LEB128Writer
writeUTF(String data)
Write String as a sequence of bytes representing UTF8 encoded string.
-
-
-
Field Detail
-
EXT_BIT
static final int EXT_BIT
- See Also:
- Constant Field Values
-
COMPRESSED_INT_MASK
static final long COMPRESSED_INT_MASK
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
static LEB128Writer getInstance()
Get a default LEB128Writer instance- Returns:
- a new instance of LEB128Writer
-
reset
void reset()
Reset the writer. Discard any collected data and set position to 0.
-
writeChar
LEB128Writer writeChar(char data)
Write Character data in LEB128 encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeChar
long writeChar(long offset, char data)
Write Character data in LEB128 encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeShort
LEB128Writer writeShort(short data)
Write Short data in LEB128 encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeShort
long writeShort(long offset, short data)
Write Short data in LEB128 encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeInt
LEB128Writer writeInt(int data)
Write Integer data in LEB128 encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeInt
long writeInt(long offset, int data)
Write Integer data in LEB128 encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeLong
LEB128Writer writeLong(long data)
Write Long data in LEB128 encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeLong
long writeLong(long offset, long data)
Write Long data in LEB128 encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeFloat
LEB128Writer writeFloat(float data)
Write Float data in default Java encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeFloat
long writeFloat(long offset, float data)
Write Float data in default Java encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeDouble
LEB128Writer writeDouble(double data)
Write Double data in default Java encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeDouble
long writeDouble(long offset, double data)
Write Double data in default Java encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeBoolean
LEB128Writer writeBoolean(boolean data)
Write Boolean data in default Java encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeBoolean
long writeBoolean(long offset, boolean data)
Write Boolean data in default Java encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeByte
LEB128Writer writeByte(byte data)
Write Byte data- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeByte
long writeByte(long offset, byte data)
Write Byte data at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeBytes
LEB128Writer writeBytes(byte... data)
Write an array of Byte elements- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeBytes
long writeBytes(long offset, byte... data)
Write an array of Byte elements at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeUTF
LEB128Writer writeUTF(String data)
Write String as a sequence of bytes representing UTF8 encoded string. The sequence starts with LEB128 encoded int for the length of the sequence followed by the sequence bytes.- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeUTF
LEB128Writer writeUTF(byte[] utf8Data)
Write String byte array data as a sequence of bytes representing UTF8 encoded string. The sequence starts with LEB128 encoded int for the length of the sequence followed by the sequence bytes.- Parameters:
utf8Data
- the byte array representation of an UTF8 string- Returns:
- the writer instance for chaining
-
writeUTF
long writeUTF(long offset, String data)
Write String as a sequence of bytes representing UTF8 encoded string at the given offset. The sequence starts with LEB128 encoded int for the length of the sequence followed by the sequence bytes.- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeUTF
long writeUTF(long offset, byte[] utf8Data)
Write String byte array data at the given offset. The sequence starts with LEB128 encoded int for the length of the sequence followed by the sequence bytes.- Parameters:
offset
- the offset from which to start writing the datautf8Data
- the byte array representation of an UTF8 string- Returns:
- the writer position after the data has been written
-
writeCompactUTF
LEB128Writer writeCompactUTF(byte[] utf8Data)
Write String byte array data in special encoding. The string will translate to (byte)0 for null value, (byte)1 for empty string and (byte)3 for the sequence of bytes representing UTF8 encoded string. The sequence starts with LEB128 encoded int for the length of the sequence followed by the sequence bytes.- Parameters:
utf8Data
- the byte array representation of an UTF8 string- Returns:
- the writer instance for chaining
-
writeCompactUTF
long writeCompactUTF(long offset, byte[] utf8Data)
Write String as a sequence of bytes representing UTF8 encoded string at the given offset. The sequence starts with LEB128 encoded int for the length of the sequence followed by the sequence bytes.- Parameters:
offset
- the offset from which to start writing the datautf8Data
- the byte array representation of an UTF8 string- Returns:
- the writer position after the data has been written
-
writeCompactUTF
LEB128Writer writeCompactUTF(String data)
Write String in special encoding. The string will translate to (byte)0 for null value, (byte)1 for empty string and (byte)3 for the sequence of bytes representing UTF8 encoded string. The sequence starts with LEB128 encoded int for the length of the sequence followed by the sequence bytes.- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeCompactUTF
long writeCompactUTF(long offset, String data)
Write String byte array data in special encoding at the given offset. The string will translate to (byte)0 for null value, (byte)1 for empty string and (byte)3 for the sequence of bytes representing UTF8 encoded string. The sequence starts with LEB128 encoded int for the length of the sequence followed by the sequence bytes.- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeShortRaw
LEB128Writer writeShortRaw(short data)
Write Short data in default Java encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeShortRaw
long writeShortRaw(long offset, short data)
Write Short data in default Java encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeIntRaw
LEB128Writer writeIntRaw(int data)
Write Integer data in default Java encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeIntRaw
long writeIntRaw(long offset, int data)
Write Integer data in default Java encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
writeLongRaw
LEB128Writer writeLongRaw(long data)
Write Long data in default Java encoding- Parameters:
data
- the data- Returns:
- the writer instance for chaining
-
writeLongRaw
long writeLongRaw(long offset, long data)
Write Long data in default Java encoding at the given offset- Parameters:
offset
- the offset from which to start writing the datadata
- the data- Returns:
- the writer position after the data has been written
-
export
default byte[] export()
Transfer the written data to a byte array- Returns:
- byte array containing the written data
-
export
void export(Consumer<ByteBuffer> consumer)
Transfer the written data as a ByteBuffer- Parameters:
consumer
- a ByteBuffer callback
-
position
int position()
- Returns:
- current writer position
-
length
int length()
- Returns:
- number of bytes written adjusted by the number of bytes necessary to encode the length itself
-
capacity
int capacity()
- Returns:
- the maximum number of bytes the writer can process
-
-