MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / __call_view__

Method __call_view__

crates/bindings-cpp/src/internal/Module.cpp:519–552  ·  view source on GitHub ↗

Dispatch function for views with ViewContext (has sender)

Source from the content-addressed store, hash-verified

517
518// Dispatch function for views with ViewContext (has sender)
519int16_t Module::__call_view__(
520 uint32_t id,
521 uint64_t sender_0, uint64_t sender_1, uint64_t sender_2, uint64_t sender_3,
522 BytesSource args_source,
523 BytesSink result_sink
524) {
525 // Check if view ID is valid
526 if (id >= g_view_handlers.size()) {
527 fprintf(stderr, "ERROR: Invalid view ID %u (have %zu views)\n",
528 id, g_view_handlers.size());
529 return -1; // NO_SUCH_VIEW
530 }
531
532 // Create sender identity from the 4 uint64_t parts
533 std::array<uint8_t, 32> sender_bytes{};
534 std::memcpy(sender_bytes.data(), &sender_0, 8);
535 std::memcpy(sender_bytes.data() + 8, &sender_1, 8);
536 std::memcpy(sender_bytes.data() + 16, &sender_2, 8);
537 std::memcpy(sender_bytes.data() + 24, &sender_3, 8);
538
539 Identity sender_identity(sender_bytes);
540
541 // Create view context
542 ViewContext ctx(sender_identity);
543
544 // Get the handler
545 const auto& handler_info = g_view_handlers[id];
546
547 // Call the view handler - returns fully serialized result data, including the header byte.
548 std::vector<uint8_t> result_data = handler_info.handler(ctx, args_source);
549 WriteBytes(result_sink, result_data);
550
551 return 2; // Success with data
552}
553
554// Dispatch function for views with AnonymousViewContext (no sender)
555int16_t Module::__call_view_anon__(

Callers

nothing calls this directly

Calls 3

WriteBytesFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected