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>;
101 static absl::StatusOr<ChunkMetadata>
FromMsgpack(std::string_view bytes);
105 template <
typename Sink>
107 sink.Append(
value.DebugString());
145 [[nodiscard]]
virtual std::string_view
tag()
const = 0;
147 [[nodiscard]]
virtual std::string_view
mimetype()
const = 0;
149 [[nodiscard]]
virtual absl::StatusOr<Bytes>
Encode()
const = 0;
154 [[nodiscard]]
virtual const void* absl_nonnull
address()
const = 0;
184 std::shared_ptr<const ChunkObject>
object{};
193 [[nodiscard]]
bool IsEmpty()
const;
195 [[nodiscard]]
bool IsNull()
const;
200 [[nodiscard]]
bool HasObject()
const {
return object !=
nullptr; }
231 static absl::StatusOr<Chunk>
FromMsgpack(std::string_view bytes);
235 template <
typename Sink>
237 sink.Append(
value.DebugString());
260 bool closing =
false);
271 absl::flat_hash_map<std::string, std::string>
fields{};
293 std::vector<StorageService>
317 std::optional<StorageIdentity>
329 std::optional<std::string_view> service = std::nullopt)
const;
348 static absl::StatusOr<NodeRef>
FromMsgpack(std::string_view bytes);
352 template <
typename Sink>
354 sink.Append(
value.DebugString());
369 std::optional<std::uint32_t>
seq = {};
379 absl::StatusOr<Chunk* absl_nonnull>
GetChunk();
381 absl::StatusOr<const Chunk* absl_nonnull>
GetChunk()
const;
383 absl::StatusOr<NodeRef* absl_nonnull>
GetNodeRef();
385 absl::StatusOr<const NodeRef* absl_nonnull>
GetNodeRef()
const;
404 static absl::StatusOr<NodeFragment>
FromMsgpack(std::string_view bytes);
408 template <
typename Sink>
410 sink.Append(
value.DebugString());
448 static absl::StatusOr<Port>
FromMsgpack(std::string_view bytes);
452 template <
typename Sink>
454 sink.Append(
value.DebugString());
497 static absl::StatusOr<ActionMessage>
FromMsgpack(std::string_view bytes);
501 template <
typename Sink>
503 sink.Append(
value.DebugString());
547 static absl::StatusOr<WireMessage>
FromMsgpack(std::string_view bytes);
551 template <
typename Sink>
553 sink.Append(
value.DebugString());
An in-process value a chunk may carry instead of its encoded bytes.
Definition types.h:140
virtual std::string_view mimetype() const =0
The mimetype the value would be encoded as.
virtual const void *absl_nonnull address() const =0
An opaque address supplied by the object implementation.
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:100
std::string key
Definition discover.cc:764
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:251
absl::StatusOr< Chunk > MakeStatusChunk(const absl::Status &status, bool closing)
Encodes status as a chunk of mimetype kStatusMimetype.
Definition types.cc:419
size_t EmptyWireMessageSize()
The encoded size of an empty WireMessage.
Definition types.cc:1100
bool IsHalfCloseMessage(const WireMessage &message)
Whether message is a transport half-close signal.
Definition types.cc:1092
absl::Status ValidateName(std::string_view name)
Validates an A11 identifier (node/port/action name).
Definition types.cc:190
bool IsStatusChunk(const Chunk &chunk)
Whether chunk carries a packed status.
Definition types.cc:430
constexpr std::string_view kStatusMimetype
Mimetype marking a chunk whose payload is a packed status.
Definition types.h:242
WireMessage MakeHalfCloseMessage(ByteMap trailers)
Builds a half-close WireMessage carrying optional trailers.
Definition types.cc:1096
absl::StatusOr< absl::Status > StatusFromStatusChunk(const Chunk &chunk)
Decodes a status previously encoded by MakeStatusChunk.
Definition types.cc:439
bool IsCloseStatusChunk(const Chunk &chunk)
Whether chunk is a status chunk marking write-half closure.
Definition types.cc:434
absl::flat_hash_map< std::string, Bytes > ByteMap
String-keyed map of byte values (headers, attributes, etc.).
Definition types.h:58
std::optional< data::StorageCredentials > credentials
Definition runtime_streams.cc:38
The wire description of an action invocation.
Definition types.h:466
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:817
std::vector< Port > outputs
Output port -> node bindings.
Definition types.h:470
static absl::StatusOr< ActionMessage > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into an ActionMessage.
Definition types.cc:870
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this message as MessagePack bytes.
Definition types.cc:845
std::string id
Unique id of this action instance.
Definition types.h:467
friend bool operator==(const ActionMessage &, const ActionMessage &)=default
std::vector< Port > inputs
Input port -> node bindings.
Definition types.h:469
absl::Status Validate() const
Validate the invocation id, action name, ports, and headers.
Definition types.cc:825
std::string name
Registered action name.
Definition types.h:468
ByteMap headers
Per-call headers.
Definition types.h:471
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:855
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:803
friend void AbslStringify(Sink &sink, const ActionMessage &value)
Definition types.h:502
A unit of data: bytes plus optional descriptive metadata.
Definition types.h:173
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this chunk as MessagePack bytes.
Definition types.cc:367
std::optional< ChunkMetadata > metadata
Optional payload metadata.
Definition types.h:174
bool IsEmpty() const
Whether the chunk carries no data, reference or object.
Definition types.cc:325
friend bool operator==(const Chunk &, const Chunk &)=default
bool HasObject() const
Whether this chunk is carrying a value rather than bytes.
Definition types.h:200
absl::Status Validate() const
Validate that payload, reference, and metadata fields are consistent.
Definition types.cc:336
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:377
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:317
Bytes data
Inline byte payload.
Definition types.h:176
size_t ApproxBytes() const
Estimate memory/wire weight for bounded-buffer accounting.
Definition types.cc:308
friend void AbslStringify(Sink &sink, const Chunk &value)
Definition types.h:236
static absl::StatusOr< Chunk > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a Chunk.
Definition types.cc:392
std::string GetMimetype() const
Returns the metadata mimetype, or empty when unset.
Definition types.cc:321
bool IsNull() const
Whether the chunk represents an explicit null value.
Definition types.cc:332
absl::Status Materialize()
Produces data from object, if it has not been produced yet.
Definition types.cc:347
std::string ref
Node id this chunk references, if not inline.
Definition types.h:175
One piece of a node's stream: an inline chunk or a node reference.
Definition types.h:366
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this fragment as MessagePack bytes.
Definition types.cc:676
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:631
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:625
absl::StatusOr< Chunk *absl_nonnull > GetChunk()
Returns the held Chunk, or an error when it holds a NodeRef.
Definition types.cc:648
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:662
friend void AbslStringify(Sink &sink, const NodeFragment &value)
Definition types.h:409
std::variant< Chunk, NodeRef > data
Inline chunk or reference.
Definition types.h:368
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:686
absl::Status Validate() const
Validate the node id, payload, sequence, and continuation marker.
Definition types.cc:641
bool continued
Whether further fragments follow this one.
Definition types.h:370
std::optional< std::uint32_t > seq
Ordering sequence number.
Definition types.h:369
static absl::StatusOr< NodeFragment > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a NodeFragment.
Definition types.cc:705
A reference to a (slice of a) logical node, in lieu of inline data.
Definition types.h:311
absl::Status Validate() const
Validate the referenced node id and requested slice.
Definition types.cc:551
std::optional< std::uint64_t > length
Optional fragment count.
Definition types.h:316
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:540
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:573
std::optional< StorageIdentity > storage
Host-resolved storage identity.
Definition types.h:318
absl::StatusOr< NodeRef > WithCredentials(StorageCredentials credentials, std::optional< std::string_view > service=std::nullopt) const
Return a qualified copy with the selected access fields.
Definition types.cc:500
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this reference as MessagePack bytes.
Definition types.cc:563
friend void AbslStringify(Sink &sink, const NodeRef &value)
Definition types.h:353
static absl::StatusOr< NodeRef > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a NodeRef.
Definition types.cc:590
std::uint32_t offset
First referenced fragment sequence.
Definition types.h:313
size_t ApproxBytes() const
Estimate memory/wire weight for bounded-buffer accounting.
Definition types.cc:535
std::string id
Id of the referenced node.
Definition types.h:312
Binds an action's port name to the concrete node id serving it.
Definition types.h:420
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this port as MessagePack bytes.
Definition types.cc:774
size_t ApproxBytes() const
Estimate memory/wire weight for session and transport limits.
Definition types.cc:757
std::string name
Schema-defined port name.
Definition types.h:421
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:784
static absl::StatusOr< Port > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a Port.
Definition types.cc:790
friend void AbslStringify(Sink &sink, const Port &value)
Definition types.h:453
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:767
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:761
std::string id
Id of the node backing this port.
Definition types.h:422
Scheme-labelled credential fields supplied to a host storage resolver.
Definition types.h:269
friend bool operator==(const StorageCredentials &, const StorageCredentials &)=default
std::string scheme
Authentication scheme interpreted by the host.
Definition types.h:270
absl::Status Validate() const
Validate the scheme and field names.
Definition types.cc:453
absl::flat_hash_map< std::string, std::string > fields
Scheme fields.
Definition types.h:271
Logical namespace with optional host-interpreted backend access information.
Definition types.h:290
std::string DebugString() const
Describe the namespace without printing credentials.
Definition types.cc:529
absl::Status Validate() const
Validate the namespace and its service metadata.
Definition types.cc:469
size_t ApproxBytes() const
Estimate wire weight, including credential fields.
Definition types.cc:480
std::vector< StorageService > services
Optional backend access metadata.
Definition types.h:294
friend bool operator==(const StorageIdentity &, const StorageIdentity &)=default
std::optional< StorageCredentials > credentials
Namespace access.
Definition types.h:292
One named service participating in a storage backend.
Definition types.h:279
std::optional< StorageCredentials > credentials
Optional access fields.
Definition types.h:282
absl::Status Validate() const
Validate service identity and authentication metadata.
Definition types.cc:461
friend bool operator==(const StorageService &, const StorageService &)=default
std::string endpoint
Host-interpreted endpoint.
Definition types.h:281
std::string role
Service role within the backend.
Definition types.h:280
The top-level frame exchanged between two A11 endpoints.
Definition types.h:516
friend void AbslStringify(Sink &sink, const WireMessage &value)
Definition types.h:552
std::string DebugString() const
Return a concise representation suitable for logs and diagnostics.
Definition types.cc:928
absl::Status Validate() const
Validate every contained fragment, action, and header.
Definition types.cc:995
ByteMap headers
Message-level headers.
Definition types.h:521
size_t ApproxBytes() const
Estimate memory/wire weight before admitting this message to a buffer.
Definition types.cc:914
absl::Status ToMsgpackInto(MsgpackWriter *absl_nonnull writer) const
Append this record's fields to an already-open writer.
Definition types.cc:1019
std::vector< ActionMessage > actions
Action invocations.
Definition types.h:520
static absl::StatusOr< WireMessage > FromMsgpack(std::string_view bytes)
Decodes MessagePack bytes into a WireMessage.
Definition types.cc:1038
static constexpr std::uint32_t kVersion
Wire format version.
Definition types.h:517
friend bool operator==(const WireMessage &, const WireMessage &)=default
std::vector< NodeFragment > node_fragments
Streamed data fragments.
Definition types.h:519
absl::StatusOr< Bytes > ToMsgpack() const
Encodes this message as MessagePack bytes.
Definition types.cc:1009