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

public abstract static class NTCP2Payload.Blockextends Object
Base class for NTCP 2 payload blocks to be transmitted. Not used for receive; we use callbacks instead.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
    Type of the block being read or written.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Block(int ttype)
    Stores the type byte written as the block's first header byte.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract int
    Size of the data, which becomes the length field of the block header.
    int
    How many bytes the whole block occupies in a frame.
    String representation of this block.
    int
    write(byte[] tgt, int off)
    Write the block to the target array, returning the new offset.
    abstract int
    writeData(byte[] tgt, int off)
    Write the block data to the target array, returning the new offset.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • type

      private final int type
      Type 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 array
      off - 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 array
      off - index in tgt to write the data at, past the 3-byte header
      Returns:
      the offset just past the written data
    • toString

      public String toString()
      String representation of this block.
      Overrides:
      toString in class Object