1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

LibIPC: Use InputMemoryStream instead of BufferStream.

This commit is contained in:
asynts 2020-09-20 13:00:54 +02:00 committed by Andreas Kling
parent 7d1b22bbb1
commit c879ecf509
4 changed files with 24 additions and 27 deletions

View file

@ -200,7 +200,7 @@ int main(int argc, char** argv)
parse_endpoint();
out() << "#pragma once";
out() << "#include <AK/BufferStream.h>";
out() << "#include <AK/MemoryStream.h>";
out() << "#include <AK/OwnPtr.h>";
out() << "#include <AK/URL.h>";
out() << "#include <AK/Utf8View.h>";
@ -278,7 +278,7 @@ int main(int argc, char** argv)
out() << " virtual i32 message_id() const override { return (int)MessageID::" << name << "; }";
out() << " static i32 static_message_id() { return (int)MessageID::" << name << "; }";
out() << " virtual const char* message_name() const override { return \"" << endpoint.name << "::" << name << "\"; }";
out() << " static OwnPtr<" << name << "> decode(BufferStream& stream, size_t& size_in_bytes)";
out() << " static OwnPtr<" << name << "> decode(InputMemoryStream& stream, size_t& size_in_bytes)";
out() << " {";
out() << " IPC::Decoder decoder(stream);";
@ -349,10 +349,10 @@ int main(int argc, char** argv)
out() << " virtual String name() const override { return \"" << endpoint.name << "\"; };";
out() << " static OwnPtr<IPC::Message> decode_message(const ByteBuffer& buffer, size_t& size_in_bytes)";
out() << " {";
out() << " BufferStream stream(const_cast<ByteBuffer&>(buffer));";
out() << " InputMemoryStream stream { buffer };";
out() << " i32 message_endpoint_magic = 0;";
out() << " stream >> message_endpoint_magic;";
out() << " if (stream.handle_read_failure()) {";
out() << " if (stream.handle_any_error()) {";
#ifdef GENERATE_DEBUG_CODE
out() << " dbg() << \"Failed to read message endpoint magic\";";
#endif
@ -366,7 +366,7 @@ int main(int argc, char** argv)
out() << " }";
out() << " i32 message_id = 0;";
out() << " stream >> message_id;";
out() << " if (stream.handle_read_failure()) {";
out() << " if (stream.handle_any_error()) {";
#ifdef GENERATE_DEBUG_CODE
out() << " dbg() << \"Failed to read message ID\";";
#endif
@ -391,7 +391,7 @@ int main(int argc, char** argv)
out() << " return nullptr;";
out() << " }";
out() << " if (stream.handle_read_failure()) {";
out() << " if (stream.handle_any_error()) {";
#ifdef GENERATE_DEBUG_CODE
out() << " dbg() << \"Failed to read the message\";";
#endif

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/BufferStream.h>
#include <AK/MemoryStream.h>
#include <AK/URL.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Dictionary.h>
@ -34,68 +34,68 @@ namespace IPC {
bool Decoder::decode(bool& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(u8& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(u16& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(u32& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(u64& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(i8& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(i16& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(i32& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(i64& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(float& value)
{
m_stream >> value;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(String& value)
{
i32 length = 0;
m_stream >> length;
if (m_stream.handle_read_failure())
if (m_stream.handle_any_error())
return false;
if (length < 0) {
value = {};
@ -107,11 +107,9 @@ bool Decoder::decode(String& value)
}
char* text_buffer = nullptr;
auto text_impl = StringImpl::create_uninitialized(static_cast<size_t>(length), text_buffer);
for (size_t i = 0; i < static_cast<size_t>(length); ++i) {
m_stream >> text_buffer[i];
}
m_stream >> Bytes { text_buffer, static_cast<size_t>(length) };
value = *text_impl;
return !m_stream.handle_read_failure();
return !m_stream.handle_any_error();
}
bool Decoder::decode(URL& value)
@ -127,7 +125,7 @@ bool Decoder::decode(Dictionary& dictionary)
{
u64 size = 0;
m_stream >> size;
if (m_stream.handle_read_failure())
if (m_stream.handle_any_error())
return false;
if (size >= NumericLimits<i32>::max()) {
ASSERT_NOT_REACHED();

View file

@ -43,7 +43,7 @@ inline bool decode(Decoder&, T&)
class Decoder {
public:
explicit Decoder(BufferStream& stream)
explicit Decoder(InputMemoryStream& stream)
: m_stream(stream)
{
}
@ -101,7 +101,7 @@ public:
}
private:
BufferStream& m_stream;
InputMemoryStream& m_stream;
};
}

View file

@ -32,10 +32,9 @@
namespace IPC {
template<typename T>
bool encode(BufferStream&, T&)
bool encode(Encoder&, T&)
{
ASSERT_NOT_REACHED();
return false;
}
class Encoder {