Compare commits
No commits in common. "52142afeb8a3a8adf24c07ff9497fa42c810f6eb" and "0e99189dba851335d2f44e426b73ceb73d0c0d3e" have entirely different histories.
52142afeb8
...
0e99189dba
|
@ -4,7 +4,7 @@ interface VFS {
|
||||||
|
|
||||||
message OpenFileRequest {
|
message OpenFileRequest {
|
||||||
string path;
|
string path;
|
||||||
repeated u64 options;
|
u64 options;
|
||||||
}
|
}
|
||||||
|
|
||||||
message File {
|
message File {
|
||||||
|
|
|
@ -28,30 +28,23 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, u
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenFileRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
|
||||||
CheckHeader(bytes);
|
CheckHeader(bytes);
|
||||||
// Parse path.
|
// Parse path.
|
||||||
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
|
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
|
||||||
// Parse options.
|
// Parse options.
|
||||||
auto options_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 1));
|
set_options(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
|
||||||
|
}
|
||||||
options_.Resize(options_pointer.length);
|
|
||||||
for (uint64_t i = offset + options_pointer.offset;
|
|
||||||
i < offset + options_pointer.offset + (sizeof(uint64_t) * options_pointer.length);
|
|
||||||
i += sizeof(uint64_t)) {
|
|
||||||
options_.PushBack(bytes.At<uint64_t>(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
|
CheckHeader(bytes);
|
||||||
|
// Parse path.
|
||||||
|
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
|
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
|
||||||
|
// Parse options.
|
||||||
|
set_options(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -69,18 +62,7 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
|
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||||
// Write options.
|
// Write options.
|
||||||
ExtPointer options_ptr{
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), options());
|
||||||
.offset = next_extension,
|
|
||||||
.length = (uint32_t)(options().size() * sizeof(uint64_t)),
|
|
||||||
};
|
|
||||||
|
|
||||||
next_extension += options_ptr.length;
|
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 1), options_ptr);
|
|
||||||
|
|
||||||
for (uint64_t i = 0; i < options().size(); i++) {
|
|
||||||
uint32_t ext_offset = offset + options_ptr.offset + (i * sizeof(uint64_t));
|
|
||||||
bytes.WriteAt<uint64_t>(ext_offset, options().at(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
@ -104,18 +86,7 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
|
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||||
// Write options.
|
// Write options.
|
||||||
ExtPointer options_ptr{
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), options());
|
||||||
.offset = next_extension,
|
|
||||||
.length = (uint32_t)(options().size() * sizeof(uint64_t)),
|
|
||||||
};
|
|
||||||
|
|
||||||
next_extension += options_ptr.length;
|
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 1), options_ptr);
|
|
||||||
|
|
||||||
for (uint64_t i = 0; i < options().size(); i++) {
|
|
||||||
uint32_t ext_offset = offset + options_ptr.offset + (i * sizeof(uint64_t));
|
|
||||||
bytes.WriteAt<uint64_t>(ext_offset, options().at(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
@ -123,21 +94,6 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void File::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
void File::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
// Parse mem_cap.
|
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
|
||||||
set_mem_cap(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void File::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
// Parse mem_cap.
|
|
||||||
uint64_t mem_cap_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
|
|
||||||
|
|
||||||
set_mem_cap(caps.At(mem_cap_ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
void File::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
|
||||||
CheckHeader(bytes);
|
CheckHeader(bytes);
|
||||||
// Parse path.
|
// Parse path.
|
||||||
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
@ -146,8 +102,22 @@ void File::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset
|
||||||
// Parse attrs.
|
// Parse attrs.
|
||||||
set_attrs(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
|
set_attrs(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
|
||||||
// Parse mem_cap.
|
// Parse mem_cap.
|
||||||
// Skip Cap.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
|
set_mem_cap(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void File::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
|
CheckHeader(bytes);
|
||||||
|
// Parse path.
|
||||||
|
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
|
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
|
||||||
|
// Parse attrs.
|
||||||
|
set_attrs(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
|
||||||
|
// Parse mem_cap.
|
||||||
|
uint64_t mem_cap_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
|
||||||
|
|
||||||
|
set_mem_cap(caps.At(mem_cap_ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t File::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t File::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
#include <glacier/container/vector.h>
|
|
||||||
#include <glacier/string/string.h>
|
#include <glacier/string/string.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
class OpenFileRequest {
|
class OpenFileRequest {
|
||||||
|
@ -16,18 +15,16 @@ class OpenFileRequest {
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
glcr::String path() const { return path_; }
|
glcr::String path() const { return path_; }
|
||||||
void set_path(const glcr::String& value) { path_ = value; }
|
void set_path(const glcr::String& value) { path_ = value; }
|
||||||
const glcr::Vector<uint64_t>& options() const { return options_; }
|
uint64_t options() const { return options_; }
|
||||||
void add_options(const uint64_t& value) { options_.PushBack(value); }
|
void set_options(const uint64_t& value) { options_ = value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glcr::String path_;
|
glcr::String path_;
|
||||||
glcr::Vector<uint64_t> options_;
|
uint64_t options_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
|
||||||
};
|
};
|
||||||
class File {
|
class File {
|
||||||
public:
|
public:
|
||||||
|
@ -39,11 +36,11 @@ class File {
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
glcr::String path() const { return path_; }
|
glcr::String path() const { return path_; }
|
||||||
void set_path(const glcr::String& value) { path_ = value; }
|
void set_path(const glcr::String& value) { path_ = value; }
|
||||||
uint64_t attrs() const { return attrs_; }
|
uint64_t attrs() const { return attrs_; }
|
||||||
void set_attrs(const uint64_t& value) { attrs_ = value; }
|
void set_attrs(const uint64_t& value) { attrs_ = value; }
|
||||||
z_cap_t mem_cap() const { return mem_cap_; }
|
z_cap_t mem_cap() const { return mem_cap_; }
|
||||||
void set_mem_cap(const z_cap_t& value) { mem_cap_ = value; }
|
void set_mem_cap(const z_cap_t& value) { mem_cap_ = value; }
|
||||||
|
|
||||||
|
@ -52,6 +49,4 @@ class File {
|
||||||
uint64_t attrs_;
|
uint64_t attrs_;
|
||||||
z_cap_t mem_cap_;
|
z_cap_t mem_cap_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
|
||||||
};
|
};
|
|
@ -31,7 +31,8 @@ void VFSServerBaseThreadBootstrap(void* server_base) {
|
||||||
|
|
||||||
glcr::ErrorOr<VFSClient> VFSServerBase::CreateClient() {
|
glcr::ErrorOr<VFSClient> VFSServerBase::CreateClient() {
|
||||||
uint64_t client_cap;
|
uint64_t client_cap;
|
||||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
// FIXME: Restrict permissions to send-only here.
|
||||||
|
RET_ERR(ZCapDuplicate(endpoint_, &client_cap));
|
||||||
return VFSClient(client_cap);
|
return VFSClient(client_cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,9 +51,9 @@ void VFSServerBase::ServerThread() {
|
||||||
uint64_t recv_cap_size = 0x10;
|
uint64_t recv_cap_size = 0x10;
|
||||||
uint64_t recv_buf_size = 0x1000;
|
uint64_t recv_buf_size = 0x1000;
|
||||||
recv_cap.Reset();
|
recv_cap.Reset();
|
||||||
glcr::ErrorCode recv_err = static_cast<glcr::ErrorCode>(ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap));
|
glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap);
|
||||||
if (recv_err != glcr::OK) {
|
if (recv_err != glcr::OK) {
|
||||||
dbgln("Error in receive: {x}", recv_err);
|
dbgln("Error in receive: %x", recv_err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,13 +64,13 @@ void VFSServerBase::ServerThread() {
|
||||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||||
if (err != glcr::OK) {
|
if (err != glcr::OK) {
|
||||||
WriteError(resp_buffer, err);
|
WriteError(resp_buffer, err);
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr);
|
||||||
} else {
|
} else {
|
||||||
WriteHeader(resp_buffer, resp_length);
|
WriteHeader(resp_buffer, resp_length);
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr()));
|
reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr());
|
||||||
}
|
}
|
||||||
if (reply_err != glcr::OK) {
|
if (reply_err != glcr::OK) {
|
||||||
dbgln("Error in reply: {x}", reply_err);
|
dbgln("Error in reply: %x", reply_err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,36 +30,10 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, u
|
||||||
|
|
||||||
{%- for message in messages %}
|
{%- for message in messages %}
|
||||||
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
|
||||||
{%- if field.type == Type.CAPABILITY %}
|
|
||||||
// Parse {{field.name}}.
|
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
|
||||||
set_{{field.name}}(0);
|
|
||||||
{%- endif %}
|
|
||||||
{%- endfor %}
|
|
||||||
}
|
|
||||||
|
|
||||||
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
|
||||||
{%- if field.type == Type.CAPABILITY %}
|
|
||||||
// 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));
|
|
||||||
{%- endif %}
|
|
||||||
{%- endfor %}
|
|
||||||
}
|
|
||||||
|
|
||||||
void {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
|
||||||
CheckHeader(bytes);
|
CheckHeader(bytes);
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
{%- for field in message.fields %}
|
||||||
// Parse {{field.name}}.
|
// Parse {{field.name}}.
|
||||||
{%- if not field.repeated %}
|
|
||||||
{%- if field.type == Type.U64 %}
|
{%- if field.type == Type.U64 %}
|
||||||
set_{{field.name}}(bytes.At<uint64_t>(offset + header_size + (8 * {{loop.index0}})));
|
set_{{field.name}}(bytes.At<uint64_t>(offset + header_size + (8 * {{loop.index0}})));
|
||||||
{%- elif field.type == Type.I64 %}
|
{%- elif field.type == Type.I64 %}
|
||||||
|
@ -69,22 +43,35 @@ void {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uin
|
||||||
|
|
||||||
set_{{field.name}}(bytes.StringAt(offset + {{field.name}}_pointer.offset, {{field.name}}_pointer.length));
|
set_{{field.name}}(bytes.StringAt(offset + {{field.name}}_pointer.offset, {{field.name}}_pointer.length));
|
||||||
{%- elif field.type == Type.CAPABILITY %}
|
{%- elif field.type == Type.CAPABILITY %}
|
||||||
// Skip Cap.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
|
set_{{field.name}}(0);
|
||||||
{%- else %}
|
{%- else %}
|
||||||
// TODO: Unimplemented parsing {{field.type}}
|
// TODO: Unimplemented parsing {{field.type}}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- else %}
|
{%- endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
|
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
|
CheckHeader(bytes);
|
||||||
|
|
||||||
|
{%- for field in message.fields %}
|
||||||
|
// Parse {{field.name}}.
|
||||||
|
{%- if field.type == Type.U64 %}
|
||||||
|
set_{{field.name}}(bytes.At<uint64_t>(offset + header_size + (8 * {{loop.index0}})));
|
||||||
|
{%- elif field.type == Type.I64 %}
|
||||||
|
set_{{field.name}}(bytes.At<int64_t>(offset + header_size + (8 * {{loop.index0}})));
|
||||||
|
{%- elif field.type == Type.STRING %}
|
||||||
auto {{field.name}}_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * {{loop.index0}}));
|
auto {{field.name}}_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * {{loop.index0}}));
|
||||||
|
|
||||||
{{field.name}}_.Resize({{field.name}}_pointer.length / sizeof({{field.cpp_type()}}));
|
set_{{field.name}}(bytes.StringAt(offset + {{field.name}}_pointer.offset, {{field.name}}_pointer.length));
|
||||||
for (uint64_t i = offset + {{field.name}}_pointer.offset;
|
{%- elif field.type == Type.CAPABILITY %}
|
||||||
i < offset + {{field.name}}_pointer.offset + {{field.name}}_pointer.length;
|
uint64_t {{field.name}}_ptr = bytes.At<uint64_t>(offset + header_size + (8 * {{loop.index0}}));
|
||||||
i += sizeof({{field.cpp_type()}})) {
|
|
||||||
{{field.name}}_.PushBack(bytes.At<{{field.cpp_type()}}>(i));
|
|
||||||
}
|
|
||||||
{% endif %}
|
|
||||||
{%- endfor %}
|
|
||||||
|
|
||||||
|
set_{{field.name}}(caps.At({{field.name}}_ptr));
|
||||||
|
{%- else %}
|
||||||
|
// TODO: Unimplemented parsing {{field.type}}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -93,7 +80,6 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
{%- for field in message.fields %}
|
||||||
// Write {{field.name}}.
|
// Write {{field.name}}.
|
||||||
{%- if not field.repeated %}
|
|
||||||
{%- if field.type == Type.U64 %}
|
{%- if field.type == Type.U64 %}
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
|
||||||
{%- elif field.type == Type.I64 %}
|
{%- elif field.type == Type.I64 %}
|
||||||
|
@ -115,20 +101,6 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
{%- else %}
|
{%- else %}
|
||||||
// TODO: Unimplemented serialization {{field.type}}
|
// TODO: Unimplemented serialization {{field.type}}
|
||||||
{%- endif %}
|
{%- 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);
|
|
||||||
|
|
||||||
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 %}
|
{%- endfor %}
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
|
@ -144,7 +116,6 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
{%- for field in message.fields %}
|
||||||
// Write {{field.name}}.
|
// Write {{field.name}}.
|
||||||
{%- if not field.repeated %}
|
|
||||||
{%- if field.type == Type.U64 %}
|
{%- if field.type == Type.U64 %}
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
|
||||||
{%- elif field.type == Type.I64 %}
|
{%- elif field.type == Type.I64 %}
|
||||||
|
@ -166,20 +137,6 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
{%- else %}
|
{%- else %}
|
||||||
// TODO: Unimplemented serialization {{field.type}}
|
// TODO: Unimplemented serialization {{field.type}}
|
||||||
{%- endif %}
|
{%- 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);
|
|
||||||
|
|
||||||
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 %}
|
{%- endfor %}
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
#include <glacier/container/vector.h>
|
|
||||||
#include <glacier/string/string.h>
|
#include <glacier/string/string.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
@ -22,25 +21,14 @@ class {{message.name}} {
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
{%- for field in message.fields %}
|
||||||
{%- if not field.repeated %}
|
|
||||||
{{field.cpp_type()}} {{field.name}}() const { return {{field.name}}_; }
|
{{field.cpp_type()}} {{field.name}}() const { return {{field.name}}_; }
|
||||||
void set_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_ = value; }
|
void set_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_ = value; }
|
||||||
{%- else %}
|
|
||||||
const glcr::Vector<{{field.cpp_type()}}>& {{field.name}}() const { return {{field.name}}_; }
|
|
||||||
void add_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_.PushBack(value); }
|
|
||||||
{%- endif %}
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
{%- for field in message.fields %}
|
{%- for field in message.fields %}
|
||||||
{%- if not field.repeated %}
|
|
||||||
{{field.cpp_type()}} {{field.name}}_;
|
{{field.cpp_type()}} {{field.name}}_;
|
||||||
{%- else %}
|
|
||||||
glcr::Vector<{{field.cpp_type()}}> {{field.name}}_;
|
|
||||||
{%- endif %}
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
// Parses everything except for caps.
|
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
|
||||||
};
|
};
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
|
@ -114,10 +114,9 @@ type_to_cppstr = {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Field():
|
class Field():
|
||||||
def __init__(self, fieldtype: Type, name: str, repeated = False):
|
def __init__(self, fieldtype: Type, name: str):
|
||||||
self.type = fieldtype
|
self.type = fieldtype
|
||||||
self.name = name
|
self.name = name
|
||||||
self.repeated = repeated
|
|
||||||
|
|
||||||
def cpp_type(self):
|
def cpp_type(self):
|
||||||
return type_to_cppstr[self.type]
|
return type_to_cppstr[self.type]
|
||||||
|
@ -251,19 +250,14 @@ class Parser():
|
||||||
|
|
||||||
def field(self):
|
def field(self):
|
||||||
|
|
||||||
repeated = False
|
|
||||||
field_type_str = self.consume_identifier()
|
field_type_str = self.consume_identifier()
|
||||||
if field_type_str == "repeated":
|
|
||||||
repeated = True
|
|
||||||
field_type_str = self.consume_identifier()
|
|
||||||
|
|
||||||
if field_type_str not in type_str_dict.keys():
|
if field_type_str not in type_str_dict.keys():
|
||||||
sys.exit("Expected type got '%s'" % field_type_str)
|
sys.exit("Expected type got '%s'" % field_type_str)
|
||||||
field_type = type_str_dict[field_type_str]
|
field_type = type_str_dict[field_type_str]
|
||||||
|
|
||||||
name = self.consume_identifier()
|
name = self.consume_identifier()
|
||||||
self.consume_check(LexemeType.SEMICOLON)
|
self.consume_check(LexemeType.SEMICOLON)
|
||||||
return Field(field_type, name, repeated)
|
return Field(field_type, name)
|
||||||
|
|
||||||
def type_check(decls: list[Decl]):
|
def type_check(decls: list[Decl]):
|
||||||
for decl in decls:
|
for decl in decls:
|
||||||
|
|
|
@ -30,11 +30,7 @@ void dbg(const glcr::StringView& str) {
|
||||||
void AddProcPrefix() {
|
void AddProcPrefix() {
|
||||||
if (gScheduler != nullptr) {
|
if (gScheduler != nullptr) {
|
||||||
auto t = gScheduler->CurrentThread();
|
auto t = gScheduler->CurrentThread();
|
||||||
|
dbg(glcr::StrFormat("[{}.{}] ", t->pid(), t->tid()));
|
||||||
char buffer[16];
|
|
||||||
glcr::FixedStringBuilder builder(buffer, 16);
|
|
||||||
glcr::StrFormatIntoBuffer(builder, "[{}.{}] ", t->pid(), t->tid());
|
|
||||||
dbg(builder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue