/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_PACKET_HEADER_HPP
#define NMM_PACKET_HEADER_HPP NMM_PACKET_HEADER_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/nmm_types.hpp"

namespace NMM {

  /** Packet header used by packet network stream.
   * This structure is the header of a packet used by the PacketONetStream and PacketINetStream classes.
   * A packet contains part of the serialized data of a message. The header identifies the message the
   * packet belongs to, as well information for reconstructing the message if all packets that belong to it
   * are available. This information consists of a sequence number of the packet within the message and the
   * total number of packets that belong to the message.
   *
   * @see PacketINetStream, PacketONetStream, UDPStrategy, UDPBroadcaster
   */
  class PacketHeader {
  public:
    /** Constructor.
     *
     * @param message_id Sequence number of the message this packet belongs to
     * @param packet_no Sequence number of this packet within the message it belongs to
     * @param packet_count Total number of packets which belong to the same message
     * @param size Number of data bytes contained within this packet
     */
    PacketHeader(unsigned int message_id, unsigned int packet_no, unsigned int packet_count, unsigned int size);

    /** Get number of data bytes contained within this packet.
     *
     * @return Number of data bytes contained within this packet
     */
    unsigned int getPacketSize() const { return __size; }

    /** Get sequence number of the message this packet belongs to.
     *
     * @return Sequence number of the message this packet belongs to
     */
    unsigned int getMessageID() const { return __message_id; }

    /** Get sequence number of this packet within the message it belongs to.
     *
     * @return Sequence number of this packet within the message it belongs to
     */
    unsigned int getPacketNumber() const { return __packet_no; }

    /** Get total number of packets which belong to the same message.
     *
     * @return Total number of packets which belong to the same message
     */
    unsigned int getPacketCount() const { return __packet_count; }

  private:
    nmm_uint32 __message_id;    ///< Sequence number of the message this packet belongs to
    nmm_uint16 __packet_no;     ///< Sequence number of this packet within the message it belongs to
    nmm_uint16 __packet_count;  ///< Total number of packets which belong to the same message
    nmm_uint32 __size;          ///< Number of data bytes contained within this packet
  };
  
}

#include "nmm/nmm_suffix.hpp"

#endif
