LibAudio: Use ReadonlyBytes instead of Bytes for buffer parameters

Bytes will implicitly cast to StringView, but not to ReadonlyBytes. That
means that if you call
`Audio::Loader::create_plugin(mapped_file->bytes())`
it will silently use the `create_plugin(StringView path)` overload.

Reading audio data does not require that data to be writable, so let's
use ReadonlyBytes for it and avoid the footgun.
This commit is contained in:
Sam Atkins 2023-06-27 12:04:29 +01:00 committed by Sam Atkins
commit 0a9fa85e86
Notes: sideshowbarker 2024-07-17 02:29:45 +09:00
4 changed files with 5 additions and 4 deletions

View file

@ -86,7 +86,7 @@ protected:
class Loader : public RefCounted<Loader> {
public:
static ErrorOr<NonnullRefPtr<Loader>, LoaderError> create(StringView path);
static ErrorOr<NonnullRefPtr<Loader>, LoaderError> create(Bytes buffer);
static ErrorOr<NonnullRefPtr<Loader>, LoaderError> create(ReadonlyBytes buffer);
// Will only read less samples if we're at the end of the stream.
LoaderSamples get_more_samples(size_t samples_to_read_from_input = 128 * KiB);