|
A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
|
A unit of data: bytes plus optional descriptive metadata. More...
#include <cpp/a11/data/types.h>
Public Member Functions | |
| size_t | ApproxBytes () const |
| Estimate memory/wire weight for bounded-buffer accounting. | |
| std::string | DebugString () const |
| Return a concise representation suitable for logs and diagnostics. | |
| std::string | GetMimetype () const |
| Returns the metadata mimetype, or empty when unset. | |
| bool | IsEmpty () const |
| Whether the chunk carries no data, reference or object. | |
| bool | IsNull () const |
| Whether the chunk represents an explicit null value. | |
| absl::Status | Validate () const |
| Validate that payload, reference, and metadata fields are consistent. | |
| bool | HasObject () const |
| Whether this chunk is carrying a value rather than bytes. | |
| absl::Status | Materialize () |
Produces data from object, if it has not been produced yet. | |
| absl::StatusOr< Bytes > | ToMsgpack () const |
| Encodes this chunk as MessagePack bytes. | |
| absl::Status | ToMsgpackInto (MsgpackWriter *absl_nonnull writer) const |
Append this record's fields to an already-open writer. | |
Static Public Member Functions | |
| static absl::StatusOr< Chunk > | FromMsgpack (std::string_view bytes) |
Decodes MessagePack bytes into a Chunk. | |
Public Attributes | |
| std::optional< ChunkMetadata > | metadata {} |
| Optional payload metadata. | |
| std::string | ref {} |
| Node id this chunk references, if not inline. | |
| Bytes | data {} |
| Inline byte payload. | |
| std::shared_ptr< const ChunkObject > | object {} |
| The value this chunk stands for, when its bytes have not been produced. | |
Friends | |
| bool | operator== (const Chunk &, const Chunk &)=default |
| template<typename Sink > | |
| void | AbslStringify (Sink &sink, const Chunk &value) |
A unit of data: bytes plus optional descriptive metadata.
A chunk holds its payload in data with an optional metadata describing it. Instead of inline data a chunk may instead carry a ref naming another node whose content it stands in for; such a reference must be resolved before the payload is used.
A third possibility exists and is local to one process: an object, whose bytes have not been produced because nothing has needed them. See a11::data::ChunkObject, and note the one invariant that matters to everybody else – an object-carrying chunk is not empty, even though data is, which is why IsEmpty() consults all three fields. A chunk that read as empty would read as a null stream terminator, and would end a stream that was only getting started.
| size_t a11::data::Chunk::ApproxBytes | ( | ) | const |
Estimate memory/wire weight for bounded-buffer accounting.
| std::string a11::data::Chunk::DebugString | ( | ) | const |
Return a concise representation suitable for logs and diagnostics.
|
static |
Decodes MessagePack bytes into a Chunk.
| std::string a11::data::Chunk::GetMimetype | ( | ) | const |
Returns the metadata mimetype, or empty when unset.
|
inline |
Whether this chunk is carrying a value rather than bytes.
| bool a11::data::Chunk::IsEmpty | ( | ) | const |
Whether the chunk carries no data, reference or object.
| bool a11::data::Chunk::IsNull | ( | ) | const |
Whether the chunk represents an explicit null value.
| absl::Status a11::data::Chunk::Materialize | ( | ) |
Produces data from object, if it has not been produced yet.
Idempotent, and a no-op on a chunk that already has its bytes. Called at every boundary where bytes are required – a persisting store, an attached stream, a reader asking for a chunk – which is what keeps object an optimisation rather than a second representation everybody has to know about. The object is released afterwards, so the bytes become the single answer once they exist.
| absl::StatusOr< Bytes > a11::data::Chunk::ToMsgpack | ( | ) | const |
Encodes this chunk as MessagePack bytes.
| absl::Status a11::data::Chunk::ToMsgpackInto | ( | MsgpackWriter *absl_nonnull | writer | ) | const |
Append this record's fields to an already-open writer.
What ToMsgpack() is built from, and what a parent record calls through MsgpackWriter::PackRecord so that nesting costs no buffer of its own. Both produce the same bytes; this one avoids the intermediate string.
Assumes the record is already valid. Validate() recurses through nested records, so validating here as well would re-check every nested id once per ancestor level. ToMsgpack() validates the whole tree once and then calls this; a caller reaching for this directly should do the same, and any caller that got its record from FromMsgpack() already has.
| absl::Status a11::data::Chunk::Validate | ( | ) | const |
Validate that payload, reference, and metadata fields are consistent.
|
friend |
| Bytes a11::data::Chunk::data {} |
Inline byte payload.
| std::optional<ChunkMetadata> a11::data::Chunk::metadata {} |
Optional payload metadata.
| std::shared_ptr<const ChunkObject> a11::data::Chunk::object {} |
The value this chunk stands for, when its bytes have not been produced.
Never crosses a process boundary: everything that sends, persists or hands out bytes calls Materialize() first, so a peer and a durable store see exactly what they saw before this field existed.
| std::string a11::data::Chunk::ref {} |
Node id this chunk references, if not inline.