Loading...
Searching...
No Matches
chdr_packet.hpp
Go to the documentation of this file.
//
// Copyright 2020 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <uhd/rfnoc/chdr_types.hpp>
#include <uhd/rfnoc/rfnoc_types.hpp>
#include <uhd/types/endianness.hpp>
#include <boost/none.hpp>
#include <boost/optional.hpp>
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
namespace uhd { namespace utils { namespace chdr {
class UHD_API chdr_packet
{
public:
template <typename payload_t>
chdr_packet(uhd::rfnoc::chdr_w_t chdr_w,
uhd::rfnoc::chdr::chdr_header header,
payload_t payload,
boost::optional<uint64_t> timestamp = boost::none,
std::vector<uint64_t> metadata = {});
chdr_packet(uhd::rfnoc::chdr_w_t chdr_w,
uhd::rfnoc::chdr::chdr_header header,
std::vector<uint8_t> payload_data,
boost::optional<uint64_t> timestamp = boost::none,
std::vector<uint64_t> mdata = {});
uhd::rfnoc::chdr::chdr_header get_header() const;
void set_header(uhd::rfnoc::chdr::chdr_header header);
boost::optional<uint64_t> get_timestamp() const;
void set_timestamp(boost::optional<uint64_t> timestamp);
const std::vector<uint64_t>& get_metadata() const;
void set_metadata(std::vector<uint64_t> metadata);
std::vector<uint8_t> serialize_to_byte_vector(
endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
template <typename OutputIterator>
void serialize(OutputIterator first,
OutputIterator last,
endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
template <typename InputIterator>
static chdr_packet deserialize(uhd::rfnoc::chdr_w_t chdr_w,
InputIterator first,
InputIterator last,
endianness_t endianness = uhd::ENDIANNESS_LITTLE);
size_t get_packet_len() const;
const std::vector<uint8_t>& get_payload_bytes() const;
void set_payload_bytes(std::vector<uint8_t> bytes);
template <typename payload_t>
payload_t get_payload(uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
template <typename payload_t>
void set_payload(
payload_t payload, uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE);
std::string to_string() const;
template <typename payload_t>
std::string to_string_with_payload(
uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
private:
void serialize_ptr(endianness_t endianness, void* start, void* end) const;
static chdr_packet deserialize_ptr(uhd::rfnoc::chdr_w_t chdr_w,
endianness_t endianness,
const void* start,
const void* end);
inline void set_header_lengths()
{
_header.set_num_mdata(_mdata.size() / (uhd::rfnoc::chdr_w_to_bits(_chdr_w) / 64));
_header.set_length(get_packet_len());
}
uhd::rfnoc::chdr_w_t _chdr_w;
uhd::rfnoc::chdr::chdr_header _header;
std::vector<uint8_t> _payload;
boost::optional<uint64_t> _timestamp;
std::vector<uint64_t> _mdata;
};
}}} // namespace uhd::utils::chdr
#include <uhd/utils/chdr/chdr_packet.ipp>
chdr_packet.ipp
chdr_types.hpp
uhd::rfnoc::chdr::chdr_header
Definition chdr_types.hpp:35
uhd::utils::chdr::chdr_packet::get_header
uhd::rfnoc::chdr::chdr_header get_header() const
uhd::utils::chdr::chdr_packet::serialize_to_byte_vector
std::vector< uint8_t > serialize_to_byte_vector(endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
uhd::utils::chdr::chdr_packet::to_string_with_payload
std::string to_string_with_payload(uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
Return a string representation of this object and deserialize its payload.
Definition chdr_packet.ipp:81
uhd::utils::chdr::chdr_packet::set_payload
void set_payload(payload_t payload, uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE)
Definition chdr_packet.ipp:64
uhd::utils::chdr::chdr_packet::get_packet_len
size_t get_packet_len() const
uhd::utils::chdr::chdr_packet::get_metadata
const std::vector< uint64_t > & get_metadata() const
uhd::utils::chdr::chdr_packet::set_metadata
void set_metadata(std::vector< uint64_t > metadata)
uhd::utils::chdr::chdr_packet::set_timestamp
void set_timestamp(boost::optional< uint64_t > timestamp)
uhd::utils::chdr::chdr_packet::set_header
void set_header(uhd::rfnoc::chdr::chdr_header header)
uhd::utils::chdr::chdr_packet::to_string
std::string to_string() const
Return a string representation of this object.
uhd::utils::chdr::chdr_packet::set_payload_bytes
void set_payload_bytes(std::vector< uint8_t > bytes)
uhd::utils::chdr::chdr_packet::get_payload_bytes
const std::vector< uint8_t > & get_payload_bytes() const
uhd::utils::chdr::chdr_packet::chdr_packet
chdr_packet(uhd::rfnoc::chdr_w_t chdr_w, uhd::rfnoc::chdr::chdr_header header, std::vector< uint8_t > payload_data, boost::optional< uint64_t > timestamp=boost::none, std::vector< uint64_t > mdata={})
uhd::utils::chdr::chdr_packet::chdr_packet
chdr_packet(uhd::rfnoc::chdr_w_t chdr_w, uhd::rfnoc::chdr::chdr_header header, payload_t payload, boost::optional< uint64_t > timestamp=boost::none, std::vector< uint64_t > metadata={})
Definition chdr_packet.ipp:16
uhd::utils::chdr::chdr_packet::get_payload
payload_t get_payload(uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
Definition chdr_packet.ipp:47
uhd::utils::chdr::chdr_packet::deserialize
static chdr_packet deserialize(uhd::rfnoc::chdr_w_t chdr_w, InputIterator first, InputIterator last, endianness_t endianness=uhd::ENDIANNESS_LITTLE)
Definition chdr_packet.ipp:36
uhd::utils::chdr::chdr_packet::get_timestamp
boost::optional< uint64_t > get_timestamp() const
uhd::utils::chdr::chdr_packet::serialize
void serialize(OutputIterator first, OutputIterator last, endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
Definition chdr_packet.ipp:27
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
endianness.hpp
uhd::rfnoc::chdr_w_t
chdr_w_t
Type that indicates the CHDR Width in bits.
Definition rfnoc_types.hpp:19
uhd::rfnoc::chdr_w_to_bits
constexpr size_t chdr_w_to_bits(chdr_w_t chdr_w)
Conversion from chdr_w_t to a number of bits.
Definition rfnoc_types.hpp:22
uhd::utils::chdr
Definition chdr_packet.hpp:20
uhd::utils
Definition chdr_packet.hpp:20
uhd
Definition build_info.hpp:12
uhd::endianness_t
endianness_t
Definition endianness.hpp:30
uhd::ENDIANNESS_LITTLE
@ ENDIANNESS_LITTLE
Definition endianness.hpp:30
rfnoc_types.hpp