From 75d84a0fa5f2f9b93814b70a3aaa1be112dd4273 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Thu, 11 Jan 2024 19:59:36 -0800 Subject: [PATCH] [Yunq] Read capabilities using the parsing library. --- lib/yunq/message_view.cpp | 10 +++++++ lib/yunq/message_view.h | 5 ++++ sys/denali/lib/denali/denali.yunq.cpp | 7 ++--- .../lib/victoriafalls/victoriafalls.yunq.cpp | 7 ++--- .../lib/voyageurs/voyageurs.yunq.cpp | 7 ++--- .../lib/yellowstone/yellowstone.yunq.cpp | 28 ++++++------------- yunq/message.cpp.jinja | 17 +++++++---- 7 files changed, 41 insertions(+), 40 deletions(-) diff --git a/lib/yunq/message_view.cpp b/lib/yunq/message_view.cpp index 9cf2881..5e74430 100644 --- a/lib/yunq/message_view.cpp +++ b/lib/yunq/message_view.cpp @@ -49,4 +49,14 @@ glcr::ErrorOr> MessageView::ReadRepeated( return v; } +glcr::ErrorOr MessageView::ReadCapability( + uint64_t field_index) const { + return buffer_.At(field_offset(field_index)); +} + +glcr::ErrorOr MessageView::ReadCapability( + uint64_t field_index, const glcr::CapBuffer& caps) const { + uint64_t offset = buffer_.At(field_offset(field_index)); + return caps.At(offset); +} } // namespace yunq diff --git a/lib/yunq/message_view.h b/lib/yunq/message_view.h index ee5aea1..85c5fb6 100644 --- a/lib/yunq/message_view.h +++ b/lib/yunq/message_view.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -36,6 +37,10 @@ class MessageView { template glcr::ErrorOr> ReadRepeated(uint64_t field_index) const; + glcr::ErrorOr ReadCapability(uint64_t field_index) const; + glcr::ErrorOr ReadCapability(uint64_t field_index, + const glcr::CapBuffer& caps) const; + private: const glcr::ByteBuffer& buffer_; uint64_t offset_; diff --git a/sys/denali/lib/denali/denali.yunq.cpp b/sys/denali/lib/denali/denali.yunq.cpp index b142571..9a56e3a 100644 --- a/sys/denali/lib/denali/denali.yunq.cpp +++ b/sys/denali/lib/denali/denali.yunq.cpp @@ -177,8 +177,7 @@ glcr::Status ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_ yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse memory. - // FIXME: Implement in-buffer capabilities for inprocess serialization. - set_memory(0); + ASSIGN_OR_RETURN(memory_, message.ReadCapability(2)); return glcr::Status::Ok(); } @@ -186,9 +185,7 @@ glcr::Status ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_ yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse memory. - uint64_t memory_ptr = bytes.At(offset + header_size + (8 * 2)); - - set_memory(caps.At(memory_ptr)); + ASSIGN_OR_RETURN(memory_, message.ReadCapability(2, caps)); return glcr::Status::Ok(); } diff --git a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.cpp b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.cpp index e0b91cb..5bf0b5d 100644 --- a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.cpp +++ b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.cpp @@ -81,8 +81,7 @@ glcr::Status OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uin yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse memory. - // FIXME: Implement in-buffer capabilities for inprocess serialization. - set_memory(0); + ASSIGN_OR_RETURN(memory_, message.ReadCapability(2)); return glcr::Status::Ok(); } @@ -90,9 +89,7 @@ glcr::Status OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uin yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse memory. - uint64_t memory_ptr = bytes.At(offset + header_size + (8 * 2)); - - set_memory(caps.At(memory_ptr)); + ASSIGN_OR_RETURN(memory_, message.ReadCapability(2, caps)); return glcr::Status::Ok(); } diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp index 576c32d..1214c2f 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp @@ -19,8 +19,7 @@ glcr::Status KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uin yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse port_capability. - // FIXME: Implement in-buffer capabilities for inprocess serialization. - set_port_capability(0); + ASSIGN_OR_RETURN(port_capability_, message.ReadCapability(0)); return glcr::Status::Ok(); } @@ -28,9 +27,7 @@ glcr::Status KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uin yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse port_capability. - uint64_t port_capability_ptr = bytes.At(offset + header_size + (8 * 0)); - - set_port_capability(caps.At(port_capability_ptr)); + ASSIGN_OR_RETURN(port_capability_, message.ReadCapability(0, caps)); return glcr::Status::Ok(); } diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp index 54d707f..ec2dffa 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp @@ -21,8 +21,7 @@ glcr::Status RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& byt yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse endpoint_capability. - // FIXME: Implement in-buffer capabilities for inprocess serialization. - set_endpoint_capability(0); + ASSIGN_OR_RETURN(endpoint_capability_, message.ReadCapability(1)); return glcr::Status::Ok(); } @@ -30,9 +29,7 @@ glcr::Status RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& byt yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse endpoint_capability. - uint64_t endpoint_capability_ptr = bytes.At(offset + header_size + (8 * 1)); - - set_endpoint_capability(caps.At(endpoint_capability_ptr)); + ASSIGN_OR_RETURN(endpoint_capability_, message.ReadCapability(1, caps)); return glcr::Status::Ok(); } @@ -159,8 +156,7 @@ glcr::Status Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse endpoint. - // FIXME: Implement in-buffer capabilities for inprocess serialization. - set_endpoint(0); + ASSIGN_OR_RETURN(endpoint_, message.ReadCapability(0)); return glcr::Status::Ok(); } @@ -168,9 +164,7 @@ glcr::Status Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse endpoint. - uint64_t endpoint_ptr = bytes.At(offset + header_size + (8 * 0)); - - set_endpoint(caps.At(endpoint_ptr)); + ASSIGN_OR_RETURN(endpoint_, message.ReadCapability(0, caps)); return glcr::Status::Ok(); } @@ -211,8 +205,7 @@ glcr::Status AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse ahci_region. - // FIXME: Implement in-buffer capabilities for inprocess serialization. - set_ahci_region(0); + ASSIGN_OR_RETURN(ahci_region_, message.ReadCapability(0)); return glcr::Status::Ok(); } @@ -220,9 +213,7 @@ glcr::Status AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse ahci_region. - uint64_t ahci_region_ptr = bytes.At(offset + header_size + (8 * 0)); - - set_ahci_region(caps.At(ahci_region_ptr)); + ASSIGN_OR_RETURN(ahci_region_, message.ReadCapability(0, caps)); return glcr::Status::Ok(); } @@ -379,8 +370,7 @@ glcr::Status DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse denali_endpoint. - // FIXME: Implement in-buffer capabilities for inprocess serialization. - set_denali_endpoint(0); + ASSIGN_OR_RETURN(denali_endpoint_, message.ReadCapability(0)); return glcr::Status::Ok(); } @@ -388,9 +378,7 @@ glcr::Status DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t yunq::MessageView message(bytes, offset); RETURN_ERROR(ParseFromBytesInternal(message)); // Parse denali_endpoint. - uint64_t denali_endpoint_ptr = bytes.At(offset + header_size + (8 * 0)); - - set_denali_endpoint(caps.At(denali_endpoint_ptr)); + ASSIGN_OR_RETURN(denali_endpoint_, message.ReadCapability(0, caps)); return glcr::Status::Ok(); } diff --git a/yunq/message.cpp.jinja b/yunq/message.cpp.jinja index 0c4f002..67919e9 100644 --- a/yunq/message.cpp.jinja +++ b/yunq/message.cpp.jinja @@ -25,9 +25,13 @@ glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uin {%- for field in message.fields %} {%- if field.type == Type.CAPABILITY %} +{%- if not field.repeated %} // Parse {{field.name}}. - // FIXME: Implement in-buffer capabilities for inprocess serialization. - set_{{field.name}}(0); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{loop.index0}})); + {%- else %} + // Parse {{field.name}}. + ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{loop.index0}})); + {%- endif %} {%- endif %} {%- endfor %} return glcr::Status::Ok(); @@ -39,10 +43,13 @@ glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uin {%- for field in message.fields %} {%- if field.type == Type.CAPABILITY %} +{%- if not field.repeated %} // Parse {{field.name}}. - uint64_t {{field.name}}_ptr = bytes.At(offset + header_size + (8 * {{loop.index0}})); - - set_{{field.name}}(caps.At({{field.name}}_ptr)); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{loop.index0}}, caps)); + {%- else %} + // Parse {{field.name}}. + ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{loop.index0}}, caps)); + {%- endif %} {%- endif %} {%- endfor %} return glcr::Status::Ok();