Write tensor into char buffer and be able to read into a tensor

Hello,
I am in a position where i need to write the contents of a torch::Tensor to a char buffer, then be able to reconstruct the torch::Tensor from a supplied buffer. How can i do this? Tensor data type is float

Would something like this help ?

torch::Tensor tensorToSave = torch::randn({ 2, 3 });
std::cout << "tensorToSave: " << tensorToSave << std::endl;

// option #1
{
	std::vector<char> data = torch::pickle_save(tensorToSave);

	torch::Tensor loadedTensor = torch::pickle_load(data).toTensor();

	std::cout << "loadedTensor: " << loadedTensor << std::endl;
}

// option #2
{
	std::string data;

	{
		std::ostringstream ostream;
		torch::save(tensorToSave, ostream);
		data = ostream.str();
	}

	torch::Tensor loadedTensor;

	{
		std::istringstream istream(data);
		torch::load(loadedTensor, istream);
	}

	std::cout << "loadedTensor: " << loadedTensor << std::endl;
}

Yep! i ended up doing something like option #2 but with a sstream, thanks!