buffer should be a unique_ptr<>