MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ as_composite_access()

MAYAFLUX_API std::optional< CompositeAccess > MayaFlux::Kakshya::as_composite_access ( const DataVariant &  elements,
const DataVariant &  text,
const DataVariant &  blob,
const CompositeLayout &  layout 
)

Validate and borrow packed Composite-compatible NDData.

Parameters
elementsDataVariant holding vector<uint8_t> packed elements.
textDataVariant holding vector<uint8_t> UTF-8 bytes.
blobDataVariant holding vector<uint8_t> binary bytes.
layoutFinalized layout for the packed elements.
Returns
Access view, or std::nullopt for incompatible storage or layout.
Note
This validates storage types, stride, and field extents. Individual text and binary offset bounds are checked when fields are read.

Definition at line 24 of file CompositeAccess.cpp.

27{
28 const auto* element_bytes = std::get_if<std::vector<uint8_t>>(&elements);
29 const auto* text_bytes = std::get_if<std::vector<uint8_t>>(&text);
30 const auto* blob_bytes = std::get_if<std::vector<uint8_t>>(&blob);
31 const size_t stride = layout.stride_bytes();
32 if (!element_bytes || !text_bytes || !blob_bytes || stride == 0
33 || element_bytes->size() % stride != 0) {
34 MF_WARN(Journal::Component::Kakshya, Journal::Context::Runtime,
35 "as_composite_access: invalid storage or element stride");
36 return std::nullopt;
37 }
38
39 for (const auto& field : layout.fields()) {
40 if (field.offset_bytes > stride || field.size_bytes > stride - field.offset_bytes
41 || ((field.type == typeid(std::string)
42 || field.type == typeid(std::vector<uint8_t>))
43 && field.size_bytes != 2 * sizeof(uint64_t))
44 || (field.type == typeid(detail::CompositeDynamic)
45 && field.size_bytes != 3 * sizeof(uint64_t))) {
46 MF_WARN(Journal::Component::Kakshya, Journal::Context::Runtime,
47 "as_composite_access: invalid layout for field '{}'", field.name);
48 return std::nullopt;
49 }
50 }
51
52 return CompositeAccess(elements, text, blob, layout);
53}
#define MF_WARN(comp, ctx,...)
size_t element_bytes
size_t stride_bytes() const noexcept
Bytes per packed element after finalization.
Definition Composite.hpp:86

Referenced by MayaFlux::Kakshya::CompositeArray::access().

+ Here is the caller graph for this function: