com.hazelcast.nio

## Class PacketIOHelper

- java.lang.Object
- - com.hazelcast.nio.PacketIOHelper

-     @PrivateApi
      public class PacketIOHelper
      extends Object

  Responsible for writing or reading an Packet. Originally the logic was placed in the Packet. The problem with this approach is that a single Packet instance can't be shared between multiple connections and this leads to increased memory usage since the packet needs to be copied for every connection. The `PacketIOHelper` is stateful because it tracks where the packet reading from ByteBuffer or writing to ByteBuffer. A `PacketIOHelper` instance should only be used for reading, or only be used for writing. So if you need to read and write at the same time, you need to have 2 instances. A `PacketIOHelper` is designed to be reused.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PacketIOHelper()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Packet` | `readFrom(ByteBuffer src)` Reads the packet data from the supplied `ByteBuffer`.
    `boolean` | `writeTo(Packet packet, ByteBuffer dst)` Writes the packet data to the supplied `ByteBuffer`, up to the buffer's limit.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PacketIOHelper

          public PacketIOHelper()

  - ### Method Detail

    - #### writeTo

          public boolean writeTo(Packet packet,
                                 ByteBuffer dst)

      Writes the packet data to the supplied `ByteBuffer`, up to the buffer's limit. If it returns `false`, it should be called again to write the remaining data.
      Parameters:
        `dst` - the destination byte buffer
      Returns:
        `true` if all the packet's data is now written out; `false` otherwise.

    - #### readFrom

          public Packet readFrom(ByteBuffer src)

      Reads the packet data from the supplied `ByteBuffer`. The buffer may not contain the complete packet. If this method returns `false`, it should be called again to read more packet data.
      Parameters:
        `src` - the source byte buffer
      Returns:
        the read Packet if all the packet's data is now read; `null` otherwise.

Copyright © 2020. All rights reserved.