[Yunq] Create libyunq and move parsing code to it.
This commit is contained in:
parent
91f3f8ee43
commit
7d9f9a7ae9
16 changed files with 310 additions and 260 deletions
|
|
@ -17,6 +17,8 @@ macro(yunq_gen dir include_dir name)
|
|||
|
||||
target_link_libraries(${target}
|
||||
mammoth
|
||||
glacier
|
||||
yunq
|
||||
)
|
||||
set_target_properties(${target} PROPERTIES
|
||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Generated file -- DO NOT MODIFY.
|
||||
#include "{{file}}.h"
|
||||
|
||||
#include <yunq/serialize.h>
|
||||
|
||||
{% if package != None %}
|
||||
namespace {{package.cpp_namespace()}} {
|
||||
{% endif %}
|
||||
|
|
@ -13,27 +15,11 @@ struct ExtPointer {
|
|||
uint32_t length;
|
||||
};
|
||||
|
||||
void CheckHeader(const glcr::ByteBuffer& bytes) {
|
||||
// TODO: Check ident.
|
||||
// TODO: Parse core size.
|
||||
// TODO: Parse extension size.
|
||||
// TODO: Check CRC32
|
||||
// TODO: Parse options.
|
||||
}
|
||||
|
||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) {
|
||||
bytes.WriteAt<uint32_t>(offset + 0, 0xDEADBEEF); // TODO: Chose a more unique ident sequence.
|
||||
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.
|
||||
bytes.WriteAt<uint64_t>(offset + 16, 0); // TODO: Add options.
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
{%- for message in messages %}
|
||||
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||
ParseFromBytesInternal(bytes, offset);
|
||||
glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||
|
||||
{%- for field in message.fields %}
|
||||
{%- if field.type == Type.CAPABILITY %}
|
||||
|
|
@ -42,10 +28,11 @@ void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of
|
|||
set_{{field.name}}(0);
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||
ParseFromBytesInternal(bytes, offset);
|
||||
glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||
|
||||
{%- for field in message.fields %}
|
||||
{%- if field.type == Type.CAPABILITY %}
|
||||
|
|
@ -55,10 +42,11 @@ void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of
|
|||
set_{{field.name}}(caps.At({{field.name}}_ptr));
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
void {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||
CheckHeader(bytes);
|
||||
glcr::Status {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||
RETURN_ERROR(yunq::CheckHeader(bytes));
|
||||
|
||||
{%- for field in message.fields %}
|
||||
// Parse {{field.name}}.
|
||||
|
|
@ -88,6 +76,7 @@ void {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uin
|
|||
{% endif %}
|
||||
{%- endfor %}
|
||||
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
|
|
@ -135,7 +124,7 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
|||
{%- endfor %}
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
WriteHeader(bytes, offset, core_size, next_extension);
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
}
|
||||
|
|
@ -186,7 +175,7 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
|||
{%- endfor %}
|
||||
|
||||
// The next extension pointer is the length of the message.
|
||||
WriteHeader(bytes, offset, core_size, next_extension);
|
||||
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <glacier/buffer/byte_buffer.h>
|
||||
#include <glacier/buffer/cap_buffer.h>
|
||||
#include <glacier/status/status.h>
|
||||
#include <glacier/container/vector.h>
|
||||
#include <glacier/string/string.h>
|
||||
#include <ztypes.h>
|
||||
|
|
@ -19,8 +20,8 @@ class {{message.name}} {
|
|||
{{message.name}}(const {{message.name}}&) = delete;
|
||||
{{message.name}}({{message.name}}&&) = delete;
|
||||
|
||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||
glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||
glcr::Status 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, glcr::CapBuffer&) const;
|
||||
|
||||
|
|
@ -44,7 +45,7 @@ class {{message.name}} {
|
|||
{%- endfor %}
|
||||
|
||||
// Parses everything except for caps.
|
||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||
};
|
||||
{%- endfor %}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue