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

Method __call_procedure__

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

Dispatch function for procedures

Source from the content-addressed store, hash-verified

579
580// Dispatch function for procedures
581int16_t Module::__call_procedure__(
582 uint32_t id,
583 uint64_t sender_0, uint64_t sender_1, uint64_t sender_2, uint64_t sender_3,
584 uint64_t conn_id_0, uint64_t conn_id_1,
585 uint64_t timestamp_microseconds,
586 BytesSource args_source,
587 BytesSink result_sink
588) {
589 // Check if procedure ID is valid
590 if (id >= g_procedure_handlers.size()) {
591 fprintf(stderr, "ERROR: Invalid procedure ID %u (have %zu procedures)\n",
592 id, g_procedure_handlers.size());
593 return -1; // NO_SUCH_PROCEDURE
594 }
595
596 // Create sender identity from the 4 uint64_t parts
597 std::array<uint8_t, 32> sender_bytes{};
598 std::memcpy(sender_bytes.data(), &sender_0, 8);
599 std::memcpy(sender_bytes.data() + 8, &sender_1, 8);
600 std::memcpy(sender_bytes.data() + 16, &sender_2, 8);
601 std::memcpy(sender_bytes.data() + 24, &sender_3, 8);
602
603 Identity sender_identity(sender_bytes);
604
605 // Create timestamp from microseconds
606 Timestamp timestamp = Timestamp::from_micros_since_epoch(
607 static_cast<int64_t>(timestamp_microseconds));
608
609 // Create connection ID from the two 64-bit parts (full 128-bit value)
610 ConnectionId connection_id;
611 if (conn_id_0 != 0 || conn_id_1 != 0) {
612 connection_id = ConnectionId(u128(conn_id_1, conn_id_0));
613 }
614
615 // Create procedure context
616 ProcedureContext ctx(sender_identity, timestamp, connection_id);
617
618 // Get the handler
619 const auto& handler_info = g_procedure_handlers[id];
620
621 // Call the procedure handler - this may trap if there's an error
622 std::vector<uint8_t> result_data = handler_info.handler(ctx, args_source);
623
624 // If we got here, procedure succeeded - write result
625 WriteBytes(result_sink, result_data);
626
627 return 0; // Success (StatusCode::OK)
628}
629
630int16_t Module::__call_http_handler__(
631 uint32_t id,

Callers

nothing calls this directly

Calls 5

WriteBytesFunction · 0.85
ConnectionIdClass · 0.50
u128Class · 0.50
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected