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

◆ encode() [2/2]

bool MayaFlux::Nexus::StateEncoder::encode ( const Tapestry &  tapestry,
const std::string &  base_dir,
nlohmann::json  user_state = {} 
)

Encode all Fabrics in tapestry to base_dir.

Writes one EXR+JSON pair per Fabric under base_dir/{fabric_name_or_id}, then writes base_dir/tapestry.json as the envelope.

Parameters
tapestrySource Tapestry.
base_dirDirectory path. Must exist.
Returns
True on success.

Definition at line 526 of file Encoder.cpp.

527{
528 m_last_error.clear();
529
530 State::TapestrySchema schema;
531
532 std::unordered_set<const Expanse*> tapestry_owned;
533 for (const auto& [xname, xptr] : tapestry.all_expanses()) {
534 tapestry_owned.insert(xptr.get());
535 }
536
537 for (const auto& fabric : tapestry.all_fabrics()) {
538 const std::string fabric_id = fabric->name().empty()
539 ? std::to_string(fabric->id())
540 : fabric->name();
541
542 const std::string base_path = base_dir + "/" + fabric_id;
543
544 if (!encode_fabric(*fabric, base_path, tapestry_owned)) {
545 return false;
546 }
547
548 schema.fabrics.push_back(State::FabricRef {
549 .name = fabric_id,
550 .base_path = base_path,
551 });
552 }
553
554 for (const auto& [xname, xptr] : tapestry.all_expanses()) {
555 State::TapestryExpanseRecord xrec { .name = xname };
556 fill_expanse(xrec, *xptr);
557 for (const auto& fabric : tapestry.all_fabrics()) {
558 for (uint32_t xid : fabric->all_expanse_ids()) {
559 if (fabric->get_expanse(xid) == xptr) {
560 const std::string fname = fabric->name().empty()
561 ? std::to_string(fabric->id())
562 : fabric->name();
563 xrec.fabric_names.push_back(fname);
564 break;
565 }
566 }
567 }
568 schema.expanses.push_back(std::move(xrec));
569 }
570
571 schema.user_state = std::move(user_state);
572
573 IO::JSONSerializer ser;
574 const std::string tapestry_path = base_dir + "/tapestry.json";
575 if (!ser.write(tapestry_path, schema)) {
576 m_last_error = "Failed to write tapestry schema: " + ser.last_error();
578 return false;
579 }
580
582 "StateEncoder: wrote {} fabrics to {}", schema.fabrics.size(), tapestry_path);
583 return true;
584}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
std::string name
Definition VKDevice.cpp:123
static void fill_expanse(Record &record, const Expanse &expanse)
Definition Encoder.cpp:170
bool encode_fabric(const Fabric &fabric, const std::string &base_path, const std::unordered_set< const Expanse * > &tapestry_owned)
Definition Encoder.cpp:199
@ FileIO
Filesystem I/O operations.
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.

References MayaFlux::Nexus::Tapestry::all_expanses(), MayaFlux::Nexus::Tapestry::all_fabrics(), MayaFlux::Nexus::State::TapestrySchema::expanses, MayaFlux::Nexus::State::TapestrySchema::fabrics, MayaFlux::Journal::FileIO, MayaFlux::IO::JSONSerializer::last_error(), MF_ERROR, MF_INFO, MayaFlux::Nexus::State::FabricRef::name, MayaFlux::Nexus::State::TapestryExpanseRecord::name, MayaFlux::Journal::Nexus, MayaFlux::Nexus::State::TapestrySchema::user_state, and MayaFlux::IO::JSONSerializer::write().

+ Here is the call graph for this function: