1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:17:45 +00:00

AK: Rename Stream::read_entire_buffer to Stream::read_until_filled

No functional changes.
This commit is contained in:
Tim Schumacher 2023-03-01 15:27:35 +01:00 committed by Linus Groh
parent d5871f5717
commit a3f73e7d85
31 changed files with 58 additions and 58 deletions

View file

@ -81,7 +81,7 @@ inline ErrorOr<void> TarInputStream::for_each_extended_header(F func)
auto header_size = TRY(header().size());
ByteBuffer file_contents_buffer = TRY(ByteBuffer::create_zeroed(header_size));
TRY(file_stream.read_entire_buffer(file_contents_buffer));
TRY(file_stream.read_until_filled(file_contents_buffer));
StringView file_contents { file_contents_buffer };

View file

@ -232,7 +232,7 @@ ErrorOr<MP3::MP3Frame, LoaderError> MP3LoaderPlugin::read_frame_data(MP3::Header
auto& buffer = maybe_buffer.value();
size_t old_reservoir_size = m_bit_reservoir.used_buffer_size();
LOADER_TRY(m_bitstream->read_entire_buffer(buffer));
LOADER_TRY(m_bitstream->read_until_filled(buffer));
// FIXME: This should write the entire span.
if (LOADER_TRY(m_bit_reservoir.write_some(buffer)) != header.slot_count)
return LoaderError { LoaderError::Category::IO, m_loaded_samples, "Could not write frame into bit reservoir." };

View file

@ -93,7 +93,7 @@ template<typename T>
static ErrorOr<double> read_sample(Stream& stream)
{
T sample { 0 };
TRY(stream.read_entire_buffer(Bytes { &sample, sizeof(T) }));
TRY(stream.read_until_filled(Bytes { &sample, sizeof(T) }));
// Remap integer samples to normalized floating-point range of -1 to 1.
if constexpr (IsIntegral<T>) {
if constexpr (NumericLimits<T>::is_signed()) {
@ -157,7 +157,7 @@ ErrorOr<Vector<FixedArray<Sample>>, LoaderError> WavLoaderPlugin::load_chunks(si
pcm_bits_per_sample(m_sample_format), sample_format_name(m_sample_format));
auto sample_data = LOADER_TRY(ByteBuffer::create_zeroed(bytes_to_read));
LOADER_TRY(m_stream->read_entire_buffer(sample_data.bytes()));
LOADER_TRY(m_stream->read_until_filled(sample_data.bytes()));
// m_loaded_samples should contain the amount of actually loaded samples
m_loaded_samples += samples_to_read;

View file

@ -329,7 +329,7 @@ ErrorOr<ByteBuffer> DeflateDecompressor::decompress_all(ReadonlyBytes bytes)
}
auto output_buffer = TRY(ByteBuffer::create_uninitialized(output_stream.used_buffer_size()));
TRY(output_stream.read_entire_buffer(output_buffer));
TRY(output_stream.read_until_filled(output_buffer));
return output_buffer;
}
@ -1027,7 +1027,7 @@ ErrorOr<ByteBuffer> DeflateCompressor::compress_all(ReadonlyBytes bytes, Compres
TRY(deflate_stream->final_flush());
auto buffer = TRY(ByteBuffer::create_uninitialized(output_stream->used_buffer_size()));
TRY(output_stream->read_entire_buffer(buffer));
TRY(output_stream->read_until_filled(buffer));
return buffer;
}

View file

@ -179,7 +179,7 @@ ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
}
auto output_buffer = TRY(ByteBuffer::create_uninitialized(output_stream.used_buffer_size()));
TRY(output_stream.read_entire_buffer(output_buffer));
TRY(output_stream.read_until_filled(output_buffer));
return output_buffer;
}
@ -245,7 +245,7 @@ ErrorOr<ByteBuffer> GzipCompressor::compress_all(ReadonlyBytes bytes)
TRY(gzip_stream.write_entire_buffer(bytes));
auto buffer = TRY(ByteBuffer::create_uninitialized(output_stream->used_buffer_size()));
TRY(output_stream->read_entire_buffer(buffer.bytes()));
TRY(output_stream->read_until_filled(buffer.bytes()));
return buffer;
}

View file

@ -173,7 +173,7 @@ ErrorOr<ByteBuffer> ZlibCompressor::compress_all(ReadonlyBytes bytes, ZlibCompre
TRY(zlib_stream->finish());
auto buffer = TRY(ByteBuffer::create_uninitialized(output_stream->used_buffer_size()));
TRY(output_stream->read_entire_buffer(buffer.bytes()));
TRY(output_stream->read_until_filled(buffer.bytes()));
return buffer;
}

View file

@ -171,7 +171,7 @@ ErrorOr<Reply> send_connect_request_message(Core::Socket& socket, Core::SOCKSPro
return Error::from_string_literal("SOCKS negotiation failed: Failed to send connect request trailer");
auto buffer = TRY(ByteBuffer::create_uninitialized(stream.used_buffer_size()));
TRY(stream.read_entire_buffer(buffer.bytes()));
TRY(stream.read_until_filled(buffer.bytes()));
// FIXME: This should write the entire span.
size = TRY(socket.write_some({ buffer.data(), buffer.size() }));
@ -263,7 +263,7 @@ ErrorOr<u8> send_username_password_authentication_message(Core::Socket& socket,
return Error::from_string_literal("SOCKS negotiation failed: Failed to send username/password authentication message");
auto buffer = TRY(ByteBuffer::create_uninitialized(stream.used_buffer_size()));
TRY(stream.read_entire_buffer(buffer.bytes()));
TRY(stream.read_until_filled(buffer.bytes()));
// FIXME: This should write the entire span.
size = TRY(socket.write_some(buffer));

View file

@ -72,7 +72,7 @@ ErrorOr<ByteBuffer> Packet::to_byte_buffer() const
}
auto buffer = TRY(ByteBuffer::create_uninitialized(stream.used_buffer_size()));
TRY(stream.read_entire_buffer(buffer));
TRY(stream.read_until_filled(buffer));
return buffer;
}

View file

@ -58,11 +58,11 @@ struct [[gnu::packed]] CompilationUnitHeader {
static ErrorOr<CompilationUnitHeader> read_from_stream(Stream& stream)
{
CompilationUnitHeader header;
TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) }));
TRY(stream.read_until_filled(Bytes { &header.common, sizeof(header.common) }));
if (header.common.version <= 4)
TRY(stream.read_entire_buffer(Bytes { &header.v4, sizeof(header.v4) }));
TRY(stream.read_until_filled(Bytes { &header.v4, sizeof(header.v4) }));
else
TRY(stream.read_entire_buffer(Bytes { &header.v5, sizeof(header.v5) }));
TRY(stream.read_until_filled(Bytes { &header.v5, sizeof(header.v5) }));
return header;
}
};

View file

@ -68,12 +68,12 @@ struct [[gnu::packed]] LineProgramUnitHeader32 {
static ErrorOr<LineProgramUnitHeader32> read_from_stream(Stream& stream)
{
LineProgramUnitHeader32 header;
TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) }));
TRY(stream.read_until_filled(Bytes { &header.common, sizeof(header.common) }));
if (header.common.version <= 4)
TRY(stream.read_entire_buffer(Bytes { &header.v4, sizeof(header.v4) }));
TRY(stream.read_until_filled(Bytes { &header.v4, sizeof(header.v4) }));
else
TRY(stream.read_entire_buffer(Bytes { &header.v5, sizeof(header.v5) }));
TRY(stream.read_entire_buffer(Bytes { &header.std_opcode_lengths, min(sizeof(header.std_opcode_lengths), (header.opcode_base() - 1) * sizeof(header.std_opcode_lengths[0])) }));
TRY(stream.read_until_filled(Bytes { &header.v5, sizeof(header.v5) }));
TRY(stream.read_until_filled(Bytes { &header.std_opcode_lengths, min(sizeof(header.std_opcode_lengths), (header.opcode_base() - 1) * sizeof(header.std_opcode_lengths[0])) }));
return header;
}
};

View file

@ -94,7 +94,7 @@ static ErrorOr<GIFFormat> decode_gif_header(Stream& stream)
static auto valid_header_89 = "GIF89a"sv;
Array<u8, 6> header;
TRY(stream.read_entire_buffer(header));
TRY(stream.read_until_filled(header));
if (header.span() == valid_header_87.bytes())
return GIFFormat::GIF87a;
@ -424,7 +424,7 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
break;
TRY(sub_block.try_resize(sub_block.size() + sub_block_length));
TRY(stream.read_entire_buffer(sub_block.span().slice_from_end(sub_block_length)));
TRY(stream.read_until_filled(sub_block.span().slice_from_end(sub_block_length)));
}
if (extension_type == 0xF9) {
@ -501,7 +501,7 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
break;
Array<u8, 256> buffer;
TRY(stream.read_entire_buffer(buffer.span().trim(lzw_encoded_bytes_expected)));
TRY(stream.read_until_filled(buffer.span().trim(lzw_encoded_bytes_expected)));
for (int i = 0; i < lzw_encoded_bytes_expected; ++i) {
image->lzw_encoded_bytes.append(buffer[i]);

View file

@ -769,7 +769,7 @@ static ErrorOr<void> read_icc_profile(SeekableStream& stream, JPEGLoadingContext
return Error::from_string_literal("Duplicate ICC chunk at sequence number");
chunk_state->chunks[index] = TRY(ByteBuffer::create_zeroed(bytes_to_read));
TRY(stream.read_entire_buffer(chunk_state->chunks[index]));
TRY(stream.read_until_filled(chunk_state->chunks[index]));
chunk_state->seen_number_of_icc_chunks++;

View file

@ -35,7 +35,7 @@ static ErrorOr<Color> decode_qoi_op_rgb(Stream& stream, u8 first_byte, Color pix
{
VERIFY(first_byte == QOI_OP_RGB);
u8 bytes[3];
TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) }));
TRY(stream.read_until_filled({ &bytes, array_size(bytes) }));
// The alpha value remains unchanged from the previous pixel.
return Color { bytes[0], bytes[1], bytes[2], pixel.alpha() };
@ -45,7 +45,7 @@ static ErrorOr<Color> decode_qoi_op_rgba(Stream& stream, u8 first_byte)
{
VERIFY(first_byte == QOI_OP_RGBA);
u8 bytes[4];
TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) }));
TRY(stream.read_until_filled({ &bytes, array_size(bytes) }));
return Color { bytes[0], bytes[1], bytes[2], bytes[3] };
}
@ -110,7 +110,7 @@ static ErrorOr<u8> decode_qoi_op_run(Stream&, u8 first_byte)
static ErrorOr<void> decode_qoi_end_marker(Stream& stream)
{
u8 bytes[array_size(END_MARKER)];
TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) }));
TRY(stream.read_until_filled({ &bytes, array_size(bytes) }));
if (!stream.is_eof())
return Error::from_string_literal("Invalid QOI image: expected end of stream but more bytes are available");
if (memcmp(&END_MARKER, &bytes, array_size(bytes)) != 0)

View file

@ -52,7 +52,7 @@ public:
ErrorOr<void> decode_into(Bytes bytes)
{
TRY(m_stream.read_entire_buffer(bytes));
TRY(m_stream.read_until_filled(bytes));
return {};
}

View file

@ -1346,7 +1346,7 @@ ErrorOr<void> Editor::refresh_display()
return;
auto buffer = ByteBuffer::create_uninitialized(output_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
output_stream.read_entire_buffer(buffer).release_value_but_fixme_should_propagate_errors();
output_stream.read_until_filled(buffer).release_value_but_fixme_should_propagate_errors();
fwrite(buffer.data(), sizeof(char), buffer.size(), stderr);
}
};

View file

@ -90,7 +90,7 @@ void Request::set_should_buffer_all_input(bool value)
on_finish = [this](auto success, u32 total_size) {
auto output_buffer = ByteBuffer::create_uninitialized(m_internal_buffered_data->payload_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
m_internal_buffered_data->payload_stream.read_entire_buffer(output_buffer).release_value_but_fixme_should_propagate_errors();
m_internal_buffered_data->payload_stream.read_until_filled(output_buffer).release_value_but_fixme_should_propagate_errors();
on_buffered_request_finish(
success,
total_size,

View file

@ -210,7 +210,7 @@ struct ConvertToRaw<float> {
LittleEndian<u32> res;
ReadonlyBytes bytes { &value, sizeof(float) };
FixedMemoryStream stream { bytes };
stream.read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
stream.read_until_filled(res.bytes()).release_value_but_fixme_should_propagate_errors();
return static_cast<u32>(res);
}
};
@ -222,7 +222,7 @@ struct ConvertToRaw<double> {
LittleEndian<u64> res;
ReadonlyBytes bytes { &value, sizeof(double) };
FixedMemoryStream stream { bytes };
stream.read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
stream.read_until_filled(res.bytes()).release_value_but_fixme_should_propagate_errors();
return static_cast<u64>(res);
}
};
@ -260,7 +260,7 @@ T BytecodeInterpreter::read_value(ReadonlyBytes data)
{
LittleEndian<T> value;
FixedMemoryStream stream { data };
auto maybe_error = stream.read_entire_buffer(value.bytes());
auto maybe_error = stream.read_until_filled(value.bytes());
if (maybe_error.is_error()) {
dbgln("Read from {} failed", data.data());
m_trap = Trap { "Read from memory failed" };
@ -273,7 +273,7 @@ float BytecodeInterpreter::read_value<float>(ReadonlyBytes data)
{
LittleEndian<u32> raw_value;
FixedMemoryStream stream { data };
auto maybe_error = stream.read_entire_buffer(raw_value.bytes());
auto maybe_error = stream.read_until_filled(raw_value.bytes());
if (maybe_error.is_error())
m_trap = Trap { "Read from memory failed" };
return bit_cast<float>(static_cast<u32>(raw_value));
@ -284,7 +284,7 @@ double BytecodeInterpreter::read_value<double>(ReadonlyBytes data)
{
LittleEndian<u64> raw_value;
FixedMemoryStream stream { data };
auto maybe_error = stream.read_entire_buffer(raw_value.bytes());
auto maybe_error = stream.read_until_filled(raw_value.bytes());
if (maybe_error.is_error())
m_trap = Trap { "Read from memory failed" };
return bit_cast<double>(static_cast<u64>(raw_value));

View file

@ -89,7 +89,7 @@ void Configuration::dump_stack()
AllocatingMemoryStream memory_stream;
Printer { memory_stream }.print(vs...);
auto buffer = ByteBuffer::create_uninitialized(memory_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
memory_stream.read_entire_buffer(buffer).release_value_but_fixme_should_propagate_errors();
memory_stream.read_until_filled(buffer).release_value_but_fixme_should_propagate_errors();
dbgln(format.view(), StringView(buffer).trim_whitespace());
};
for (auto const& entry : stack().entries()) {

View file

@ -64,7 +64,7 @@ static auto parse_vector(Stream& stream)
if (count > Constants::max_allowed_vector_size)
return ParseResult<Vector<T>> { ParseError::HugeAllocationRequested };
entries.resize(count);
if (stream.read_entire_buffer({ entries.data(), entries.size() }).is_error())
if (stream.read_until_filled({ entries.data(), entries.size() }).is_error())
return ParseResult<Vector<T>> { with_eof_check(stream, ParseError::InvalidInput) };
break; // Note: We read this all in one go!
}
@ -486,7 +486,7 @@ ParseResult<Vector<Instruction>> Instruction::parse(Stream& stream, InstructionP
case Instructions::f32_const.value(): {
// op literal
LittleEndian<u32> value;
if (stream.read_entire_buffer(value.bytes()).is_error())
if (stream.read_until_filled(value.bytes()).is_error())
return with_eof_check(stream, ParseError::ExpectedFloatingImmediate);
auto floating = bit_cast<float>(static_cast<u32>(value));
@ -496,7 +496,7 @@ ParseResult<Vector<Instruction>> Instruction::parse(Stream& stream, InstructionP
case Instructions::f64_const.value(): {
// op literal
LittleEndian<u64> value;
if (stream.read_entire_buffer(value.bytes()).is_error())
if (stream.read_until_filled(value.bytes()).is_error())
return with_eof_check(stream, ParseError::ExpectedFloatingImmediate);
auto floating = bit_cast<double>(static_cast<u64>(value));
@ -1276,12 +1276,12 @@ ParseResult<Module> Module::parse(Stream& stream)
{
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Module"sv);
u8 buf[4];
if (stream.read_entire_buffer({ buf, 4 }).is_error())
if (stream.read_until_filled({ buf, 4 }).is_error())
return with_eof_check(stream, ParseError::InvalidInput);
if (Bytes { buf, 4 } != wasm_magic.span())
return with_eof_check(stream, ParseError::InvalidModuleMagic);
if (stream.read_entire_buffer({ buf, 4 }).is_error())
if (stream.read_until_filled({ buf, 4 }).is_error())
return with_eof_check(stream, ParseError::InvalidInput);
if (Bytes { buf, 4 } != wasm_version.span())
return with_eof_check(stream, ParseError::InvalidModuleVersion);