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

◆ blob()

std::optional< std::span< const uint8_t > > MayaFlux::Kakshya::Composite::blob ( std::string_view  field_name) const
noexcept

Borrow the bytes of a fixed or dynamic BLOB field.

Definition at line 367 of file Composite.cpp.

368{
369 const auto field_index = m_layout->find_field(field_name);
370 if (!field_index || !has(field_name))
371 return std::nullopt;
372 const auto& field = m_layout->fields()[*field_index];
373 if (field.type != typeid(std::vector<uint8_t>) && field.type != typeid(detail::CompositeDynamic))
374 return std::nullopt;
375
376 const auto& rows = std::get<std::vector<uint8_t>>(*m_rows);
377 const auto* source = rows.data() + m_index * m_layout->stride_bytes() + field.offset_bytes;
378 TextSlice slice;
379 if (field.type == typeid(detail::CompositeDynamic)) {
380 DynamicCell cell;
381 std::memcpy(&cell, source, sizeof(cell));
382 if (cell.kind != blob_kind)
383 return std::nullopt;
384 slice = { cell.payload, cell.length };
385 } else {
386 std::memcpy(&slice, source, sizeof(slice));
387 }
388 const auto& blob = std::get<std::vector<uint8_t>>(*m_blob);
389 if (slice.offset > blob.size() || slice.length > blob.size() - slice.offset)
390 return std::nullopt;
391 if (slice.length == 0)
392 return std::span<const uint8_t> {};
393 return std::span<const uint8_t>(blob.data() + slice.offset, static_cast<size_t>(slice.length));
394}
uint32_t rows
size_t stride_bytes() const noexcept
Bytes per packed element after finalization.
Definition Composite.hpp:86
const std::vector< CompositeField > & fields() const noexcept
Declared fields in element order, with finalized byte offsets.
Definition Composite.hpp:82
std::optional< size_t > find_field(std::string_view name) const noexcept
Find a field index by name, or std::nullopt if absent.
Definition Composite.cpp:54
const CompositeLayout * m_layout
bool has(std::string_view field_name) const noexcept
Whether a named field exists and is present in this element.
std::optional< std::span< const uint8_t > > blob(std::string_view field_name) const noexcept
Borrow the bytes of a fixed or dynamic BLOB field.
std::vector< double > slice(std::span< const double > data, double start_ratio, double end_ratio)
Extract a contiguous slice by ratio, returning a new vector.
Source source()
Begin a Source chain.
Definition Plot.hpp:127

References rows.