Program Listing for File SerializedPayload.hpp

Return to documentation for file (include/fastdds/rtps/common/SerializedPayload.hpp)

// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FASTDDS_RTPS_COMMON__SERIALIZEDPAYLOAD_HPP
#define FASTDDS_RTPS_COMMON__SERIALIZEDPAYLOAD_HPP

#include <cstring>
#include <new>
#include <stdexcept>
#include <cassert>
#include <stdint.h>
#include <stdlib.h>

#include <fastdds/fastdds_dll.hpp>
#include <fastdds/rtps/common/Types.hpp>
#include <fastdds/rtps/history/IPayloadPool.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

//Pre define data encapsulation schemes
#define CDR_BE 0x0000
#define CDR_LE 0x0001
#define PL_CDR_BE 0x0002
#define PL_CDR_LE 0x0003

#if FASTDDS_IS_BIG_ENDIAN_TARGET
#define DEFAULT_ENCAPSULATION CDR_BE
#define PL_DEFAULT_ENCAPSULATION PL_CDR_BE
#else
#define DEFAULT_ENCAPSULATION CDR_LE
#define PL_DEFAULT_ENCAPSULATION PL_CDR_LE
#endif  // FASTDDS_IS_BIG_ENDIAN_TARGET

struct FASTDDS_EXPORTED_API SerializedPayload_t
{
    static constexpr size_t representation_header_size = 4u;

    uint16_t encapsulation;
    uint32_t length;
    octet* data;
    uint32_t max_size;
    uint32_t pos;
    IPayloadPool* payload_owner = nullptr;

    SerializedPayload_t()
        : encapsulation(CDR_BE)
        , length(0)
        , data(nullptr)
        , max_size(0)
        , pos(0)
    {
    }

    explicit SerializedPayload_t(
            uint32_t len)
        : SerializedPayload_t()
    {
        this->reserve(len);
    }

    SerializedPayload_t(
            const SerializedPayload_t& other) = delete;
    SerializedPayload_t& operator = (
            const SerializedPayload_t& other) = delete;

    SerializedPayload_t(
            SerializedPayload_t&& other) noexcept
    {
        *this = std::move(other);
    }

    SerializedPayload_t& operator = (
            SerializedPayload_t&& other) noexcept;

    ~SerializedPayload_t();

    bool operator == (
            const SerializedPayload_t& other) const;

    bool copy(
            const SerializedPayload_t* serData,
            bool with_limit = true);

    bool reserve_fragmented(
            SerializedPayload_t* serData);

    void empty();

    void reserve(
            uint32_t new_size);

};

} // namespace rtps
} // namespace fastdds
} // namespace eprosima

#endif // FASTDDS_RTPS_COMMON__SERIALIZEDPAYLOAD_HPP