VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
header.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 by Thun Lu. All rights reserved.
3 * Author: Thun Lu <thun.lu@zohomail.cn>
4 * Repo: https://github.com/thun-res/vlink
5 * _ __ __ _ __
6 * | | / / / / (_) ____ / /__
7 * | | / / / / / / / __ \ / //_/
8 * | |/ / / /___ / / / / / / / ,<
9 * |___/ /_____/ /_/ /_/ /_/ /_/|_|
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24/**
25 * @file header.h
26 * @brief Common timestamp and sequencing metadata header for VLink zero-copy data types.
27 *
28 * @details
29 * @c Header is a fixed-size (40-byte) POD structure that is embedded as the first public
30 * member in all VLink zero-copy containers (@c RawData, @c CameraFrame, @c PointCloud).
31 * It carries per-message timing and identification fields that survive binary serialisation
32 * intact because the entire container struct is @c memcpy'd into the wire buffer.
33 *
34 * The layout is verified at compile time:
35 * @code
36 * static_assert(sizeof(Header) == 40, "Sizeof must be 40 bytes.");
37 * @endcode
38 *
39 * @par Memory layout
40 * @code
41 * Offset Size Field
42 * ------ ---- ----------
43 * 0 16 frame_id
44 * 16 4 seq
45 * 20 4 reserved
46 * 24 8 time_meas
47 * 32 8 time_pub
48 * @endcode
49 *
50 * @note
51 * - All fields are plain data; no virtual functions, no dynamic allocation.
52 * - The struct is 8-byte aligned (@c VLINK_EXPORT_AND_ALIGNED(8)) to ensure
53 * consistent padding across compilers and architectures.
54 * - 32-bit architectures (arm, x86, i386) emit a compile-time warning and are
55 * not officially supported for zero-copy types.
56 */
57
58#pragma once
59
60#include <cstdint>
61
62#include "../base/macros.h"
63
64namespace vlink {
65
66namespace zerocopy {
67
68/**
69 * @struct Header
70 * @brief Fixed-size (40-byte) metadata header embedded in all VLink zero-copy data types.
71 *
72 * @details
73 * Provides per-frame sequencing and dual-timestamp fields. Two timestamps allow
74 * end-to-end latency to be measured by comparing @c time_meas (when the sensor
75 * acquired the data) with @c time_pub (when the publisher dispatched it).
76 */
77struct VLINK_EXPORT_AND_ALIGNED(8) Header final {
78 char frame_id[16]{"unknown"}; ///< Frame identifier; semantics defined by the producing sensor.
79 uint32_t seq{0}; ///< Monotonically increasing sequence number, wraps at UINT32_MAX.
80 uint32_t reserved{0}; ///< Reserved for future use; must be zero.
81 uint64_t time_meas{0}; ///< Measurement timestamp in nanoseconds since epoch.
82 uint64_t time_pub{0}; ///< Publish timestamp in nanoseconds since epoch.
83
84 /**
85 * @brief Default constructor.
86 *
87 * @details
88 * Verifies via @c static_assert that the struct is exactly 40 bytes on
89 * 64-bit platforms (the check is omitted on 32-bit architectures).
90 */
91 Header() noexcept;
92};
93
94} // namespace zerocopy
95
96} // namespace vlink
Platform-independent macro definitions for the VLink library.
#define VLINK_EXPORT_AND_ALIGNED(align_num)
Marks a class or variable as both exported and aligned to the given byte boundary.
Definition macros.h:103
Fixed-size (40-byte) metadata header embedded in all VLink zero-copy data types.