java.lang.Object
net.i2p.router.transport.ntcp.NTCP2Payload.Block
- Direct Known Subclasses:
NTCP2Payload.DateTimeBlock, NTCP2Payload.I2NPBlock, NTCP2Payload.OptionsBlock, NTCP2Payload.PaddingBlock, NTCP2Payload.RIBlock, NTCP2Payload.TerminationBlock
- Enclosing class:
NTCP2Payload
Base class for NTCP 2 payload blocks to be transmitted. Not used for receive; we use callbacks instead.
Field Summary
FieldsConstructor Summary
ConstructorsConstructorDescriptionBlock(int ttype) Stores the type byte written as the block's first header byte.Method Summary
Modifier and TypeMethodDescriptionabstract intSize of the data, which becomes the length field of the block header.intHow many bytes the whole block occupies in a frame.toString()String representation of this block.intwrite(byte[] tgt, int off) Write the block to the target array, returning the new offset.abstract intwriteData(byte[] tgt, int off) Write the block data to the target array, returning the new offset.
Field Details
type
private final int typeType of the block being read or written.
Constructor Details
Block
public Block(int ttype) Stores the type byte written as the block's first header byte.- Parameters:
ttype- the block type byte, written as the first header byte
Method Details
write
public int write(byte[] tgt, int off) Write the block to the target array, returning the new offset.- Parameters:
tgt- the destination arrayoff- index in tgt to write the 3-byte block header at- Returns:
- the offset just past the block's data
getTotalLength
public int getTotalLength()How many bytes the whole block occupies in a frame.- Returns:
- the size of the block, including the 3 byte header (type and size)
getDataLength
public abstract int getDataLength()Size of the data, which becomes the length field of the block header.- Returns:
- the size of the block, NOT including the 3 byte header (type and size)
writeData
public abstract int writeData(byte[] tgt, int off) Write the block data to the target array, returning the new offset.- Parameters:
tgt- the destination arrayoff- index in tgt to write the data at, past the 3-byte header- Returns:
- the offset just past the written data
toString