1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:07:46 +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(); parse_endpoint();
out() << "#pragma once"; out() << "#pragma once";
out() << "#include <AK/BufferStream.h>"; out() << "#include <AK/MemoryStream.h>";
out() << "#include <AK/OwnPtr.h>"; out() << "#include <AK/OwnPtr.h>";
out() << "#include <AK/URL.h>"; out() << "#include <AK/URL.h>";
out() << "#include <AK/Utf8View.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() << " virtual i32 message_id() const override { return (int)MessageID::" << name << "; }";
out() << " static i32 static_message_id() { 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() << " 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() << " {";
out() << " IPC::Decoder decoder(stream);"; 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() << " virtual String name() const override { return \"" << endpoint.name << "\"; };";
out() << " static OwnPtr<IPC::Message> decode_message(const ByteBuffer& buffer, size_t& size_in_bytes)"; out() << " static OwnPtr<IPC::Message> decode_message(const ByteBuffer& buffer, size_t& size_in_bytes)";
out() << " {"; out() << " {";
out() << " BufferStream stream(const_cast<ByteBuffer&>(buffer));"; out() << " InputMemoryStream stream { buffer };";
out() << " i32 message_endpoint_magic = 0;"; out() << " i32 message_endpoint_magic = 0;";
out() << " stream >> message_endpoint_magic;"; out() << " stream >> message_endpoint_magic;";
out() << " if (stream.handle_read_failure()) {"; out() << " if (stream.handle_any_error()) {";
#ifdef GENERATE_DEBUG_CODE #ifdef GENERATE_DEBUG_CODE
out() << " dbg() << \"Failed to read message endpoint magic\";"; out() << " dbg() << \"Failed to read message endpoint magic\";";
#endif #endif
@ -366,7 +366,7 @@ int main(int argc, char** argv)
out() << " }"; out() << " }";
out() << " i32 message_id = 0;"; out() << " i32 message_id = 0;";
out() << " stream >> message_id;"; out() << " stream >> message_id;";
out() << " if (stream.handle_read_failure()) {"; out() << " if (stream.handle_any_error()) {";
#ifdef GENERATE_DEBUG_CODE #ifdef GENERATE_DEBUG_CODE
out() << " dbg() << \"Failed to read message ID\";"; out() << " dbg() << \"Failed to read message ID\";";
#endif #endif
@ -391,7 +391,7 @@ int main(int argc, char** argv)
out() << " return nullptr;"; out() << " return nullptr;";
out() << " }"; out() << " }";
out() << " if (stream.handle_read_failure()) {"; out() << " if (stream.handle_any_error()) {";
#ifdef GENERATE_DEBUG_CODE #ifdef GENERATE_DEBUG_CODE
out() << " dbg() << \"Failed to read the message\";"; out() << " dbg() << \"Failed to read the message\";";
#endif #endif

View file

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

View file

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

View file

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