static int encodeSocketAddress(
        final UnsafeBuffer encodingBuffer, final int offset, final InetSocketAddress address)
    {
        int encodedLength = 0;
        /*
         * Stream of values:
         * - port (int) (unsigned short int)
         * - IP address length (int) (4 or 16)
         * - IP address (4 or 16 bytes)
         */

        encodingBuffer.putInt(offset + encodedLength, address.getPort(), LITTLE_ENDIAN);
        encodedLength += SIZE_OF_INT;

        final byte[] addressBytes = address.getAddress().getAddress();
        encodingBuffer.putInt(offset + encodedLength, addressBytes.length, LITTLE_ENDIAN);
        encodedLength += SIZE_OF_INT;

        encodingBuffer.putBytes(offset + encodedLength, addressBytes);
        encodedLength += addressBytes.length;

        return encodedLength;
    }
@Test
    void encodeSocketAddress()
    {
        final InetSocketAddress socketAddress = new InetSocketAddress(15015);
        final byte[] address = socketAddress.getAddress().getAddress();

        final int encodedLength = CommonEventEncoder.encodeSocketAddress(buffer, 4, socketAddress);

        assertEquals(SIZE_OF_INT * 2 + address.length, encodedLength);
        assertEquals(15015, buffer.getInt(4, LITTLE_ENDIAN));
        assertEquals(address.length, buffer.getInt(4 + SIZE_OF_INT, LITTLE_ENDIAN));
        final byte[] encodedAddress = new byte[address.length];
        buffer.getBytes(4 + SIZE_OF_INT * 2, encodedAddress);
        assertArrayEquals(address, encodedAddress);
    }