[Yunq] Move serialization to yunq library.
This commit is contained in:
parent
0135d8d844
commit
7ec4f696a8
|
@ -6,23 +6,10 @@
|
|||
#include <glacier/status/error_or.h>
|
||||
#include <glacier/status/status.h>
|
||||
|
||||
#include "yunq/yunq.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;
|
||||
};
|
||||
|
||||
class MessageView {
|
||||
public:
|
||||
MessageView(const glcr::ByteBuffer& buffer, uint64_t offset)
|
||||
|
|
|
@ -7,12 +7,38 @@ const uint64_t kIdentByte = 0x33441122;
|
|||
|
||||
} // namespace
|
||||
|
||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size,
|
||||
uint32_t extension_size) {
|
||||
bytes.WriteAt<uint32_t>(offset + 0, kIdentByte);
|
||||
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
||||
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
||||
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
||||
void Serializer::WriteHeader() {
|
||||
buffer_.WriteAt<uint32_t>(offset_ + 0, kIdentByte);
|
||||
buffer_.WriteAt<uint32_t>(offset_ + 4, core_size_);
|
||||
buffer_.WriteAt<uint32_t>(offset_ + 8, next_extension_);
|
||||
buffer_.WriteAt<uint32_t>(offset_ + 12, 0); // TODO: Calculate CRC32.
|
||||
}
|
||||
|
||||
template <>
|
||||
void Serializer::WriteField<glcr::String>(uint64_t field_index,
|
||||
const glcr::String& value) {
|
||||
ExtensionPointer ptr{
|
||||
.offset = (uint32_t)next_extension_,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)value.length(),
|
||||
};
|
||||
|
||||
buffer_.WriteStringAt(offset_ + next_extension_, value);
|
||||
next_extension_ += ptr.length;
|
||||
|
||||
buffer_.WriteAt<ExtensionPointer>(field_offset(field_index), ptr);
|
||||
}
|
||||
|
||||
void Serializer::WriteCapability(uint64_t field_index, uint64_t value) {
|
||||
if (caps_) {
|
||||
buffer_.WriteAt<uint64_t>(field_offset(field_index), next_cap_);
|
||||
caps_.value().get().WriteAt(next_cap_++, value);
|
||||
} else {
|
||||
WriteField<uint64_t>(field_index, value);
|
||||
}
|
||||
}
|
||||
|
||||
void Serializer::WriteRepeatedCapability(uint64_t field_index,
|
||||
const glcr::Vector<uint64_t>& value) {}
|
||||
|
||||
} // namespace yunq
|
||||
|
|
|
@ -1,11 +1,84 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/buffer/byte_buffer.h>
|
||||
#include <glacier/buffer/cap_buffer.h>
|
||||
#include <glacier/container/optional.h>
|
||||
#include <glacier/container/vector.h>
|
||||
#include <glacier/memory/reference.h>
|
||||
#include <glacier/status/status.h>
|
||||
|
||||
#include "yunq/yunq.h"
|
||||
|
||||
namespace yunq {
|
||||
|
||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size,
|
||||
uint32_t extension_size);
|
||||
class Serializer {
|
||||
public:
|
||||
Serializer(glcr::ByteBuffer& bytes, uint64_t offset, uint64_t num_fields)
|
||||
: buffer_(bytes),
|
||||
offset_(offset),
|
||||
next_extension_(kHeaderSize + (8 * num_fields)),
|
||||
core_size_(next_extension_),
|
||||
caps_() {}
|
||||
Serializer(glcr::ByteBuffer& bytes, uint64_t offset, uint64_t num_fields,
|
||||
glcr::CapBuffer& caps)
|
||||
: buffer_(bytes),
|
||||
offset_(offset),
|
||||
next_extension_(kHeaderSize + (8 * num_fields)),
|
||||
core_size_(next_extension_),
|
||||
caps_(caps) {}
|
||||
|
||||
template <typename T>
|
||||
void WriteField(uint64_t field_index, const T& value);
|
||||
|
||||
template <typename T>
|
||||
void WriteRepeated(uint64_t field_index, const glcr::Vector<T>& value);
|
||||
|
||||
void WriteCapability(uint64_t field_index, uint64_t value);
|
||||
|
||||
void WriteRepeatedCapability(uint64_t field_index,
|
||||
const glcr::Vector<uint64_t>& value);
|
||||
|
||||
void WriteHeader();
|
||||
|
||||
uint64_t size() const { return next_extension_; }
|
||||
|
||||
private:
|
||||
glcr::ByteBuffer& buffer_;
|
||||
uint64_t offset_;
|
||||
uint64_t next_extension_;
|
||||
uint64_t core_size_;
|
||||
uint64_t next_cap_ = 0;
|
||||
glcr::Optional<glcr::Ref<glcr::CapBuffer>> caps_;
|
||||
|
||||
uint64_t field_offset(uint64_t field_index) const {
|
||||
return offset_ + kHeaderSize + (8 * field_index);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void Serializer::WriteField(uint64_t field_index, const T& value) {
|
||||
buffer_.WriteAt<T>(field_offset(field_index), value);
|
||||
}
|
||||
|
||||
template <>
|
||||
void Serializer::WriteField<glcr::String>(uint64_t field_index,
|
||||
const glcr::String& value);
|
||||
|
||||
template <typename T>
|
||||
void Serializer::WriteRepeated(uint64_t field_index,
|
||||
const glcr::Vector<T>& value) {
|
||||
ExtensionPointer ptr{
|
||||
.offset = (uint32_t)next_extension_,
|
||||
.length = (uint32_t)(value.size() * sizeof(T)),
|
||||
};
|
||||
|
||||
next_extension_ += ptr.length;
|
||||
buffer_.WriteAt<ExtensionPointer>(field_offset(field_index), ptr);
|
||||
|
||||
for (uint64_t i = 0; i < value.size(); i++) {
|
||||
uint32_t ext_offset = offset_ + ptr.offset + (i * sizeof(T));
|
||||
buffer_.WriteAt<T>(ext_offset, value.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace yunq
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace yunq {
|
||||
|
||||
struct MessageHeader {
|
||||
uint32_t ident;
|
||||
uint32_t core_length;
|
||||
uint32_t length;
|
||||
uint32_t crc32;
|
||||
uint64_t options;
|
||||
} __attribute__((packed));
|
||||
|
||||
const uint64_t kHeaderSize = 24; // 4x uint32, 1x uint64
|
||||
|
||||
struct ExtensionPointer {
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
};
|
||||
|
||||
} // namespace yunq
|
|
@ -38,36 +38,31 @@ glcr::Status ReadRequest::ParseFromBytesInternal(const yunq::MessageView& messag
|
|||
}
|
||||
|
||||
uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 3);
|
||||
// Write device_id.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), device_id());
|
||||
serializer.WriteField<uint64_t>(0, device_id_);
|
||||
// Write lba.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), lba());
|
||||
serializer.WriteField<uint64_t>(1, lba_);
|
||||
// Write size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), size());
|
||||
serializer.WriteField<uint64_t>(2, size_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 3, caps);
|
||||
// Write device_id.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), device_id());
|
||||
serializer.WriteField<uint64_t>(0, device_id_);
|
||||
// Write lba.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), lba());
|
||||
serializer.WriteField<uint64_t>(1, lba_);
|
||||
// Write size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), size());
|
||||
serializer.WriteField<uint64_t>(2, size_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status ReadManyRequest::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -94,80 +89,31 @@ glcr::Status ReadManyRequest::ParseFromBytesInternal(const yunq::MessageView& me
|
|||
}
|
||||
|
||||
uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 3);
|
||||
// Write device_id.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), device_id());
|
||||
serializer.WriteField<uint64_t>(0, device_id_);
|
||||
// Write lba.
|
||||
ExtPointer lba_ptr{
|
||||
.offset = next_extension,
|
||||
.length = (uint32_t)(lba().size() * sizeof(uint64_t)),
|
||||
};
|
||||
|
||||
next_extension += lba_ptr.length;
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 1), lba_ptr);
|
||||
|
||||
for (uint64_t i = 0; i < lba().size(); i++) {
|
||||
uint32_t ext_offset = offset + lba_ptr.offset + (i * sizeof(uint64_t));
|
||||
bytes.WriteAt<uint64_t>(ext_offset, lba().at(i));
|
||||
}
|
||||
serializer.WriteRepeated<uint64_t>(1, lba_);
|
||||
// Write sector_cnt.
|
||||
ExtPointer sector_cnt_ptr{
|
||||
.offset = next_extension,
|
||||
.length = (uint32_t)(sector_cnt().size() * sizeof(uint64_t)),
|
||||
};
|
||||
serializer.WriteRepeated<uint64_t>(2, sector_cnt_);
|
||||
|
||||
next_extension += sector_cnt_ptr.length;
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 2), sector_cnt_ptr);
|
||||
serializer.WriteHeader();
|
||||
|
||||
for (uint64_t i = 0; i < sector_cnt().size(); i++) {
|
||||
uint32_t ext_offset = offset + sector_cnt_ptr.offset + (i * sizeof(uint64_t));
|
||||
bytes.WriteAt<uint64_t>(ext_offset, sector_cnt().at(i));
|
||||
}
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 3, caps);
|
||||
// Write device_id.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), device_id());
|
||||
serializer.WriteField<uint64_t>(0, device_id_);
|
||||
// Write lba.
|
||||
ExtPointer lba_ptr{
|
||||
.offset = next_extension,
|
||||
.length = (uint32_t)(lba().size() * sizeof(uint64_t)),
|
||||
};
|
||||
|
||||
next_extension += lba_ptr.length;
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 1), lba_ptr);
|
||||
|
||||
for (uint64_t i = 0; i < lba().size(); i++) {
|
||||
uint32_t ext_offset = offset + lba_ptr.offset + (i * sizeof(uint64_t));
|
||||
bytes.WriteAt<uint64_t>(ext_offset, lba().at(i));
|
||||
}
|
||||
serializer.WriteRepeated<uint64_t>(1, lba_);
|
||||
// Write sector_cnt.
|
||||
ExtPointer sector_cnt_ptr{
|
||||
.offset = next_extension,
|
||||
.length = (uint32_t)(sector_cnt().size() * sizeof(uint64_t)),
|
||||
};
|
||||
serializer.WriteRepeated<uint64_t>(2, sector_cnt_);
|
||||
|
||||
next_extension += sector_cnt_ptr.length;
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 2), sector_cnt_ptr);
|
||||
serializer.WriteHeader();
|
||||
|
||||
for (uint64_t i = 0; i < sector_cnt().size(); i++) {
|
||||
uint32_t ext_offset = offset + sector_cnt_ptr.offset + (i * sizeof(uint64_t));
|
||||
bytes.WriteAt<uint64_t>(ext_offset, sector_cnt().at(i));
|
||||
}
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status ReadResponse::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -195,37 +141,30 @@ glcr::Status ReadResponse::ParseFromBytesInternal(const yunq::MessageView& messa
|
|||
}
|
||||
|
||||
uint64_t ReadResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 3);
|
||||
// Write device_id.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), device_id());
|
||||
serializer.WriteField<uint64_t>(0, device_id_);
|
||||
// Write size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), size());
|
||||
serializer.WriteField<uint64_t>(1, size_);
|
||||
// Write memory.
|
||||
// FIXME: Implement inbuffer capabilities.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), 0);
|
||||
serializer.WriteCapability(2, memory_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t ReadResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 3, caps);
|
||||
// Write device_id.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), device_id());
|
||||
serializer.WriteField<uint64_t>(0, device_id_);
|
||||
// Write size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), size());
|
||||
serializer.WriteField<uint64_t>(1, size_);
|
||||
// Write memory.
|
||||
caps.WriteAt(next_cap, memory());
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), next_cap++);
|
||||
serializer.WriteCapability(2, memory_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,46 +34,23 @@ glcr::Status OpenFileRequest::ParseFromBytesInternal(const yunq::MessageView& me
|
|||
}
|
||||
|
||||
uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
// Write path.
|
||||
ExtPointer path_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)path().length(),
|
||||
};
|
||||
serializer.WriteField<glcr::String>(0, path_);
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, path());
|
||||
next_extension += path_ptr.length;
|
||||
serializer.WriteHeader();
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
// Write path.
|
||||
ExtPointer path_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)path().length(),
|
||||
};
|
||||
serializer.WriteField<glcr::String>(0, path_);
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, path());
|
||||
next_extension += path_ptr.length;
|
||||
serializer.WriteHeader();
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status OpenFileResponse::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -101,56 +78,31 @@ glcr::Status OpenFileResponse::ParseFromBytesInternal(const yunq::MessageView& m
|
|||
}
|
||||
|
||||
uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 3);
|
||||
// Write path.
|
||||
ExtPointer path_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)path().length(),
|
||||
};
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, path());
|
||||
next_extension += path_ptr.length;
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||
serializer.WriteField<glcr::String>(0, path_);
|
||||
// Write size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), size());
|
||||
serializer.WriteField<uint64_t>(1, size_);
|
||||
// Write memory.
|
||||
// FIXME: Implement inbuffer capabilities.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), 0);
|
||||
serializer.WriteCapability(2, memory_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 3, caps);
|
||||
// Write path.
|
||||
ExtPointer path_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)path().length(),
|
||||
};
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, path());
|
||||
next_extension += path_ptr.length;
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||
serializer.WriteField<glcr::String>(0, path_);
|
||||
// Write size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), size());
|
||||
serializer.WriteField<uint64_t>(1, size_);
|
||||
// Write memory.
|
||||
caps.WriteAt(next_cap, memory());
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), next_cap++);
|
||||
serializer.WriteCapability(2, memory_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status GetDirectoryRequest::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -171,46 +123,23 @@ glcr::Status GetDirectoryRequest::ParseFromBytesInternal(const yunq::MessageView
|
|||
}
|
||||
|
||||
uint64_t GetDirectoryRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
// Write path.
|
||||
ExtPointer path_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)path().length(),
|
||||
};
|
||||
serializer.WriteField<glcr::String>(0, path_);
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, path());
|
||||
next_extension += path_ptr.length;
|
||||
serializer.WriteHeader();
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t GetDirectoryRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
// Write path.
|
||||
ExtPointer path_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)path().length(),
|
||||
};
|
||||
serializer.WriteField<glcr::String>(0, path_);
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, path());
|
||||
next_extension += path_ptr.length;
|
||||
serializer.WriteHeader();
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status Directory::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -231,45 +160,22 @@ glcr::Status Directory::ParseFromBytesInternal(const yunq::MessageView& message)
|
|||
}
|
||||
|
||||
uint64_t Directory::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
// Write filenames.
|
||||
ExtPointer filenames_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)filenames().length(),
|
||||
};
|
||||
serializer.WriteField<glcr::String>(0, filenames_);
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, filenames());
|
||||
next_extension += filenames_ptr.length;
|
||||
serializer.WriteHeader();
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), filenames_ptr);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t Directory::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
// Write filenames.
|
||||
ExtPointer filenames_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)filenames().length(),
|
||||
};
|
||||
serializer.WriteField<glcr::String>(0, filenames_);
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, filenames());
|
||||
next_extension += filenames_ptr.length;
|
||||
serializer.WriteHeader();
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), filenames_ptr);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,29 +37,22 @@ glcr::Status KeyboardListener::ParseFromBytesInternal(const yunq::MessageView& m
|
|||
}
|
||||
|
||||
uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
// Write port_capability.
|
||||
// FIXME: Implement inbuffer capabilities.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
||||
serializer.WriteCapability(0, port_capability_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
// Write port_capability.
|
||||
caps.WriteAt(next_cap, port_capability());
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
||||
serializer.WriteCapability(0, port_capability_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,52 +41,27 @@ glcr::Status RegisterEndpointRequest::ParseFromBytesInternal(const yunq::Message
|
|||
}
|
||||
|
||||
uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 2;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 2);
|
||||
// Write endpoint_name.
|
||||
ExtPointer endpoint_name_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)endpoint_name().length(),
|
||||
};
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, endpoint_name());
|
||||
next_extension += endpoint_name_ptr.length;
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
|
||||
serializer.WriteField<glcr::String>(0, endpoint_name_);
|
||||
// Write endpoint_capability.
|
||||
// FIXME: Implement inbuffer capabilities.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), 0);
|
||||
serializer.WriteCapability(1, endpoint_capability_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 2;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 2, caps);
|
||||
// Write endpoint_name.
|
||||
ExtPointer endpoint_name_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)endpoint_name().length(),
|
||||
};
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, endpoint_name());
|
||||
next_extension += endpoint_name_ptr.length;
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
|
||||
serializer.WriteField<glcr::String>(0, endpoint_name_);
|
||||
// Write endpoint_capability.
|
||||
caps.WriteAt(next_cap, endpoint_capability());
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), next_cap++);
|
||||
serializer.WriteCapability(1, endpoint_capability_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status GetEndpointRequest::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -107,46 +82,23 @@ glcr::Status GetEndpointRequest::ParseFromBytesInternal(const yunq::MessageView&
|
|||
}
|
||||
|
||||
uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
// Write endpoint_name.
|
||||
ExtPointer endpoint_name_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)endpoint_name().length(),
|
||||
};
|
||||
serializer.WriteField<glcr::String>(0, endpoint_name_);
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, endpoint_name());
|
||||
next_extension += endpoint_name_ptr.length;
|
||||
serializer.WriteHeader();
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
// Write endpoint_name.
|
||||
ExtPointer endpoint_name_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t)endpoint_name().length(),
|
||||
};
|
||||
serializer.WriteField<glcr::String>(0, endpoint_name_);
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, endpoint_name());
|
||||
next_extension += endpoint_name_ptr.length;
|
||||
serializer.WriteHeader();
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status Endpoint::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -170,30 +122,23 @@ glcr::Status Endpoint::ParseFromBytesInternal(const yunq::MessageView& message)
|
|||
}
|
||||
|
||||
uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
// Write endpoint.
|
||||
// FIXME: Implement inbuffer capabilities.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
||||
serializer.WriteCapability(0, endpoint_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 1;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
// Write endpoint.
|
||||
caps.WriteAt(next_cap, endpoint());
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
||||
serializer.WriteCapability(0, endpoint_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status AhciInfo::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -219,34 +164,27 @@ glcr::Status AhciInfo::ParseFromBytesInternal(const yunq::MessageView& message)
|
|||
}
|
||||
|
||||
uint64_t AhciInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 2;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 2);
|
||||
// Write ahci_region.
|
||||
// FIXME: Implement inbuffer capabilities.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
||||
serializer.WriteCapability(0, ahci_region_);
|
||||
// Write region_length.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), region_length());
|
||||
serializer.WriteField<uint64_t>(1, region_length_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t AhciInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 2;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 2, caps);
|
||||
// Write ahci_region.
|
||||
caps.WriteAt(next_cap, ahci_region());
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
||||
serializer.WriteCapability(0, ahci_region_);
|
||||
// Write region_length.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), region_length());
|
||||
serializer.WriteField<uint64_t>(1, region_length_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status FramebufferInfo::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -289,72 +227,67 @@ glcr::Status FramebufferInfo::ParseFromBytesInternal(const yunq::MessageView& me
|
|||
}
|
||||
|
||||
uint64_t FramebufferInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 12;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 12);
|
||||
// Write address_phys.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), address_phys());
|
||||
serializer.WriteField<uint64_t>(0, address_phys_);
|
||||
// Write width.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), width());
|
||||
serializer.WriteField<uint64_t>(1, width_);
|
||||
// Write height.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), height());
|
||||
serializer.WriteField<uint64_t>(2, height_);
|
||||
// Write pitch.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 3), pitch());
|
||||
serializer.WriteField<uint64_t>(3, pitch_);
|
||||
// Write bpp.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 4), bpp());
|
||||
serializer.WriteField<uint64_t>(4, bpp_);
|
||||
// Write memory_model.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 5), memory_model());
|
||||
serializer.WriteField<uint64_t>(5, memory_model_);
|
||||
// Write red_mask_size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 6), red_mask_size());
|
||||
serializer.WriteField<uint64_t>(6, red_mask_size_);
|
||||
// Write red_mask_shift.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 7), red_mask_shift());
|
||||
serializer.WriteField<uint64_t>(7, red_mask_shift_);
|
||||
// Write green_mask_size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 8), green_mask_size());
|
||||
serializer.WriteField<uint64_t>(8, green_mask_size_);
|
||||
// Write green_mask_shift.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 9), green_mask_shift());
|
||||
serializer.WriteField<uint64_t>(9, green_mask_shift_);
|
||||
// Write blue_mask_size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 10), blue_mask_size());
|
||||
serializer.WriteField<uint64_t>(10, blue_mask_size_);
|
||||
// Write blue_mask_shift.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 11), blue_mask_shift());
|
||||
serializer.WriteField<uint64_t>(11, blue_mask_shift_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t FramebufferInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 12;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 12, caps);
|
||||
// Write address_phys.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), address_phys());
|
||||
serializer.WriteField<uint64_t>(0, address_phys_);
|
||||
// Write width.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), width());
|
||||
serializer.WriteField<uint64_t>(1, width_);
|
||||
// Write height.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), height());
|
||||
serializer.WriteField<uint64_t>(2, height_);
|
||||
// Write pitch.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 3), pitch());
|
||||
serializer.WriteField<uint64_t>(3, pitch_);
|
||||
// Write bpp.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 4), bpp());
|
||||
serializer.WriteField<uint64_t>(4, bpp_);
|
||||
// Write memory_model.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 5), memory_model());
|
||||
serializer.WriteField<uint64_t>(5, memory_model_);
|
||||
// Write red_mask_size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 6), red_mask_size());
|
||||
serializer.WriteField<uint64_t>(6, red_mask_size_);
|
||||
// Write red_mask_shift.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 7), red_mask_shift());
|
||||
serializer.WriteField<uint64_t>(7, red_mask_shift_);
|
||||
// Write green_mask_size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 8), green_mask_size());
|
||||
serializer.WriteField<uint64_t>(8, green_mask_size_);
|
||||
// Write green_mask_shift.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 9), green_mask_shift());
|
||||
serializer.WriteField<uint64_t>(9, green_mask_shift_);
|
||||
// Write blue_mask_size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 10), blue_mask_size());
|
||||
serializer.WriteField<uint64_t>(10, blue_mask_size_);
|
||||
// Write blue_mask_shift.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 11), blue_mask_shift());
|
||||
serializer.WriteField<uint64_t>(11, blue_mask_shift_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status DenaliInfo::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
|
@ -382,38 +315,31 @@ glcr::Status DenaliInfo::ParseFromBytesInternal(const yunq::MessageView& message
|
|||
}
|
||||
|
||||
uint64_t DenaliInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
yunq::Serializer serializer(bytes, offset, 3);
|
||||
// Write denali_endpoint.
|
||||
// FIXME: Implement inbuffer capabilities.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
||||
serializer.WriteCapability(0, denali_endpoint_);
|
||||
// Write device_id.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), device_id());
|
||||
serializer.WriteField<uint64_t>(1, device_id_);
|
||||
// Write lba_offset.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), lba_offset());
|
||||
serializer.WriteField<uint64_t>(2, lba_offset_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t DenaliInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
yunq::Serializer serializer(bytes, offset, 3, caps);
|
||||
// Write denali_endpoint.
|
||||
caps.WriteAt(next_cap, denali_endpoint());
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
||||
serializer.WriteCapability(0, denali_endpoint_);
|
||||
// Write device_id.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), device_id());
|
||||
serializer.WriteField<uint64_t>(1, device_id_);
|
||||
// Write lba_offset.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), lba_offset());
|
||||
serializer.WriteField<uint64_t>(2, lba_offset_);
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -73,105 +73,63 @@ glcr::Status {{message.name}}::ParseFromBytesInternal(const yunq::MessageView& m
|
|||
}
|
||||
|
||||
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
uint32_t next_extension = header_size + 8 * {{ message.fields | length }};
|
||||
const uint32_t core_size = next_extension;
|
||||
|
||||
yunq::Serializer serializer(bytes, offset, {{ message.fields | length }});
|
||||
|
||||
{%- for field in message.fields %}
|
||||
// Write {{field.name}}.
|
||||
{%- if not field.repeated %}
|
||||
{%- if field.type == Type.U64 %}
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
|
||||
{%- elif field.type == Type.I64 %}
|
||||
bytes.WriteAt<int64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
|
||||
{%- elif field.type == Type.STRING %}
|
||||
ExtPointer {{field.name}}_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t){{field.name}}().length(),
|
||||
};
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, {{field.name}}());
|
||||
next_extension += {{field.name}}_ptr.length;
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}_ptr);
|
||||
{%- elif field.type == Type.CAPABILITY %}
|
||||
// FIXME: Implement inbuffer capabilities.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), 0);
|
||||
{%- if field.type != Type.CAPABILITY %}
|
||||
serializer.WriteField<{{field.cpp_type()}}>({{loop.index0}}, {{field.name}}_);
|
||||
{%- else %}
|
||||
// TODO: Unimplemented serialization {{field.type}}
|
||||
serializer.WriteCapability({{loop.index0}}, {{field.name}}_);
|
||||
{%- endif %}
|
||||
|
||||
{%- else %}
|
||||
ExtPointer {{field.name}}_ptr{
|
||||
.offset = next_extension,
|
||||
.length = (uint32_t)({{field.name}}().size() * sizeof({{field.cpp_type()}})),
|
||||
};
|
||||
|
||||
next_extension += {{field.name}}_ptr.length;
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}_ptr);
|
||||
{%- if field.type != Type.CAPABILITY %}
|
||||
serializer.WriteRepeated<{{field.cpp_type()}}>({{loop.index0}}, {{field.name}}_);
|
||||
{%- else %}
|
||||
serializer.WriteRepeatedCapability({{loop.index0}}, {{field.name}}_);
|
||||
{%- endif %}
|
||||
|
||||
for (uint64_t i = 0; i < {{field.name}}().size(); i++) {
|
||||
uint32_t ext_offset = offset + {{field.name}}_ptr.offset + (i * sizeof({{field.cpp_type()}}));
|
||||
bytes.WriteAt<{{field.cpp_type()}}>(ext_offset, {{field.name}}().at(i));
|
||||
}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
uint32_t next_extension = header_size + 8 * {{ message.fields | length}};
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
|
||||
yunq::Serializer serializer(bytes, offset, {{ message.fields | length }}, caps);
|
||||
|
||||
{%- for field in message.fields %}
|
||||
// Write {{field.name}}.
|
||||
{%- if not field.repeated %}
|
||||
{%- if field.type == Type.U64 %}
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
|
||||
{%- elif field.type == Type.I64 %}
|
||||
bytes.WriteAt<int64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
|
||||
{%- elif field.type == Type.STRING %}
|
||||
ExtPointer {{field.name}}_ptr{
|
||||
.offset = next_extension,
|
||||
// FIXME: Check downcast of str length.
|
||||
.length = (uint32_t){{field.name}}().length(),
|
||||
};
|
||||
|
||||
bytes.WriteStringAt(offset + next_extension, {{field.name}}());
|
||||
next_extension += {{field.name}}_ptr.length;
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}_ptr);
|
||||
{%- elif field.type == Type.CAPABILITY %}
|
||||
caps.WriteAt(next_cap, {{field.name}}());
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), next_cap++);
|
||||
{%- if field.type != Type.CAPABILITY %}
|
||||
serializer.WriteField<{{field.cpp_type()}}>({{loop.index0}}, {{field.name}}_);
|
||||
{%- else %}
|
||||
// TODO: Unimplemented serialization {{field.type}}
|
||||
serializer.WriteCapability({{loop.index0}}, {{field.name}}_);
|
||||
{%- endif %}
|
||||
|
||||
{%- else %}
|
||||
ExtPointer {{field.name}}_ptr{
|
||||
.offset = next_extension,
|
||||
.length = (uint32_t)({{field.name}}().size() * sizeof({{field.cpp_type()}})),
|
||||
};
|
||||
|
||||
next_extension += {{field.name}}_ptr.length;
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}_ptr);
|
||||
{%- if field.type != Type.CAPABILITY %}
|
||||
serializer.WriteRepeated<{{field.cpp_type()}}>({{loop.index0}}, {{field.name}}_);
|
||||
{%- else %}
|
||||
serializer.WriteRepeatedCapability({{loop.index0}}, {{field.name}}_);
|
||||
{%- endif %}
|
||||
|
||||
for (uint64_t i = 0; i < {{field.name}}().size(); i++) {
|
||||
uint32_t ext_offset = offset + {{field.name}}_ptr.offset + (i * sizeof({{field.cpp_type()}}));
|
||||
bytes.WriteAt<{{field.cpp_type()}}>(ext_offset, {{field.name}}().at(i));
|
||||
}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
serializer.WriteHeader();
|
||||
|
||||
return next_extension;
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
{%- endfor %}
|
||||
|
||||
{% if package != None %}
|
||||
|
|
Loading…
Reference in New Issue