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

Function vecToListU8

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

Helper function to convert std::vector to zlib_component_list_u8_t

Source from the content-addressed store, hash-verified

112
113// Helper function to convert std::vector<uint8_t> to zlib_component_list_u8_t
114static void vecToListU8(const std::vector<uint8_t> &Vec,
115 zlib_component_list_u8_t *List) {
116 if (Vec.empty()) {
117 List->ptr = nullptr;
118 List->len = 0;
119 return;
120 }
121 List->ptr =
122 static_cast<uint8_t *>(canonical_abi_realloc(nullptr, 0, 1, Vec.size()));
123 if (List->ptr) {
124 memcpy(List->ptr, Vec.data(), Vec.size());
125 List->len = Vec.size();
126 } else {
127 List->len = 0; // Allocation failed
128 fprintf(stderr, "ABI Layer Error: Memory allocation failed for list_u8_t "
129 "conversion.\n");
130 }
131}
132
133// Helper function to convert std::string to zlib_component_string_t
134static void strToComponentString(const std::string &Str,

Calls 4

canonical_abi_reallocFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected