MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / deserialize

Function deserialize

examples/serialize.cc:42–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void deserialize(std::vector<uint8_t> buffer) {
43 std::cout << "Initializing...\n";
44 Engine engine;
45 Store store(engine);
46
47 std::cout << "Deserialize module...\n";
48 Module module =
49 Module::deserialize(engine, Span<uint8_t>(buffer.data(), buffer.size()))
50 .unwrap();
51
52 std::cout << "Creating callback...\n";
53 Func hello_func = Func::wrap(store, []() {
54 std::cout << "Calling back...\n";
55 std::cout << "> Hello World!\n";
56 });
57
58 std::cout << "Instantiating module...\n";
59 Instance instance = Instance::create(store, module, {hello_func}).unwrap();
60
61 std::cout << "Extracting export...\n";
62 Func run = std::get<Func>(*instance.get(store, "run"));
63
64 std::cout << "Calling export...\n";
65 run.call(store, {}).unwrap();
66
67 std::cout << "Done.\n";
68}
69
70int main() {
71 auto buffer = serialize();

Callers 1

mainFunction · 0.70

Calls 6

createFunction · 0.50
unwrapMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected