From 0e6aa532a100337864dde15ffcf21ad34a377d44 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Thu, 11 Jan 2024 19:51:18 -0800 Subject: [PATCH] [Yunq] Move MessageView higher in call stack. --- lib/yunq/message_view.cpp | 24 +++- lib/yunq/message_view.h | 24 +++- lib/yunq/serialize.cpp | 11 -- lib/yunq/serialize.h | 3 - sys/denali/lib/denali/denali.yunq.cpp | 52 ++++----- sys/denali/lib/denali/denali.yunq.h | 7 +- .../lib/victoriafalls/victoriafalls.yunq.cpp | 58 +++++----- .../lib/victoriafalls/victoriafalls.yunq.h | 9 +- .../lib/voyageurs/voyageurs.yunq.cpp | 12 +- sys/voyageurs/lib/voyageurs/voyageurs.yunq.h | 3 +- .../lib/yellowstone/yellowstone.yunq.cpp | 106 +++++++++--------- .../lib/yellowstone/yellowstone.yunq.h | 13 ++- yunq/message.cpp.jinja | 16 +-- yunq/message.h.jinja | 3 +- 14 files changed, 181 insertions(+), 160 deletions(-) diff --git a/lib/yunq/message_view.cpp b/lib/yunq/message_view.cpp index 071e756..9cf2881 100644 --- a/lib/yunq/message_view.cpp +++ b/lib/yunq/message_view.cpp @@ -2,14 +2,32 @@ namespace yunq { +namespace { + +const uint64_t kIdentByte = 0x33441122; + +} // namespace + +glcr::Status MessageView::CheckHeader() const { + if (buffer_.At(offset_ + 0) != kIdentByte) { + return glcr::InvalidArgument("Trying to parse an invalid yunq message."); + } + // TODO: Parse core size. + // TODO: Parse extension size. + // TODO: Check CRC32 + // TODO: Parse options. + return glcr::Status::Ok(); +} + template <> -glcr::ErrorOr MessageView::ReadField(uint64_t field_index) { +glcr::ErrorOr MessageView::ReadField( + uint64_t field_index) const { return buffer_.At(field_offset(field_index)); } template <> glcr::ErrorOr MessageView::ReadField( - uint64_t field_index) { + uint64_t field_index) const { ExtensionPointer ptr = buffer_.At(field_offset(field_index)); @@ -18,7 +36,7 @@ glcr::ErrorOr MessageView::ReadField( template <> glcr::ErrorOr> MessageView::ReadRepeated( - uint64_t field_index) { + uint64_t field_index) const { ExtensionPointer pointer = buffer_.At(field_offset(field_index)); diff --git a/lib/yunq/message_view.h b/lib/yunq/message_view.h index 24bdcc8..ee5aea1 100644 --- a/lib/yunq/message_view.h +++ b/lib/yunq/message_view.h @@ -3,11 +3,20 @@ #include #include #include +#include namespace yunq { const uint64_t kHeaderSize = 24; // 4x uint32, 1x uint64 +struct MessageHeader { + uint32_t ident; + uint32_t core_length; + uint32_t length; + uint32_t crc32; + uint64_t options; +} __attribute__((packed)); + struct ExtensionPointer { uint32_t offset; uint32_t length; @@ -18,31 +27,34 @@ class MessageView { MessageView(const glcr::ByteBuffer& buffer, uint64_t offset) : buffer_(buffer), offset_(offset) {} + [[nodiscard]] glcr::Status CheckHeader() const; + // TODO: Implement glcr::StatusOr template - glcr::ErrorOr ReadField(uint64_t field_index); + glcr::ErrorOr ReadField(uint64_t field_index) const; template - glcr::ErrorOr> ReadRepeated(uint64_t field_index); + glcr::ErrorOr> ReadRepeated(uint64_t field_index) const; private: const glcr::ByteBuffer& buffer_; uint64_t offset_; - uint64_t field_offset(uint64_t field_index) { + uint64_t field_offset(uint64_t field_index) const { return offset_ + kHeaderSize + (8 * field_index); } }; template <> -glcr::ErrorOr MessageView::ReadField(uint64_t field_index); +glcr::ErrorOr MessageView::ReadField( + uint64_t field_index) const; template <> glcr::ErrorOr MessageView::ReadField( - uint64_t field_index); + uint64_t field_index) const; template <> glcr::ErrorOr> MessageView::ReadRepeated( - uint64_t field_index); + uint64_t field_index) const; } // namespace yunq diff --git a/lib/yunq/serialize.cpp b/lib/yunq/serialize.cpp index afaad06..749063b 100644 --- a/lib/yunq/serialize.cpp +++ b/lib/yunq/serialize.cpp @@ -7,17 +7,6 @@ const uint64_t kIdentByte = 0x33441122; } // namespace -glcr::Status CheckHeader(const glcr::ByteBuffer& buffer, uint64_t offset) { - if (buffer.At(offset + 0) != kIdentByte) { - return glcr::InvalidArgument("Trying to parse an invalid yunq message."); - } - // TODO: Parse core size. - // TODO: Parse extension size. - // TODO: Check CRC32 - // TODO: Parse options. - return glcr::Status::Ok(); -} - void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) { bytes.WriteAt(offset + 0, kIdentByte); diff --git a/lib/yunq/serialize.h b/lib/yunq/serialize.h index 2e90779..cdb76c1 100644 --- a/lib/yunq/serialize.h +++ b/lib/yunq/serialize.h @@ -5,9 +5,6 @@ namespace yunq { -[[nodiscard]] glcr::Status CheckHeader(const glcr::ByteBuffer& buffer, - uint64_t offset); - void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size); diff --git a/sys/denali/lib/denali/denali.yunq.cpp b/sys/denali/lib/denali/denali.yunq.cpp index 66db996..b142571 100644 --- a/sys/denali/lib/denali/denali.yunq.cpp +++ b/sys/denali/lib/denali/denali.yunq.cpp @@ -16,25 +16,25 @@ struct ExtPointer { } // namespace glcr::Status ReadRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } glcr::Status ReadRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } -glcr::Status ReadRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status ReadRequest::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse device_id. - ASSIGN_OR_RETURN(device_id_, view.ReadField(0)); + ASSIGN_OR_RETURN(device_id_, message.ReadField(0)); // Parse lba. - ASSIGN_OR_RETURN(lba_, view.ReadField(1)); + ASSIGN_OR_RETURN(lba_, message.ReadField(1)); // Parse size. - ASSIGN_OR_RETURN(size_, view.ReadField(2)); + ASSIGN_OR_RETURN(size_, message.ReadField(2)); return glcr::Status::Ok(); } @@ -72,26 +72,26 @@ uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, return next_extension; } glcr::Status ReadManyRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } glcr::Status ReadManyRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } -glcr::Status ReadManyRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status ReadManyRequest::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse device_id. - ASSIGN_OR_RETURN(device_id_, view.ReadField(0)); + ASSIGN_OR_RETURN(device_id_, message.ReadField(0)); // Parse lba. - ASSIGN_OR_RETURN(lba_, view.ReadRepeated(1)); + ASSIGN_OR_RETURN(lba_, message.ReadRepeated(1)); // Parse sector_cnt. - ASSIGN_OR_RETURN(sector_cnt_, view.ReadRepeated(2)); + ASSIGN_OR_RETURN(sector_cnt_, message.ReadRepeated(2)); return glcr::Status::Ok(); @@ -174,7 +174,8 @@ uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off return next_extension; } glcr::Status ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse memory. // FIXME: Implement in-buffer capabilities for inprocess serialization. set_memory(0); @@ -182,7 +183,8 @@ glcr::Status ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_ } glcr::Status ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse memory. uint64_t memory_ptr = bytes.At(offset + header_size + (8 * 2)); @@ -190,14 +192,12 @@ glcr::Status ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_ return glcr::Status::Ok(); } -glcr::Status ReadResponse::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status ReadResponse::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse device_id. - ASSIGN_OR_RETURN(device_id_, view.ReadField(0)); + ASSIGN_OR_RETURN(device_id_, message.ReadField(0)); // Parse size. - ASSIGN_OR_RETURN(size_, view.ReadField(1)); + ASSIGN_OR_RETURN(size_, message.ReadField(1)); // Parse memory. return glcr::Status::Ok(); diff --git a/sys/denali/lib/denali/denali.yunq.h b/sys/denali/lib/denali/denali.yunq.h index 414c807..3e5973f 100644 --- a/sys/denali/lib/denali/denali.yunq.h +++ b/sys/denali/lib/denali/denali.yunq.h @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -33,7 +34,7 @@ class ReadRequest { uint64_t size_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class ReadManyRequest { public: @@ -59,7 +60,7 @@ class ReadManyRequest { glcr::Vector sector_cnt_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class ReadResponse { public: @@ -85,6 +86,6 @@ class ReadResponse { z_cap_t memory_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; diff --git a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.cpp b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.cpp index 46f8899..e0b91cb 100644 --- a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.cpp +++ b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.cpp @@ -16,21 +16,21 @@ struct ExtPointer { } // namespace glcr::Status OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } glcr::Status OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } -glcr::Status OpenFileRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status OpenFileRequest::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse path. - ASSIGN_OR_RETURN(path_, view.ReadField(0)); + ASSIGN_OR_RETURN(path_, message.ReadField(0)); return glcr::Status::Ok(); } @@ -78,7 +78,8 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off return next_extension; } glcr::Status OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse memory. // FIXME: Implement in-buffer capabilities for inprocess serialization. set_memory(0); @@ -86,7 +87,8 @@ glcr::Status OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uin } glcr::Status OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse memory. uint64_t memory_ptr = bytes.At(offset + header_size + (8 * 2)); @@ -94,14 +96,12 @@ glcr::Status OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uin return glcr::Status::Ok(); } -glcr::Status OpenFileResponse::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status OpenFileResponse::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse path. - ASSIGN_OR_RETURN(path_, view.ReadField(0)); + ASSIGN_OR_RETURN(path_, message.ReadField(0)); // Parse size. - ASSIGN_OR_RETURN(size_, view.ReadField(1)); + ASSIGN_OR_RETURN(size_, message.ReadField(1)); // Parse memory. return glcr::Status::Ok(); @@ -160,21 +160,21 @@ uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of return next_extension; } glcr::Status GetDirectoryRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } glcr::Status GetDirectoryRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } -glcr::Status GetDirectoryRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status GetDirectoryRequest::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse path. - ASSIGN_OR_RETURN(path_, view.ReadField(0)); + ASSIGN_OR_RETURN(path_, message.ReadField(0)); return glcr::Status::Ok(); } @@ -222,21 +222,21 @@ uint64_t GetDirectoryRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t return next_extension; } glcr::Status Directory::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } glcr::Status Directory::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } -glcr::Status Directory::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status Directory::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse filenames. - ASSIGN_OR_RETURN(filenames_, view.ReadField(0)); + ASSIGN_OR_RETURN(filenames_, message.ReadField(0)); return glcr::Status::Ok(); } diff --git a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.h b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.h index 7549408..0b54d3b 100644 --- a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.h +++ b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.h @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -27,7 +28,7 @@ class OpenFileRequest { glcr::String path_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class OpenFileResponse { public: @@ -53,7 +54,7 @@ class OpenFileResponse { z_cap_t memory_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class GetDirectoryRequest { public: @@ -73,7 +74,7 @@ class GetDirectoryRequest { glcr::String path_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class Directory { public: @@ -93,6 +94,6 @@ class Directory { glcr::String filenames_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp index 563b0f6..576c32d 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp @@ -16,7 +16,8 @@ struct ExtPointer { } // namespace glcr::Status KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse port_capability. // FIXME: Implement in-buffer capabilities for inprocess serialization. set_port_capability(0); @@ -24,7 +25,8 @@ glcr::Status KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uin } glcr::Status KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse port_capability. uint64_t port_capability_ptr = bytes.At(offset + header_size + (8 * 0)); @@ -32,10 +34,8 @@ glcr::Status KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uin return glcr::Status::Ok(); } -glcr::Status KeyboardListener::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status KeyboardListener::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse port_capability. return glcr::Status::Ok(); diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.h b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.h index da5c585..7abc356 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.h +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.h @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -27,6 +28,6 @@ class KeyboardListener { z_cap_t port_capability_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp index 3a5dc65..54d707f 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp @@ -18,7 +18,8 @@ struct ExtPointer { } // namespace glcr::Status RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse endpoint_capability. // FIXME: Implement in-buffer capabilities for inprocess serialization. set_endpoint_capability(0); @@ -26,7 +27,8 @@ glcr::Status RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& byt } glcr::Status RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse endpoint_capability. uint64_t endpoint_capability_ptr = bytes.At(offset + header_size + (8 * 1)); @@ -34,12 +36,10 @@ glcr::Status RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& byt return glcr::Status::Ok(); } -glcr::Status RegisterEndpointRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status RegisterEndpointRequest::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse endpoint_name. - ASSIGN_OR_RETURN(endpoint_name_, view.ReadField(0)); + ASSIGN_OR_RETURN(endpoint_name_, message.ReadField(0)); // Parse endpoint_capability. return glcr::Status::Ok(); @@ -94,21 +94,21 @@ uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint return next_extension; } glcr::Status GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } glcr::Status GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } -glcr::Status GetEndpointRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status GetEndpointRequest::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse endpoint_name. - ASSIGN_OR_RETURN(endpoint_name_, view.ReadField(0)); + ASSIGN_OR_RETURN(endpoint_name_, message.ReadField(0)); return glcr::Status::Ok(); } @@ -156,7 +156,8 @@ uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t return next_extension; } glcr::Status Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse endpoint. // FIXME: Implement in-buffer capabilities for inprocess serialization. set_endpoint(0); @@ -164,7 +165,8 @@ glcr::Status Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of } glcr::Status Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse endpoint. uint64_t endpoint_ptr = bytes.At(offset + header_size + (8 * 0)); @@ -172,10 +174,8 @@ glcr::Status Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of return glcr::Status::Ok(); } -glcr::Status Endpoint::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status Endpoint::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse endpoint. return glcr::Status::Ok(); @@ -208,7 +208,8 @@ uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, gl return next_extension; } glcr::Status AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse ahci_region. // FIXME: Implement in-buffer capabilities for inprocess serialization. set_ahci_region(0); @@ -216,7 +217,8 @@ glcr::Status AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of } glcr::Status AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse ahci_region. uint64_t ahci_region_ptr = bytes.At(offset + header_size + (8 * 0)); @@ -224,13 +226,11 @@ glcr::Status AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of return glcr::Status::Ok(); } -glcr::Status AhciInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status AhciInfo::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse ahci_region. // Parse region_length. - ASSIGN_OR_RETURN(region_length_, view.ReadField(1)); + ASSIGN_OR_RETURN(region_length_, message.ReadField(1)); return glcr::Status::Ok(); } @@ -266,43 +266,43 @@ uint64_t AhciInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, gl return next_extension; } glcr::Status FramebufferInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } glcr::Status FramebufferInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); return glcr::Status::Ok(); } -glcr::Status FramebufferInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status FramebufferInfo::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse address_phys. - ASSIGN_OR_RETURN(address_phys_, view.ReadField(0)); + ASSIGN_OR_RETURN(address_phys_, message.ReadField(0)); // Parse width. - ASSIGN_OR_RETURN(width_, view.ReadField(1)); + ASSIGN_OR_RETURN(width_, message.ReadField(1)); // Parse height. - ASSIGN_OR_RETURN(height_, view.ReadField(2)); + ASSIGN_OR_RETURN(height_, message.ReadField(2)); // Parse pitch. - ASSIGN_OR_RETURN(pitch_, view.ReadField(3)); + ASSIGN_OR_RETURN(pitch_, message.ReadField(3)); // Parse bpp. - ASSIGN_OR_RETURN(bpp_, view.ReadField(4)); + ASSIGN_OR_RETURN(bpp_, message.ReadField(4)); // Parse memory_model. - ASSIGN_OR_RETURN(memory_model_, view.ReadField(5)); + ASSIGN_OR_RETURN(memory_model_, message.ReadField(5)); // Parse red_mask_size. - ASSIGN_OR_RETURN(red_mask_size_, view.ReadField(6)); + ASSIGN_OR_RETURN(red_mask_size_, message.ReadField(6)); // Parse red_mask_shift. - ASSIGN_OR_RETURN(red_mask_shift_, view.ReadField(7)); + ASSIGN_OR_RETURN(red_mask_shift_, message.ReadField(7)); // Parse green_mask_size. - ASSIGN_OR_RETURN(green_mask_size_, view.ReadField(8)); + ASSIGN_OR_RETURN(green_mask_size_, message.ReadField(8)); // Parse green_mask_shift. - ASSIGN_OR_RETURN(green_mask_shift_, view.ReadField(9)); + ASSIGN_OR_RETURN(green_mask_shift_, message.ReadField(9)); // Parse blue_mask_size. - ASSIGN_OR_RETURN(blue_mask_size_, view.ReadField(10)); + ASSIGN_OR_RETURN(blue_mask_size_, message.ReadField(10)); // Parse blue_mask_shift. - ASSIGN_OR_RETURN(blue_mask_shift_, view.ReadField(11)); + ASSIGN_OR_RETURN(blue_mask_shift_, message.ReadField(11)); return glcr::Status::Ok(); } @@ -376,7 +376,8 @@ uint64_t FramebufferInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off return next_extension; } glcr::Status DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse denali_endpoint. // FIXME: Implement in-buffer capabilities for inprocess serialization. set_denali_endpoint(0); @@ -384,7 +385,8 @@ glcr::Status DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t } glcr::Status DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); // Parse denali_endpoint. uint64_t denali_endpoint_ptr = bytes.At(offset + header_size + (8 * 0)); @@ -392,15 +394,13 @@ glcr::Status DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t return glcr::Status::Ok(); } -glcr::Status DenaliInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status DenaliInfo::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); // Parse denali_endpoint. // Parse device_id. - ASSIGN_OR_RETURN(device_id_, view.ReadField(1)); + ASSIGN_OR_RETURN(device_id_, message.ReadField(1)); // Parse lba_offset. - ASSIGN_OR_RETURN(lba_offset_, view.ReadField(2)); + ASSIGN_OR_RETURN(lba_offset_, message.ReadField(2)); return glcr::Status::Ok(); } diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h index 3fb2f88..01af62b 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -32,7 +33,7 @@ class RegisterEndpointRequest { z_cap_t endpoint_capability_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class GetEndpointRequest { public: @@ -52,7 +53,7 @@ class GetEndpointRequest { glcr::String endpoint_name_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class Endpoint { public: @@ -72,7 +73,7 @@ class Endpoint { z_cap_t endpoint_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class AhciInfo { public: @@ -95,7 +96,7 @@ class AhciInfo { uint64_t region_length_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class FramebufferInfo { public: @@ -148,7 +149,7 @@ class FramebufferInfo { uint64_t blue_mask_shift_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; class DenaliInfo { public: @@ -174,7 +175,7 @@ class DenaliInfo { uint64_t lba_offset_; // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; diff --git a/yunq/message.cpp.jinja b/yunq/message.cpp.jinja index b736a6f..0c4f002 100644 --- a/yunq/message.cpp.jinja +++ b/yunq/message.cpp.jinja @@ -20,7 +20,8 @@ struct ExtPointer { {%- for message in messages %} glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); {%- for field in message.fields %} {%- if field.type == Type.CAPABILITY %} @@ -33,7 +34,8 @@ glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uin } glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(bytes, offset)); + yunq::MessageView message(bytes, offset); + RETURN_ERROR(ParseFromBytesInternal(message)); {%- for field in message.fields %} {%- if field.type == Type.CAPABILITY %} @@ -46,19 +48,17 @@ glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uin return glcr::Status::Ok(); } -glcr::Status {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - RETURN_ERROR(yunq::CheckHeader(bytes, offset)); - - yunq::MessageView view(bytes, offset); +glcr::Status {{message.name}}::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); {%- for field in message.fields %} // Parse {{field.name}}. {%- if field.type != Type.CAPABILITY %} {%- if not field.repeated %} - ASSIGN_OR_RETURN({{field.name}}_, view.ReadField<{{field.cpp_type()}}>({{loop.index0}})); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadField<{{field.cpp_type()}}>({{loop.index0}})); {%- else %} - ASSIGN_OR_RETURN({{field.name}}_, view.ReadRepeated<{{field.cpp_type()}}>({{loop.index0}})); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeated<{{field.cpp_type()}}>({{loop.index0}})); {% endif %} {%- endif %} diff --git a/yunq/message.h.jinja b/yunq/message.h.jinja index cf15b59..e98cfb5 100644 --- a/yunq/message.h.jinja +++ b/yunq/message.h.jinja @@ -6,6 +6,7 @@ #include #include #include +#include #include {% if package != None %} @@ -45,7 +46,7 @@ class {{message.name}} { {%- endfor %} // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); }; {%- endfor %}