MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / strToComponentString

Function strToComponentString

examples/plugin/wasmedge-zlib/main.cpp:134–152  ·  view source on GitHub ↗

Helper function to convert std::string to zlib_component_string_t

Source from the content-addressed store, hash-verified

132
133// Helper function to convert std::string to zlib_component_string_t
134static void strToComponentString(const std::string &Str,
135 zlib_component_string_t *CompStr) {
136 if (Str.empty()) {
137 CompStr->ptr = nullptr;
138 CompStr->len = 0;
139 return;
140 }
141 CompStr->ptr = static_cast<uint8_t *>(
142 canonical_abi_realloc(nullptr, 0, 1, Str.length()));
143 if (CompStr->ptr) {
144 memcpy(CompStr->ptr, Str.data(), Str.length());
145 CompStr->len = Str.length();
146 } else {
147 CompStr->len = 0; // Allocation failed
148 fprintf(
149 stderr,
150 "ABI Layer Error: Memory allocation failed for string conversion.\n");
151 }
152}
153
154bool exports_example_zlib_compressor_deflate(zlib_component_list_u8_t *input,
155 zlib_component_list_u8_t *ret_ok,

Calls 3

canonical_abi_reallocFunction · 0.85
emptyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected