22#ifndef A11_DATA_TYPES_H_
23#define A11_DATA_TYPES_H_
31#include <absl/base/nullability.h>
32#include <absl/container/flat_hash_map.h>
33#include <absl/status/status.h>
34#include <absl/status/statusor.h>
35#include <absl/time/time.h>
42using ByteMap = absl::flat_hash_map<std::string, Bytes>;
70 absl::StatusOr<std::string>
GetAttribute(std::string_view key)
const;
72 absl::Status
SetAttribute(std::string key, std::string value);
77 static absl::StatusOr<ChunkMetadata>
FromMsgpack(std::string_view bytes);
81 template <
typename Sink>
116 static absl::StatusOr<Chunk>
FromMsgpack(std::string_view bytes);
120 template <
typename Sink>
149 static absl::StatusOr<NodeRef>
FromMsgpack(std::string_view bytes);
153 template <
typename Sink>
170 std::optional<std::uint32_t>
seq;
180 absl::StatusOr<Chunk* absl_nonnull>
GetChunk();
182 absl::StatusOr<const Chunk* absl_nonnull>
GetChunk()
const;
184 absl::StatusOr<NodeRef* absl_nonnull>
GetNodeRef();
186 absl::StatusOr<const NodeRef* absl_nonnull>
GetNodeRef()
const;
191 static absl::StatusOr<NodeFragment>
FromMsgpack(std::string_view bytes);
195 template <
typename Sink>
221 static absl::StatusOr<Port>
FromMsgpack(std::string_view bytes);
225 template <
typename Sink>
256 static absl::StatusOr<ActionMessage>
FromMsgpack(std::string_view bytes);
260 template <
typename Sink>
292 static absl::StatusOr<WireMessage>
FromMsgpack(std::string_view bytes);
296 template <
typename Sink>
std::string Bytes
Raw byte payload; an alias of std::string.
Definition types.h:40
size_t EmptyWireMessageSize()
The encoded size of an empty WireMessage.
Definition types.cc:1036
bool IsHalfCloseMessage(const WireMessage &message)
Whether message is a transport half-close signal.
Definition types.cc:1028
absl::Status ValidateName(std::string_view name)
Validates an A11 identifier (node/port/action name).
Definition types.cc:163
WireMessage MakeHalfCloseMessage(ByteMap trailers)
Builds a half-close WireMessage carrying optional trailers.
Definition types.cc:1032
absl::flat_hash_map< std::string, Bytes > ByteMap
String-keyed map of byte values (headers, attributes, etc.).
Definition types.h:42
Future< T > SubmitWithCancellationHook(absl::AnyInvocable< absl::StatusOr< T >() && > work, std::function< void()> cancellation_hook, thread::TreeOptions tree_options)
Run work on A11's fiber pool with application-specific cancellation.
Definition executor.h:30
The wire description of an action invocation.
Definition types.h:239
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:686
std::vector< Port > outputs
Output port -> node bindings.
Definition types.h:243
static absl::StatusOr< ActionMessage > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into an ActionMessage.
Definition types.cc:762
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this message as MessagePack bytes.
Definition types.cc:725
std::string id
Unique id of this action instance.
Definition types.h:240
friend bool operator==(const ActionMessage &, const ActionMessage &)=default
std::vector< Port > inputs
Input port -> node bindings.
Definition types.h:242
absl::Status Validate() const
Validate the invocation id, action name, ports, and headers.
Definition types.cc:694
std::string name
Registered action name.
Definition types.h:241
ByteMap headers
Per-call headers.
Definition types.h:244
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:675
friend void AbslStringify(Sink &sink, const ActionMessage &value)
Definition types.h:261
A unit of data: bytes plus optional descriptive metadata.
Definition types.h:95
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this chunk as MessagePack bytes.
Definition types.cc:314
std::optional< ChunkMetadata > metadata
Optional payload metadata.
Definition types.h:96
bool IsEmpty() const
Whether the chunk carries neither data nor a reference.
Definition types.cc:299
friend bool operator==(const Chunk &, const Chunk &)=default
absl::Status Validate() const
Validate that payload, reference, and metadata fields are consistent.
Definition types.cc:307
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:291
Bytes data
Inline byte payload.
Definition types.h:98
size_t ApproxBytes() const
Estimate memory/wire weight for bounded-buffer accounting.
Definition types.cc:286
friend void AbslStringify(Sink &sink, const Chunk &value)
Definition types.h:121
static absl::StatusOr< Chunk > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a Chunk.
Definition types.cc:338
std::string GetMimetype() const
Returns the metadata mimetype, or empty when unset.
Definition types.cc:295
bool IsNull() const
Whether the chunk represents an explicit null value.
Definition types.cc:303
std::string ref
Node id this chunk references, if not inline.
Definition types.h:97
One piece of a node's stream: an inline chunk or a node reference.
Definition types.h:167
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this fragment as MessagePack bytes.
Definition types.cc:512
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:469
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:463
absl::StatusOr< Chunk *absl_nonnull > GetChunk()
Returns the held Chunk, or an error when it holds a NodeRef.
Definition types.cc:488
friend bool operator==(const NodeFragment &, const NodeFragment &)=default
absl::StatusOr< NodeRef *absl_nonnull > GetNodeRef()
Returns the held NodeRef, or an error when it holds a Chunk.
Definition types.cc:500
friend void AbslStringify(Sink &sink, const NodeFragment &value)
Definition types.h:196
std::variant< Chunk, NodeRef > data
Inline chunk or reference.
Definition types.h:169
std::string id
Id of the node this fragment belongs to.
Definition types.h:168
absl::Status Validate() const
Validate the node id, payload, sequence, and continuation marker.
Definition types.cc:479
bool continued
Whether further fragments follow this one.
Definition types.h:171
std::optional< std::uint32_t > seq
Ordering sequence number.
Definition types.h:170
static absl::StatusOr< NodeFragment > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a NodeFragment.
Definition types.cc:541
A reference to a (slice of a) logical node, in lieu of inline data.
Definition types.h:132
absl::Status Validate() const
Validate the referenced node id and requested slice.
Definition types.cc:391
std::optional< std::uint64_t > length
Optional length of the window.
Definition types.h:137
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:384
friend bool operator==(const NodeRef &, const NodeRef &)=default
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this reference as MessagePack bytes.
Definition types.cc:402
friend void AbslStringify(Sink &sink, const NodeRef &value)
Definition types.h:154
static absl::StatusOr< NodeRef > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a NodeRef.
Definition types.cc:420
std::uint32_t offset
Byte offset into the referenced node.
Definition types.h:134
size_t ApproxBytes() const
Estimate memory/wire weight for bounded-buffer accounting.
Definition types.cc:380
std::string id
Id of the referenced node.
Definition types.h:133
Binds an action's port name to the concrete node id serving it.
Definition types.h:207
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this port as MessagePack bytes.
Definition types.cc:637
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:617
std::string name
Schema-defined port name.
Definition types.h:208
static absl::StatusOr< Port > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a Port.
Definition types.cc:651
friend void AbslStringify(Sink &sink, const Port &value)
Definition types.h:226
friend bool operator==(const Port &, const Port &)=default
absl::Status Validate() const
Validate the port name and node id used to bind an action.
Definition types.cc:627
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:621
std::string id
Id of the node backing this port.
Definition types.h:209
The top-level frame exchanged between two A11 endpoints.
Definition types.h:275
friend void AbslStringify(Sink &sink, const WireMessage &value)
Definition types.h:297
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:843
absl::Status Validate() const
Validate every contained fragment, action, and header.
Definition types.cc:906
ByteMap headers
Message-level headers.
Definition types.h:280
size_t ApproxBytes() const
Estimate memory/wire weight before admitting this message to a buffer.
Definition types.cc:831
std::vector< ActionMessage > actions
Action invocations.
Definition types.h:279
static absl::StatusOr< WireMessage > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a WireMessage.
Definition types.cc:961
static constexpr std::uint32_t kVersion
Wire format version.
Definition types.h:276
friend bool operator==(const WireMessage &, const WireMessage &)=default
std::vector< NodeFragment > node_fragments
Streamed data fragments.
Definition types.h:278
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this message as MessagePack bytes.
Definition types.cc:927