コード例 #1
0
ファイル: Message.cpp プロジェクト: jarekAIM/IGVC2015
////////////////////////////////////////////////////////////////////////////////////
///
///   \brief If the IsLargeDataSet method returns true, then this method is used
///          to convert message payload data into a multi-packet stream
///          according to rules defined by the JAUS standards documents.
///
///   This method should only be overloaded if your message contains data
///   larger than Header::MaxSize - Header::MinSize (e.g. image data) and you wish
///   to optimize how data is written.  By default, this method calls the
///   WriteMessageBody method to generate a single large byte array, which is then
///   broken up into a Packet::List for the transport layer.
///
///   \param[out] stream Multi-packet stream containing serialized message 
///                      following rules of large data sets.
///   \param[out] streamHeaders Headers for packet in the stream.
///   \param[in] maxPayloadSize This is the maximum packet size including 
///                             payload, does not include transport, General
///                             Transport Header, or Message Code (USHORT).
///   \param[in] transportHeader Additional transport header data to precede
///                              the general transport header of each packet.
///   \param[in] startingSequenceNumber Sequence number to use for packets.
///   \param[in] broadcastFlags Values to use to signify if message should be
///                             sent using any broadcast options (e.g. 
///                             multicast). 0 = no options, 1 = local broadcast,
///                             2 = global broadcast.
///
///   \return FAILURE on error, otherwise number of packets written.
///
////////////////////////////////////////////////////////////////////////////////////
int Message::WriteLargeDataSet(Packet::List& stream,
                               Header::List& streamHeaders,
                               const UShort maxPayloadSize,
                               const Packet* transportHeader,
                               const UShort startingSequenceNumber,
                               const Byte broadcastFlags) const
{
    Header header;
    header.mDestinationID = mDestinationID;
    header.mSourceID = mSourceID;
    header.mPriorityFlag = mPriority;
    header.mBroadcastFlag = broadcastFlags;

    stream.clear();
    streamHeaders.clear();
    Packet* temp = ((Packet *)(&mStreamPayload));
    temp->Clear();
    if(IsLargeDataSet() && WriteMessageBody(*temp) >= 0)
    {
        LargeDataSet::CreateLargeDataSet(header, 
                                         mMessageCode, 
                                         *temp, 
                                         stream, 
                                         streamHeaders, 
                                         transportHeader, 
                                         maxPayloadSize,
                                         startingSequenceNumber);
        return (int)stream.size();
    }
    return FAILURE;
}
コード例 #2
0
ファイル: judp.cpp プロジェクト: ShowLove/Robotics_Club
////////////////////////////////////////////////////////////////////////////////////
///
///   \brief Converts the message data into JUDP packets for transmission.
///
///   \param[in] message Message to convert/serialize.
///   \param[out] stream Packets to send.
///   \param[out] streamHeaders Header info for packets.
///   \param[in] startingSequenceNumber Sequence number to use for packets.
///   \param[in] broadcastFlags Values to use to signify if message should be
///                             sent using any broadcast options (e.g. 
///                             multicast). 0 = no options, 1 = local broadcast,
///                             2 = global broadcast.
///
///   \return True on success, false on failure.
///
////////////////////////////////////////////////////////////////////////////////////
bool JUDP::SerializeMessage(const Message* message,
                            Packet::List& stream,
                            Header::List& streamHeaders,
                            const UShort startingSequenceNumber,
                            const int broadcastFlags) const
{
    Packet packet;
    Header header;

    // Pre-allocate memory.
    packet.Reserve(mMaxPayloadSize + OverheadSizeBytes);

    // Clear stream/headers.
    stream.clear();
    streamHeaders.clear();

    // If the message is a large data set, create a multi-packet stream.
    if(message->IsLargeDataSet(mMaxPayloadSize))
    {
        return message->WriteLargeDataSet(stream, 
                                          streamHeaders, 
                                          mMaxPayloadSize, 
                                          &mTransportHeader,
                                          startingSequenceNumber) > 0;
    }
    // Single packet.
    else if(message->Write(packet, header, &mTransportHeader, true, startingSequenceNumber) > 0)
    {
        stream.push_back(packet);
        streamHeaders.push_back(header);
        return true;
    }
    return false;
}