RegularPacketWriter (Naga API)
Date: 2016-06-28

naga.packetwriter

## Class RegularPacketWriter

- java.lang.Object
- - naga.packetwriter.RegularPacketWriter

- All Implemented Interfaces:
    PacketWriter

      public class RegularPacketWriter
      extends java.lang.Object
      implements PacketWriter

  Writes packet of the format

  `[header 1-4 bytes] => content size
  [content] => 0-255/0-65535/0-16777215/0-2147483646`

  Note that the maximum size for 4 bytes is a signed 32 bit int, not unsigned.

  The packet writer will not validate outgoing packets, so make sure that the packet content size will fit in the header. I.e. make sure that if you have a 1 byte header, you do not send packets larger than 255 bytes, if two bytes, larger than 65535 and so on.

  Author:
    Christoffer Lerno

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RegularPacketWriter(int headerSize, boolean bigEndian)` Creates a regular packet writer with the given header size.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.nio.ByteBuffer[]` | `write(java.nio.ByteBuffer[] byteBuffers)` Convert the incoming bytes to the bytes to be serialized.

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

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

- - ### Constructor Detail

    - #### RegularPacketWriter

          public RegularPacketWriter(int headerSize,
                             boolean bigEndian)

      Creates a regular packet writer with the given header size.
      Parameters:
        `headerSize` - the header size, 1 - 4 bytes.
        `bigEndian` - big endian (largest byte first) or little endian (smallest byte first)

  - ### Method Detail

    - #### write

          public java.nio.ByteBuffer[] write(java.nio.ByteBuffer[] byteBuffers)

      Description copied from interface: `PacketWriter`
      Convert the incoming bytes to the bytes to be serialized.
      Specified by:
        `write` in interface `PacketWriter`
      Parameters:
        `byteBuffers` - an array of ByteBuffers containing data the bytes to be written.
      Returns:
        the resulting array of ByteBuffers.