[Yunq] Move MessageView higher in call stack.

This commit is contained in:
Drew Galbraith 2024-01-11 19:51:18 -08:00
parent 30b220b2fb
commit 0e6aa532a1
14 changed files with 181 additions and 160 deletions

View File

@ -2,14 +2,32 @@
namespace yunq {
namespace {
const uint64_t kIdentByte = 0x33441122;
} // namespace
glcr::Status MessageView::CheckHeader() const {
if (buffer_.At<uint32_t>(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<uint64_t> MessageView::ReadField<uint64_t>(uint64_t field_index) {
glcr::ErrorOr<uint64_t> MessageView::ReadField<uint64_t>(
uint64_t field_index) const {
return buffer_.At<uint64_t>(field_offset(field_index));
}
template <>
glcr::ErrorOr<glcr::String> MessageView::ReadField<glcr::String>(
uint64_t field_index) {
uint64_t field_index) const {
ExtensionPointer ptr =
buffer_.At<ExtensionPointer>(field_offset(field_index));
@ -18,7 +36,7 @@ glcr::ErrorOr<glcr::String> MessageView::ReadField<glcr::String>(
template <>
glcr::ErrorOr<glcr::Vector<uint64_t>> MessageView::ReadRepeated<uint64_t>(
uint64_t field_index) {
uint64_t field_index) const {
ExtensionPointer pointer =
buffer_.At<ExtensionPointer>(field_offset(field_index));

View File

@ -3,11 +3,20 @@
#include <glacier/buffer/byte_buffer.h>
#include <glacier/container/vector.h>
#include <glacier/status/error_or.h>
#include <glacier/status/status.h>
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 <typename T>
glcr::ErrorOr<T> ReadField(uint64_t field_index);
glcr::ErrorOr<T> ReadField(uint64_t field_index) const;
template <typename T>
glcr::ErrorOr<glcr::Vector<T>> ReadRepeated(uint64_t field_index);
glcr::ErrorOr<glcr::Vector<T>> 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<uint64_t> MessageView::ReadField<uint64_t>(uint64_t field_index);
glcr::ErrorOr<uint64_t> MessageView::ReadField<uint64_t>(
uint64_t field_index) const;
template <>
glcr::ErrorOr<glcr::String> MessageView::ReadField<glcr::String>(
uint64_t field_index);
uint64_t field_index) const;
template <>
glcr::ErrorOr<glcr::Vector<uint64_t>> MessageView::ReadRepeated<uint64_t>(
uint64_t field_index);
uint64_t field_index) const;
} // namespace yunq

View File

@ -7,17 +7,6 @@ const uint64_t kIdentByte = 0x33441122;
} // namespace
glcr::Status CheckHeader(const glcr::ByteBuffer& buffer, uint64_t offset) {
if (buffer.At<uint32_t>(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<uint32_t>(offset + 0, kIdentByte);

View File

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

View File

@ -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<uint64_t>(0));
ASSIGN_OR_RETURN(device_id_, message.ReadField<uint64_t>(0));
// Parse lba.
ASSIGN_OR_RETURN(lba_, view.ReadField<uint64_t>(1));
ASSIGN_OR_RETURN(lba_, message.ReadField<uint64_t>(1));
// Parse size.
ASSIGN_OR_RETURN(size_, view.ReadField<uint64_t>(2));
ASSIGN_OR_RETURN(size_, message.ReadField<uint64_t>(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<uint64_t>(0));
ASSIGN_OR_RETURN(device_id_, message.ReadField<uint64_t>(0));
// Parse lba.
ASSIGN_OR_RETURN(lba_, view.ReadRepeated<uint64_t>(1));
ASSIGN_OR_RETURN(lba_, message.ReadRepeated<uint64_t>(1));
// Parse sector_cnt.
ASSIGN_OR_RETURN(sector_cnt_, view.ReadRepeated<uint64_t>(2));
ASSIGN_OR_RETURN(sector_cnt_, message.ReadRepeated<uint64_t>(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<uint64_t>(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<uint64_t>(0));
ASSIGN_OR_RETURN(device_id_, message.ReadField<uint64_t>(0));
// Parse size.
ASSIGN_OR_RETURN(size_, view.ReadField<uint64_t>(1));
ASSIGN_OR_RETURN(size_, message.ReadField<uint64_t>(1));
// Parse memory.
return glcr::Status::Ok();

View File

@ -6,6 +6,7 @@
#include <glacier/status/status.h>
#include <glacier/container/vector.h>
#include <glacier/string/string.h>
#include <yunq/message_view.h>
#include <ztypes.h>
@ -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<uint64_t> 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);
};

View File

@ -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<glcr::String>(0));
ASSIGN_OR_RETURN(path_, message.ReadField<glcr::String>(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<uint64_t>(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<glcr::String>(0));
ASSIGN_OR_RETURN(path_, message.ReadField<glcr::String>(0));
// Parse size.
ASSIGN_OR_RETURN(size_, view.ReadField<uint64_t>(1));
ASSIGN_OR_RETURN(size_, message.ReadField<uint64_t>(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<glcr::String>(0));
ASSIGN_OR_RETURN(path_, message.ReadField<glcr::String>(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<glcr::String>(0));
ASSIGN_OR_RETURN(filenames_, message.ReadField<glcr::String>(0));
return glcr::Status::Ok();
}

View File

@ -6,6 +6,7 @@
#include <glacier/status/status.h>
#include <glacier/container/vector.h>
#include <glacier/string/string.h>
#include <yunq/message_view.h>
#include <ztypes.h>
@ -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);
};

View File

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

View File

@ -6,6 +6,7 @@
#include <glacier/status/status.h>
#include <glacier/container/vector.h>
#include <glacier/string/string.h>
#include <yunq/message_view.h>
#include <ztypes.h>
@ -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);
};

View File

@ -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<uint64_t>(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<glcr::String>(0));
ASSIGN_OR_RETURN(endpoint_name_, message.ReadField<glcr::String>(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<glcr::String>(0));
ASSIGN_OR_RETURN(endpoint_name_, message.ReadField<glcr::String>(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<uint64_t>(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<uint64_t>(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<uint64_t>(1));
ASSIGN_OR_RETURN(region_length_, message.ReadField<uint64_t>(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<uint64_t>(0));
ASSIGN_OR_RETURN(address_phys_, message.ReadField<uint64_t>(0));
// Parse width.
ASSIGN_OR_RETURN(width_, view.ReadField<uint64_t>(1));
ASSIGN_OR_RETURN(width_, message.ReadField<uint64_t>(1));
// Parse height.
ASSIGN_OR_RETURN(height_, view.ReadField<uint64_t>(2));
ASSIGN_OR_RETURN(height_, message.ReadField<uint64_t>(2));
// Parse pitch.
ASSIGN_OR_RETURN(pitch_, view.ReadField<uint64_t>(3));
ASSIGN_OR_RETURN(pitch_, message.ReadField<uint64_t>(3));
// Parse bpp.
ASSIGN_OR_RETURN(bpp_, view.ReadField<uint64_t>(4));
ASSIGN_OR_RETURN(bpp_, message.ReadField<uint64_t>(4));
// Parse memory_model.
ASSIGN_OR_RETURN(memory_model_, view.ReadField<uint64_t>(5));
ASSIGN_OR_RETURN(memory_model_, message.ReadField<uint64_t>(5));
// Parse red_mask_size.
ASSIGN_OR_RETURN(red_mask_size_, view.ReadField<uint64_t>(6));
ASSIGN_OR_RETURN(red_mask_size_, message.ReadField<uint64_t>(6));
// Parse red_mask_shift.
ASSIGN_OR_RETURN(red_mask_shift_, view.ReadField<uint64_t>(7));
ASSIGN_OR_RETURN(red_mask_shift_, message.ReadField<uint64_t>(7));
// Parse green_mask_size.
ASSIGN_OR_RETURN(green_mask_size_, view.ReadField<uint64_t>(8));
ASSIGN_OR_RETURN(green_mask_size_, message.ReadField<uint64_t>(8));
// Parse green_mask_shift.
ASSIGN_OR_RETURN(green_mask_shift_, view.ReadField<uint64_t>(9));
ASSIGN_OR_RETURN(green_mask_shift_, message.ReadField<uint64_t>(9));
// Parse blue_mask_size.
ASSIGN_OR_RETURN(blue_mask_size_, view.ReadField<uint64_t>(10));
ASSIGN_OR_RETURN(blue_mask_size_, message.ReadField<uint64_t>(10));
// Parse blue_mask_shift.
ASSIGN_OR_RETURN(blue_mask_shift_, view.ReadField<uint64_t>(11));
ASSIGN_OR_RETURN(blue_mask_shift_, message.ReadField<uint64_t>(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<uint64_t>(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<uint64_t>(1));
ASSIGN_OR_RETURN(device_id_, message.ReadField<uint64_t>(1));
// Parse lba_offset.
ASSIGN_OR_RETURN(lba_offset_, view.ReadField<uint64_t>(2));
ASSIGN_OR_RETURN(lba_offset_, message.ReadField<uint64_t>(2));
return glcr::Status::Ok();
}

View File

@ -6,6 +6,7 @@
#include <glacier/status/status.h>
#include <glacier/container/vector.h>
#include <glacier/string/string.h>
#include <yunq/message_view.h>
#include <ztypes.h>
@ -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);
};

View File

@ -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 %}

View File

@ -6,6 +6,7 @@
#include <glacier/status/status.h>
#include <glacier/container/vector.h>
#include <glacier/string/string.h>
#include <yunq/message_view.h>
#include <ztypes.h>
{% 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 %}