Class PacketUtils


  • public final class PacketUtils
    extends java.lang.Object
    Utilities for working with packet headers.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkBufferLength​(int byteLength, int offset, int length)
      Check the length of the input buffer is appropriate given the offset and length parameters.
      static void checkHeaderLength​(int givenLength, int requiredLength)
      Check that there are enough bytes in the buffer to read some number of bytes that we need to read a full header.
      static void checkInput​(byte[] data, int offset, int length, int requiredLength)
      Check the input parameters are sane and there's enough bytes to read the required length.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • checkBufferLength

        public static void checkBufferLength​(int byteLength,
                                             int offset,
                                             int length)
                                      throws DeserializationException
        Check the length of the input buffer is appropriate given the offset and length parameters.
        Parameters:
        byteLength - length of the input buffer array
        offset - offset given to begin reading bytes from
        length - length given to read up until
        Throws:
        DeserializationException - if the input parameters don't match up (i.e we can't read that many bytes from the buffer at the given offest)
      • checkHeaderLength

        public static void checkHeaderLength​(int givenLength,
                                             int requiredLength)
                                      throws DeserializationException
        Check that there are enough bytes in the buffer to read some number of bytes that we need to read a full header.
        Parameters:
        givenLength - given size of the buffer
        requiredLength - number of bytes we need to read some header fully
        Throws:
        DeserializationException - if there aren't enough bytes
      • checkInput

        public static void checkInput​(byte[] data,
                                      int offset,
                                      int length,
                                      int requiredLength)
                               throws DeserializationException
        Check the input parameters are sane and there's enough bytes to read the required length.
        Parameters:
        data - input byte buffer
        offset - offset of the start of the header
        length - length given to deserialize the header
        requiredLength - length needed to deserialize header
        Throws:
        DeserializationException - if we're unable to deserialize the packet based on the input parameters