Example #1
0
  /**
   * Initializes the packet's state and data by doing a deep copy of the contents of the buffer.
   *
   * @param buffer buffer containing both state and data in the form
   *     <pre>
   * +--------------+-------------+
   * | packet state | packet data |
   * +--------------+-------------+
   * </pre>
   */
  public JMemoryPacket(JBuffer buffer) {
    super(POINTER);

    header.setWirelen(buffer.size());

    final int len = buffer.size();
    JBuffer b = getMemoryBuffer(len);

    b.transferFrom(buffer); // Make a buffer to buffer copy

    peer(b, 0, len);

    header.setWirelen(len);
  }
Example #2
0
  /**
   * Peers the contents of the buffer directly with this packet. No copies are performed but the
   * packet state and data are expected to be contained within the buffer with a certain layout as
   * described below:
   *
   * <p>Supplied buffer layout expected:
   *
   * <pre>
   * +-----+----+
   * |State|Data|
   * +-----+----+
   * </pre>
   *
   * @param buffer buffer containing packet header, state and data
   * @param offset starting offset into the buffer
   * @return number of bytes peered
   */
  public int peerStateAndData(JBuffer buffer, int offset) {

    state.peerTo(buffer, offset, State.sizeof(0));
    int o = state.peerTo(buffer, offset, State.sizeof(state.getHeaderCount()));
    o += super.peer(buffer, offset + o, header.caplen());

    return o;
  }
Example #3
0
  /**
   * Preallocates a packet with internal buffer of the supplied size.
   *
   * @param size number of bytes to pre allocate
   */
  public JMemoryPacket(int size) {
    super(size, 0);

    header.setWirelen(size);

    /** Bug #2878768 JMemoryPacket(int) constructor doesn't work */
    super.peer(super.memory);
  }
Example #4
0
  /**
   * Initializes the packet's state and data by doing a deep copy of the contents of the buffer.
   *
   * @param buffer buffer containing both state and data in the form
   *     <pre>
   * +--------------+-------------+
   * | packet state | packet data |
   * +--------------+-------------+
   * </pre>
   */
  public JMemoryPacket(byte[] buffer) {
    super(Type.POINTER);

    final JBuffer mem = getMemoryBuffer(buffer);
    super.peer(mem);

    header.setWirelen(buffer.length);
  }
Example #5
0
  /**
   * Initializes the packet's state and data by doing a deep copy of the contents of the buffer.
   *
   * @param buffer buffer containing both state and data in the form
   *     <pre>
   * +--------------+-------------+
   * | packet state | packet data |
   * +--------------+-------------+
   * </pre>
   *
   * @throws PeeringException if there is a problem peering with the buffer
   */
  public JMemoryPacket(ByteBuffer buffer) throws PeeringException {
    super(Type.POINTER);

    final int size = buffer.limit() - buffer.position();

    final JBuffer mem = getMemoryBuffer(size);
    super.peer(mem);

    transferFrom(buffer);

    header.setWirelen(size);
  }
Example #6
0
 /**
  * Changes the wirelen of this packet.
  *
  * @param wirelen new wirelen for this packet
  */
 public void setWirelen(int wirelen) {
   header.setWirelen(wirelen);
 }