129 lines
3.7 KiB
Django/Jinja
129 lines
3.7 KiB
Django/Jinja
// Generated file -- DO NOT MODIFY.
|
|
#include "{{file}}.h"
|
|
|
|
#include <yunq/message_view.h>
|
|
#include <yunq/serialize.h>
|
|
|
|
{% if package != None %}
|
|
namespace {{package.cpp_namespace()}} {
|
|
{% endif %}
|
|
namespace {
|
|
|
|
const uint64_t header_size = 24; // 4x uint32, 1x uint64
|
|
|
|
struct ExtPointer {
|
|
uint32_t offset;
|
|
uint32_t length;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
{%- for message in messages %}
|
|
glcr::Status {{message.name}}::ParseFromBytes(const yunq::MessageView& message) {
|
|
RETURN_ERROR(ParseFromBytesInternal(message));
|
|
|
|
{%- for field in message.fields %}
|
|
{%- if field.type == Type.CAPABILITY %}
|
|
{%- if not field.repeated %}
|
|
// Parse {{field.name}}.
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{field.number}}));
|
|
{%- else %}
|
|
// Parse {{field.name}}.
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{field.number}}));
|
|
{%- endif %}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
return glcr::Status::Ok();
|
|
}
|
|
|
|
glcr::Status {{message.name}}::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) {
|
|
RETURN_ERROR(ParseFromBytesInternal(message));
|
|
|
|
{%- for field in message.fields %}
|
|
{%- if field.type == Type.CAPABILITY %}
|
|
{%- if not field.repeated %}
|
|
// Parse {{field.name}}.
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{field.number}}, caps));
|
|
{%- else %}
|
|
// Parse {{field.name}}.
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{field.number}}, caps));
|
|
{%- endif %}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
return glcr::Status::Ok();
|
|
}
|
|
|
|
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.MESSAGE %}
|
|
|
|
{%- if not field.repeated %}
|
|
message.ReadMessage<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
{%- else %}
|
|
message.ReadRepeatedMessage<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
{% endif %}
|
|
|
|
{%- elif field.type != Type.CAPABILITY %}
|
|
|
|
{%- if not field.repeated %}
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadField<{{field.cpp_type()}}>({{field.number}}));
|
|
{%- else %}
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeated<{{field.cpp_type()}}>({{field.number}}));
|
|
{% endif %}
|
|
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
|
|
return glcr::Status::Ok();
|
|
}
|
|
|
|
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
|
yunq::Serializer serializer(bytes, offset, {{ message.fields | length }});
|
|
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 %}
|
|
|
|
{%- if field.type == Type.MESSAGE %}
|
|
serializer.WriteMessage<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
{%- elif field.type == Type.CAPABILITY %}
|
|
serializer.WriteCapability({{field.number}}, {{field.name}}_);
|
|
{%- else %}
|
|
serializer.WriteField<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
{%- endif %}
|
|
|
|
{%- else %}
|
|
|
|
{%- if field.type == Type.MESSAGE %}
|
|
serializer.WriteRepeatedMessage<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
{%- elif field.type != Type.CAPABILITY %}
|
|
serializer.WriteRepeatedCapability({{field.number}}, {{field.name}}_);
|
|
{%- else %}
|
|
serializer.WriteRepeated<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
{%- endif %}
|
|
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
|
|
serializer.WriteHeader();
|
|
|
|
return serializer.size();
|
|
}
|
|
|
|
{%- endfor %}
|
|
|
|
{% if package != None %}
|
|
} // namepace {{package.cpp_namespace()}}
|
|
{% endif %}
|