> ## Documentation Index
> Fetch the complete documentation index at: https://developer.synopsys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# File autonomy_msg.h

![][C++]

**Location**: `autonomy/communication/messages/autonomy_msg.h`

## Classes

* [simulation\_framework::autonomy::communication::messages::TimestampView](https://developer.synopsys.com/docs/avxcelerate/avxcelerate-simulation-framework/2026-r1/reference/structsimulation__framework_1_1autonomy_1_1communication_1_1messages_1_1TimestampView.md)
* [simulation\_framework::autonomy::communication::messages::AutonomyMsg](https://developer.synopsys.com/docs/avxcelerate/avxcelerate-simulation-framework/2026-r1/reference/classsimulation__framework_1_1autonomy_1_1communication_1_1messages_1_1AutonomyMsg.md)

## Namespaces

* [simulation\_framework](https://developer.synopsys.com/docs/avxcelerate/avxcelerate-simulation-framework/2026-r1/reference/namespacesimulation__framework.md)
* [simulation\_framework::autonomy](https://developer.synopsys.com/docs/avxcelerate/avxcelerate-simulation-framework/2026-r1/reference/namespacesimulation__framework_1_1autonomy.md)
* [simulation\_framework::autonomy::communication](https://developer.synopsys.com/docs/avxcelerate/avxcelerate-simulation-framework/2026-r1/reference/namespacesimulation__framework_1_1autonomy_1_1communication.md)
* [simulation\_framework::autonomy::communication::messages](https://developer.synopsys.com/docs/avxcelerate/avxcelerate-simulation-framework/2026-r1/reference/namespacesimulation__framework_1_1autonomy_1_1communication_1_1messages.md)

## Includes

* \<algorithm>
* \<cstddef>
* \<cstdint>
* \<cstring>
* \<stdexcept>
* \<type\_traits>

## Included by

* [dds\_to\_autonomy\_msg\_converter.h](https://developer.synopsys.com/docs/avxcelerate/avxcelerate-simulation-framework/2026-r1/reference/dds__to__autonomy__msg__converter_8h.md)
* [vehicle\_control\_input\_msg.h](https://developer.synopsys.com/docs/avxcelerate/avxcelerate-simulation-framework/2026-r1/reference/vehicle__control__input__msg_8h.md)

## Source

```cpp theme={null}

#ifndef AUTONOMY_COMMUNICATION_MESSAGES_AUTONOMY_MSG_H
#define AUTONOMY_COMMUNICATION_MESSAGES_AUTONOMY_MSG_H

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <stdexcept>
#include <type_traits>

namespace simulation_framework
{
namespace autonomy
{
namespace communication
{
namespace messages
{

struct TimestampView
{
    uint64_t seconds() const noexcept { return secs; }

    uint64_t nanos() const noexcept { return ns; }

    uint64_t secs{0};
    uint64_t ns{0};
};

class AutonomyMsg
{
  public:
    AutonomyMsg() {}

    uint64_t sequence_id{0ULL};

    size_t ByteSizeLong() const noexcept { return BaseSize() + PayloadSize(); }

    TimestampView timestamp() const noexcept { return timestamp_view_; }

    void SetTimestamp(uint64_t seconds, uint64_t nanos) noexcept
    {
        timestamp_view_.secs = seconds;
        timestamp_view_.ns = nanos;
    }

    void SerializeToArray(void* data, size_t size) const
    {
        if (!data)
        {
            throw std::runtime_error("Serialize buffer pointer is invalid");
        }
        const size_t needed = ByteSizeLong();
        if (size < needed)
        {
            throw std::runtime_error("Serialize buffer overflow: not enough space to write value");
        }
        unsigned char* ptr = static_cast<unsigned char*>(data);
        size_t remaining = size;

        writeLE(ptr, remaining, sequence_id);
        writeLE(ptr, remaining, timestamp_view_.secs);
        writeLE(ptr, remaining, timestamp_view_.ns);

        SerializePayload(ptr, remaining);
    }
    void ParseFromArray(const void* data, size_t size)
    {
        if (!data)
            throw std::runtime_error("Parse buffer pointer is invalid");
        const unsigned char* ptr = static_cast<const unsigned char*>(data);
        size_t remaining = size;

        readLE(ptr, remaining, sequence_id);
        readLE(ptr, remaining, timestamp_view_.secs);
        readLE(ptr, remaining, timestamp_view_.ns);

        ParsePayload(ptr, remaining);
    }

  protected:
    static constexpr size_t BaseSize() noexcept { return sizeof(uint64_t) + sizeof(uint64_t) + sizeof(uint64_t); }

    virtual size_t PayloadSize() const noexcept = 0;

    virtual void SerializePayload(unsigned char*& ptr, size_t& remaining) const = 0;

    template <typename T>
    static typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value, void>::type
    readLE(const unsigned char*& ptr, size_t& remaining, T& out)
    {
        const size_t n = sizeof(T);
        if (remaining < n)
        {
            throw std::runtime_error("Parse buffer underflow: not enough data to read value");
        }
        unsigned char tmp[sizeof(T)];
        std::memcpy(tmp, ptr, n);
        const uint16_t one = 1;
        const bool host_is_little = (*reinterpret_cast<const unsigned char*>(&one) == 1);
        if (!host_is_little)
        {
            std::reverse(tmp, tmp + n);
        }
        std::memcpy(&out, tmp, n);
        ptr += n;
        remaining -= n;
    }

    virtual void ParsePayload(const unsigned char*& ptr, size_t& remaining) = 0;

    template <typename T>
    static typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value, void>::type
    writeLE(unsigned char*& ptr, size_t& remaining, T value)
    {
        const size_t n = sizeof(T);
        if (remaining < n)
        {
            throw std::runtime_error("Serialize buffer overflow: not enough space to write value");
        }
        unsigned char tmp[sizeof(T)];
        std::memcpy(tmp, &value, n);
        const uint16_t one = 1;
        const bool host_is_little = (*reinterpret_cast<const unsigned char*>(&one) == 1);
        if (!host_is_little)
        {
            std::reverse(tmp, tmp + n);
        }
        std::memcpy(ptr, tmp, n);
        ptr += n;
        remaining -= n;
    }

    TimestampView timestamp_view_;
};

}  // namespace messages
}  // namespace communication
}  // namespace autonomy
}  // namespace simulation_framework

#endif  // AUTONOMY_COMMUNICATION_MESSAGES_AUTONOMY_MSG_H
```

[private]: https://img.shields.io/badge/-private-red "private"

[public]: https://img.shields.io/badge/-public-brightgreen "public"

[const]: https://img.shields.io/badge/-const-lightblue "const"

[C++]: https://img.shields.io/badge/language-C%2B%2B-blue "C++"

[protected]: https://img.shields.io/badge/-protected-yellow "protected"

[static]: https://img.shields.io/badge/-static-lightgrey "static"
