[Yunq] Read capabilities using the parsing library.

This commit is contained in:
Drew Galbraith 2024-01-11 19:59:36 -08:00
parent 0e6aa532a1
commit 75d84a0fa5
7 changed files with 41 additions and 40 deletions

View File

@ -49,4 +49,14 @@ glcr::ErrorOr<glcr::Vector<uint64_t>> MessageView::ReadRepeated<uint64_t>(
return v;
}
glcr::ErrorOr<uint64_t> MessageView::ReadCapability(
uint64_t field_index) const {
return buffer_.At<uint64_t>(field_offset(field_index));
}
glcr::ErrorOr<uint64_t> MessageView::ReadCapability(
uint64_t field_index, const glcr::CapBuffer& caps) const {
uint64_t offset = buffer_.At<uint64_t>(field_offset(field_index));
return caps.At(offset);
}
} // namespace yunq

View File

@ -1,6 +1,7 @@
#pragma once
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <glacier/container/vector.h>
#include <glacier/status/error_or.h>
#include <glacier/status/status.h>
@ -36,6 +37,10 @@ class MessageView {
template <typename T>
glcr::ErrorOr<glcr::Vector<T>> ReadRepeated(uint64_t field_index) const;
glcr::ErrorOr<uint64_t> ReadCapability(uint64_t field_index) const;
glcr::ErrorOr<uint64_t> ReadCapability(uint64_t field_index,
const glcr::CapBuffer& caps) const;
private:
const glcr::ByteBuffer& buffer_;
uint64_t offset_;

View File

@ -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<uint64_t>(offset + header_size + (8 * 2));
set_memory(caps.At(memory_ptr));
ASSIGN_OR_RETURN(memory_, message.ReadCapability(2, caps));
return glcr::Status::Ok();
}

View File

@ -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<uint64_t>(offset + header_size + (8 * 2));
set_memory(caps.At(memory_ptr));
ASSIGN_OR_RETURN(memory_, message.ReadCapability(2, caps));
return glcr::Status::Ok();
}

View File

@ -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<uint64_t>(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();
}

View File

@ -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<uint64_t>(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<uint64_t>(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<uint64_t>(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<uint64_t>(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();
}

View File

@ -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<uint64_t>(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();