Interface LEB128Writer
-
public interface LEB128Writer
-
-
Field Summary
Fields Modifier and Type Field Description static longCOMPRESSED_INT_MASKstatic intEXT_BIT
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description intcapacity()default byte[]export()Transfer the written data to a byte arrayvoidexport(Consumer<ByteBuffer> consumer)Transfer the written data as a ByteBufferstatic LEB128WritergetInstance()Get a default LEB128Writer instanceintlength()intposition()voidreset()Reset the writer.LEB128WriterwriteBoolean(boolean data)Write Boolean data in default Java encodinglongwriteBoolean(long offset, boolean data)Write Boolean data in default Java encoding at the given offsetLEB128WriterwriteByte(byte data)Write Byte datalongwriteByte(long offset, byte data)Write Byte data at the given offsetLEB128WriterwriteBytes(byte... data)Write an array of Byte elementslongwriteBytes(long offset, byte... data)Write an array of Byte elements at the given offsetLEB128WriterwriteChar(char data)Write Character data in LEB128 encodinglongwriteChar(long offset, char data)Write Character data in LEB128 encoding at the given offsetLEB128WriterwriteCompactUTF(byte[] utf8Data)Write String byte array data in special encoding.longwriteCompactUTF(long offset, byte[] utf8Data)Write String as a sequence of bytes representing UTF8 encoded string at the given offset.longwriteCompactUTF(long offset, String data)Write String byte array data in special encoding at the given offset.LEB128WriterwriteCompactUTF(String data)Write String in special encoding.LEB128WriterwriteDouble(double data)Write Double data in default Java encodinglongwriteDouble(long offset, double data)Write Double data in default Java encoding at the given offsetLEB128WriterwriteFloat(float data)Write Float data in default Java encodinglongwriteFloat(long offset, float data)Write Float data in default Java encoding at the given offsetLEB128WriterwriteInt(int data)Write Integer data in LEB128 encodinglongwriteInt(long offset, int data)Write Integer data in LEB128 encoding at the given offsetLEB128WriterwriteIntRaw(int data)Write Integer data in default Java encodinglongwriteIntRaw(long offset, int data)Write Integer data in default Java encoding at the given offsetLEB128WriterwriteLong(long data)Write Long data in LEB128 encodinglongwriteLong(long offset, long data)Write Long data in LEB128 encoding at the given offsetLEB128WriterwriteLongRaw(long data)Write Long data in default Java encodinglongwriteLongRaw(long offset, long data)Write Long data in default Java encoding at the given offsetlongwriteShort(long offset, short data)Write Short data in LEB128 encoding at the given offsetLEB128WriterwriteShort(short data)Write Short data in LEB128 encodinglongwriteShortRaw(long offset, short data)Write Short data in default Java encoding at the given offsetLEB128WriterwriteShortRaw(short data)Write Short data in default Java encodingLEB128WriterwriteUTF(byte[] utf8Data)Write String byte array data as a sequence of bytes representing UTF8 encoded string.longwriteUTF(long offset, byte[] utf8Data)Write String byte array data at the given offset.longwriteUTF(long offset, String data)Write String as a sequence of bytes representing UTF8 encoded string at the given offset.LEB128WriterwriteUTF(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
-
-