36#ifndef A11_DATA_TYPES_H_
37#define A11_DATA_TYPES_H_
45#include <absl/base/nullability.h>
46#include <absl/container/flat_hash_map.h>
47#include <absl/status/status.h>
48#include <absl/status/statusor.h>
49#include <absl/time/time.h>
58using ByteMap = absl::flat_hash_map<std::string, Bytes>;
107 static absl::StatusOr<ChunkMetadata>
FromMsgpack(std::string_view bytes);
111 template <
typename Sink>
113 sink.Append(
value.DebugString());
151 [[nodiscard]]
virtual std::string_view
tag()
const = 0;
153 [[nodiscard]]
virtual std::string_view
mimetype()
const = 0;
155 [[nodiscard]]
virtual absl::StatusOr<Bytes>
Encode()
const = 0;
166 [[nodiscard]]
virtual const void* absl_nonnull
address()
const = 0;
196 std::shared_ptr<const ChunkObject>
object{};
205 [[nodiscard]]
bool IsEmpty()
const;
207 [[nodiscard]]
bool IsNull()
const;
212 [[nodiscard]]
bool HasObject()
const {
return object !=
nullptr; }
243 static absl::StatusOr<Chunk>
FromMsgpack(std::string_view bytes);
247 template <
typename Sink>
249 sink.Append(
value.DebugString());
272 bool closing =
false);
317 static absl::StatusOr<NodeRef>
FromMsgpack(std::string_view bytes);
321 template <
typename Sink>
323 sink.Append(
value.DebugString());
338 std::optional<std::uint32_t>
seq = {};
348 absl::StatusOr<Chunk* absl_nonnull>
GetChunk();
350 absl::StatusOr<const Chunk* absl_nonnull>
GetChunk()
const;
352 absl::StatusOr<NodeRef* absl_nonnull>
GetNodeRef();
354 absl::StatusOr<const NodeRef* absl_nonnull>
GetNodeRef()
const;
373 static absl::StatusOr<NodeFragment>
FromMsgpack(std::string_view bytes);
377 template <
typename Sink>
379 sink.Append(
value.DebugString());
417 static absl::StatusOr<Port>
FromMsgpack(std::string_view bytes);
421 template <
typename Sink>
423 sink.Append(
value.DebugString());
466 static absl::StatusOr<ActionMessage>
FromMsgpack(std::string_view bytes);
470 template <
typename Sink>
472 sink.Append(
value.DebugString());
516 static absl::StatusOr<WireMessage>
FromMsgpack(std::string_view bytes);
520 template <
typename Sink>
522 sink.Append(
value.DebugString());
An in-process value a chunk may carry instead of its encoded bytes.
Definition types.h:146
virtual std::string_view mimetype() const =0
The mimetype the value would be encoded as.
virtual const void *absl_nonnull address() const =0
The address of the held value.
virtual absl::StatusOr< Bytes > Encode() const =0
Encodes the value, for whoever needs bytes after all.
virtual size_t ApproxBytes() const =0
A size estimate that does not encode anything.
virtual std::string_view tag() const =0
The serialisation tag of the held type.
virtual ~ChunkObject()=default
Incrementally encode the fields of one A11 wire record.
Definition msgpack.h:44
std::string value
Definition discover.cc:114
std::string key
Definition discover.cc:782
std::string Bytes
Raw byte payload; an alias of std::string.
Definition types.h:56
constexpr std::string_view kCloseAttribute
Metadata attribute marking a status chunk as a closure marker.
Definition types.h:263
absl::StatusOr< Chunk > MakeStatusChunk(const absl::Status &status, bool closing)
Encodes status as a chunk of mimetype kStatusMimetype.
Definition types.cc:418
size_t EmptyWireMessageSize()
The encoded size of an empty WireMessage.
Definition types.cc:996
bool IsHalfCloseMessage(const WireMessage &message)
Whether message is a transport half-close signal.
Definition types.cc:988
absl::Status ValidateName(std::string_view name)
Validates an A11 identifier (node/port/action name).
Definition types.cc:189
bool IsStatusChunk(const Chunk &chunk)
Whether chunk carries a packed status.
Definition types.cc:429
constexpr std::string_view kStatusMimetype
Mimetype marking a chunk whose payload is a packed status.
Definition types.h:254
WireMessage MakeHalfCloseMessage(ByteMap trailers)
Builds a half-close WireMessage carrying optional trailers.
Definition types.cc:992
absl::StatusOr< absl::Status > StatusFromStatusChunk(const Chunk &chunk)
Decodes a status previously encoded by MakeStatusChunk.
Definition types.cc:438
bool IsCloseStatusChunk(const Chunk &chunk)
Whether chunk is a status chunk marking write-half closure.
Definition types.cc:433
absl::flat_hash_map< std::string, Bytes > ByteMap
String-keyed map of byte values (headers, attributes, etc.).
Definition types.h:58
The wire description of an action invocation.
Definition types.h:435
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:713
std::vector< Port > outputs
Output port -> node bindings.
Definition types.h:439
static absl::StatusOr< ActionMessage > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into an ActionMessage.
Definition types.cc:766
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this message as MessagePack bytes.
Definition types.cc:741
std::string id
Unique id of this action instance.
Definition types.h:436
friend bool operator==(const ActionMessage &, const ActionMessage &)=default
std::vector< Port > inputs
Input port -> node bindings.
Definition types.h:438
absl::Status Validate() const
Validate the invocation id, action name, ports, and headers.
Definition types.cc:721
std::string name
Registered action name.
Definition types.h:437
ByteMap headers
Per-call headers.
Definition types.h:440
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:751
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:699
friend void AbslStringify(Sink &sink, const ActionMessage &value)
Definition types.h:471
A unit of data: bytes plus optional descriptive metadata.
Definition types.h:185
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this chunk as MessagePack bytes.
Definition types.cc:366
std::optional< ChunkMetadata > metadata
Optional payload metadata.
Definition types.h:186
bool IsEmpty() const
Whether the chunk carries no data, reference or object.
Definition types.cc:324
friend bool operator==(const Chunk &, const Chunk &)=default
bool HasObject() const
Whether this chunk is carrying a value rather than bytes.
Definition types.h:212
absl::Status Validate() const
Validate that payload, reference, and metadata fields are consistent.
Definition types.cc:335
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:376
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:316
Bytes data
Inline byte payload.
Definition types.h:188
size_t ApproxBytes() const
Estimate memory/wire weight for bounded-buffer accounting.
Definition types.cc:307
friend void AbslStringify(Sink &sink, const Chunk &value)
Definition types.h:248
static absl::StatusOr< Chunk > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a Chunk.
Definition types.cc:391
std::string GetMimetype() const
Returns the metadata mimetype, or empty when unset.
Definition types.cc:320
bool IsNull() const
Whether the chunk represents an explicit null value.
Definition types.cc:331
absl::Status Materialize()
Produces data from object, if it has not been produced yet.
Definition types.cc:346
std::string ref
Node id this chunk references, if not inline.
Definition types.h:187
One piece of a node's stream: an inline chunk or a node reference.
Definition types.h:335
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this fragment as MessagePack bytes.
Definition types.cc:572
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:527
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:521
absl::StatusOr< Chunk *absl_nonnull > GetChunk()
Returns the held Chunk, or an error when it holds a NodeRef.
Definition types.cc:544
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:558
friend void AbslStringify(Sink &sink, const NodeFragment &value)
Definition types.h:378
std::variant< Chunk, NodeRef > data
Inline chunk or reference.
Definition types.h:337
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:582
absl::Status Validate() const
Validate the node id, payload, sequence, and continuation marker.
Definition types.cc:537
bool continued
Whether further fragments follow this one.
Definition types.h:339
std::optional< std::uint32_t > seq
Ordering sequence number.
Definition types.h:338
static absl::StatusOr< NodeFragment > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a NodeFragment.
Definition types.cc:601
A reference to a (slice of a) logical node, in lieu of inline data.
Definition types.h:286
absl::Status Validate() const
Validate the referenced node id and requested slice.
Definition types.cc:463
std::optional< std::uint64_t > length
Optional length of the window.
Definition types.h:291
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:456
friend bool operator==(const NodeRef &, const NodeRef &)=default
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:482
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this reference as MessagePack bytes.
Definition types.cc:472
friend void AbslStringify(Sink &sink, const NodeRef &value)
Definition types.h:322
static absl::StatusOr< NodeRef > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a NodeRef.
Definition types.cc:493
std::uint32_t offset
Byte offset into the referenced node.
Definition types.h:288
size_t ApproxBytes() const
Estimate memory/wire weight for bounded-buffer accounting.
Definition types.cc:452
std::string id
Id of the referenced node.
Definition types.h:287
Binds an action's port name to the concrete node id serving it.
Definition types.h:389
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this port as MessagePack bytes.
Definition types.cc:670
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:653
std::string name
Schema-defined port name.
Definition types.h:390
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:680
static absl::StatusOr< Port > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a Port.
Definition types.cc:686
friend void AbslStringify(Sink &sink, const Port &value)
Definition types.h:422
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:663
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:657
std::string id
Id of the node backing this port.
Definition types.h:391
The top-level frame exchanged between two A11 endpoints.
Definition types.h:485
friend void AbslStringify(Sink &sink, const WireMessage &value)
Definition types.h:521
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:824
absl::Status Validate() const
Validate every contained fragment, action, and header.
Definition types.cc:891
ByteMap headers
Message-level headers.
Definition types.h:490
size_t ApproxBytes() const
Estimate memory/wire weight before admitting this message to a buffer.
Definition types.cc:810
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:915
std::vector< ActionMessage > actions
Action invocations.
Definition types.h:489
static absl::StatusOr< WireMessage > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a WireMessage.
Definition types.cc:934
static constexpr std::uint32_t kVersion
Wire format version.
Definition types.h:486
friend bool operator==(const WireMessage &, const WireMessage &)=default
std::vector< NodeFragment > node_fragments
Streamed data fragments.
Definition types.h:488
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this message as MessagePack bytes.
Definition types.cc:905