[Yunq] Move message parser to shared internal function.
This commit is contained in:
parent
a71d5e9d24
commit
984d8b143e
10 changed files with 109 additions and 155 deletions
|
|
@ -74,36 +74,15 @@ glcr::Status {{message.name}}::ParseFromBytesInternal(const yunq::MessageView& m
|
|||
|
||||
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
yunq::Serializer serializer(bytes, offset, {{ message.fields | length }});
|
||||
|
||||
{%- for field in message.fields %}
|
||||
// Write {{field.name}}.
|
||||
{%- if not field.repeated %}
|
||||
|
||||
{%- if field.type != Type.CAPABILITY %}
|
||||
serializer.WriteField<{{field.cpp_type()}}>({{loop.index0}}, {{field.name}}_);
|
||||
{%- else %}
|
||||
serializer.WriteCapability({{loop.index0}}, {{field.name}}_);
|
||||
{%- endif %}
|
||||
|
||||
{%- else %}
|
||||
|
||||
{%- if field.type != Type.CAPABILITY %}
|
||||
serializer.WriteRepeated<{{field.cpp_type()}}>({{loop.index0}}, {{field.name}}_);
|
||||
{%- else %}
|
||||
serializer.WriteRepeatedCapability({{loop.index0}}, {{field.name}}_);
|
||||
{%- endif %}
|
||||
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
||||
serializer.WriteHeader();
|
||||
|
||||
return serializer.size();
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
yunq::Serializer serializer(bytes, offset, {{ message.fields | length }}, caps);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t {{message.name}}::SerializeInternal(yunq::Serializer& serializer) const {
|
||||
{%- for field in message.fields %}
|
||||
// Write {{field.name}}.
|
||||
{%- if not field.repeated %}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <glacier/container/vector.h>
|
||||
#include <glacier/string/string.h>
|
||||
#include <yunq/message_view.h>
|
||||
#include <yunq/serialize.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
{% if package != None %}
|
||||
|
|
@ -47,6 +48,8 @@ class {{message.name}} {
|
|||
|
||||
// Parses everything except for caps.
|
||||
glcr::Status ParseFromBytesInternal(const yunq::MessageView& message);
|
||||
|
||||
uint64_t SerializeInternal(yunq::Serializer& serializer) const;
|
||||
};
|
||||
{%- endfor %}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue