MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NetworkUtils.hpp
Go to the documentation of this file.
1#pragma once
2
4
5//=============================================================================
6// Transport identity
7//=============================================================================
8
9/**
10 * @enum NetworkTransportHint
11 * @brief Portal-level transport hint, independent of Core::NetworkTransport.
12 *
13 * Consumers express intent here. NetworkFoundry resolves the hint to an
14 * actual backend at endpoint-open time, allowing future transports (WebRTC,
15 * QUIC, GStreamer) to slot in without any Portal API change.
16 */
17enum class NetworkTransportHint : uint8_t {
18 UDP, ///< Low-latency, unordered datagrams. OSC, control, sparse streams.
19 TCP, ///< Reliable ordered byte stream. Bulk data, session-oriented.
20 SHARED_MEMORY, ///< Zero-copy IPC on the same machine.
21 AUTO ///< Let NetworkFoundry pick based on StreamProfile.
22};
23
24//=============================================================================
25// Stream characteristics
26//=============================================================================
27
28/**
29 * @enum StreamProfile
30 * @brief Data characteristics that drive transport and framing selection.
31 *
32 * Domain-agnostic. The same profile applies whether the payload is
33 * a float buffer, a matrix, a point cloud, or a raw byte sequence.
34 * NetworkFoundry uses this when TransportHint::AUTO is specified and
35 * StreamForge uses it to select wire framing.
36 *
37 * The axes are: ordering requirement × loss tolerance × payload size.
38 */
39enum class StreamProfile : uint8_t {
40 REALTIME_SMALL, ///< Small payloads, loss-tolerant, latency-sensitive.
41 ///< UDP default. Single datagram fits MTU.
42 ///< Example: sparse parameter updates, OSC-style events.
43
44 REALTIME_BULK, ///< Large payloads, loss-tolerant, latency-sensitive.
45 ///< UDP with chunking. Dropped chunk = dropped frame, acceptable.
46 ///< Example: per-cycle matrix snapshots, live geometry streams.
47
48 ORDERED_BULK, ///< Large payloads, loss-intolerant, ordering required.
49 ///< TCP or SHM. Completeness matters more than latency.
50 ///< Example: tensor transfers, model weights, file-like payloads.
51
52 ARBITRARY ///< Raw bytes. Caller owns framing entirely.
53 ///< No policy applied beyond opening the endpoint.
54};
55
56/**
57 * @enum FramingPolicy
58 * @brief How outbound payloads are framed on the wire.
59 *
60 * NONE: raw bytes, no framing (UDP default).
61 * LENGTH_PREFIX: 4-byte big-endian size header before each message (TCP default).
62 * CHUNKED: split large payloads into MTU-sized chunks with sequence numbers.
63 */
64enum class FramingPolicy : uint8_t {
65 NONE,
68};
69
70//=============================================================================
71// Stream handle type
72//=============================================================================
73
74/**
75 * @typedef StreamID
76 * @brief Opaque handle returned by NetworkFoundry when a stream is opened.
77 *
78 * Analogous to ShaderID / ComputePipelineID in Portal::Graphics.
79 * Zero is always invalid.
80 */
81using StreamID = uint64_t;
82
84
85//=============================================================================
86// Endpoint description
87//=============================================================================
88
89/**
90 * @struct StreamEndpoint
91 * @brief Describes the remote (or local) side of a network stream.
92 *
93 * Analogous to Core::EndpointInfo but expressed in Portal vocabulary.
94 * NetworkFoundry translates this to Core::EndpointInfo when opening
95 * the underlying transport endpoint.
96 */
97struct MAYAFLUX_API StreamEndpoint {
98 std::string address; ///< Remote address. Empty = listen only.
99 uint16_t port { 0 }; ///< Remote port (send) or local port (receive).
100 uint16_t local_port { 0 }; ///< Explicit local bind port. 0 = OS-assigned.
101};
102
103//=============================================================================
104// Stream configuration
105//=============================================================================
106
107/**
108 * @struct StreamConfig
109 * @brief Full configuration for an outbound or bidirectional stream.
110 *
111 * Passed to NetworkFoundry::open_stream(). Mirrors the pattern of
112 * ShaderConfig / RenderPipelineConfig in Portal::Graphics.
113 */
114struct MAYAFLUX_API StreamConfig {
115 std::string name;
117 StreamProfile profile { StreamProfile::ARBITRARY };
118 NetworkTransportHint transport { NetworkTransportHint::AUTO };
119 FramingPolicy framing { FramingPolicy::NONE };
120};
121
122//=============================================================================
123// Payload helpers
124//=============================================================================
125
126/**
127 * @brief Convenience alias for a read-only byte view.
128 *
129 * All Portal::Network send functions accept this. Callers may pass
130 * std::vector<uint8_t>, std::array, raw pointer+size via std::span,
131 * or any contiguous range.
132 */
133using ByteView = std::span<const uint8_t>;
134
135} // namespace MayaFlux::Portal::Network
NetworkTransportHint
Portal-level transport hint, independent of Core::NetworkTransport.
@ SHARED_MEMORY
Zero-copy IPC on the same machine.
@ TCP
Reliable ordered byte stream. Bulk data, session-oriented.
@ AUTO
Let NetworkFoundry pick based on StreamProfile.
@ UDP
Low-latency, unordered datagrams. OSC, control, sparse streams.
std::span< const uint8_t > ByteView
Convenience alias for a read-only byte view.
uint64_t StreamID
Opaque handle returned by NetworkFoundry when a stream is opened.
StreamProfile
Data characteristics that drive transport and framing selection.
@ ORDERED_BULK
Large payloads, loss-intolerant, ordering required.
@ REALTIME_BULK
Large payloads, loss-tolerant, latency-sensitive.
@ REALTIME_SMALL
Small payloads, loss-tolerant, latency-sensitive.
FramingPolicy
How outbound payloads are framed on the wire.
constexpr StreamID INVALID_STREAM
Full configuration for an outbound or bidirectional stream.
std::string address
Remote address. Empty = listen only.
Describes the remote (or local) side of a network stream.