MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / CopyStringToBuffer

Function CopyStringToBuffer

tensorflow/lite/toco/tflite/types.cc:24–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace {
23
24DataBuffer::FlatBufferOffset CopyStringToBuffer(
25 const Array& array, flatbuffers::FlatBufferBuilder* builder) {
26 const auto& src_data = array.GetBuffer<ArrayDataType::kString>().data;
27 ::tflite::DynamicBuffer dyn_buffer;
28 for (const string& str : src_data) {
29 dyn_buffer.AddString(str.c_str(), str.length());
30 }
31 char* tensor_buffer;
32 int bytes = dyn_buffer.WriteToBuffer(&tensor_buffer);
33 std::vector<uint8_t> dst_data(bytes);
34 memcpy(dst_data.data(), tensor_buffer, bytes);
35 free(tensor_buffer);
36 return builder->CreateVector(dst_data.data(), bytes);
37}
38
39// vector<bool> may be implemented using a bit-set, so we can't just
40// reinterpret_cast, accessing its data as vector<bool> and let flatbuffer

Callers 1

SerializeMethod · 0.85

Calls 6

AddStringMethod · 0.80
c_strMethod · 0.80
CreateVectorMethod · 0.80
lengthMethod · 0.45
WriteToBufferMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected