2023-10-24 14:54:00 -07:00
|
|
|
// Generated file -- DO NOT MODIFY.
|
|
|
|
#include "{{file}}.h"
|
|
|
|
|
2024-01-11 19:27:57 -08:00
|
|
|
#include <yunq/message_view.h>
|
2023-12-01 09:30:52 -08:00
|
|
|
#include <yunq/serialize.h>
|
|
|
|
|
2023-11-30 08:50:15 -08:00
|
|
|
{% if package != None %}
|
|
|
|
namespace {{package.cpp_namespace()}} {
|
|
|
|
{% endif %}
|
2023-10-24 14:54:00 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const uint64_t header_size = 24; // 4x uint32, 1x uint64
|
|
|
|
|
|
|
|
struct ExtPointer {
|
|
|
|
uint32_t offset;
|
|
|
|
uint32_t length;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
{%- for message in messages %}
|
2024-01-11 20:03:34 -08:00
|
|
|
glcr::Status {{message.name}}::ParseFromBytes(const yunq::MessageView& message) {
|
2024-01-11 19:51:18 -08:00
|
|
|
RETURN_ERROR(ParseFromBytesInternal(message));
|
2023-10-24 14:54:00 -07:00
|
|
|
|
|
|
|
{%- for field in message.fields %}
|
2023-11-10 12:51:23 -08:00
|
|
|
{%- if field.type == Type.CAPABILITY %}
|
2024-01-11 19:59:36 -08:00
|
|
|
{%- if not field.repeated %}
|
|
|
|
// Parse {{field.name}}.
|
2024-01-11 20:59:20 -08:00
|
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{field.number}}));
|
2024-01-11 19:59:36 -08:00
|
|
|
{%- else %}
|
2023-10-24 14:54:00 -07:00
|
|
|
// Parse {{field.name}}.
|
2024-01-11 20:59:20 -08:00
|
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{field.number}}));
|
2024-01-11 19:59:36 -08:00
|
|
|
{%- endif %}
|
2023-10-24 14:54:00 -07:00
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
2023-12-01 09:30:52 -08:00
|
|
|
return glcr::Status::Ok();
|
2023-10-24 14:54:00 -07:00
|
|
|
}
|
|
|
|
|
2024-01-11 20:03:34 -08:00
|
|
|
glcr::Status {{message.name}}::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) {
|
2024-01-11 19:51:18 -08:00
|
|
|
RETURN_ERROR(ParseFromBytesInternal(message));
|
2023-11-10 12:51:23 -08:00
|
|
|
|
|
|
|
{%- for field in message.fields %}
|
|
|
|
{%- if field.type == Type.CAPABILITY %}
|
2024-01-11 19:59:36 -08:00
|
|
|
{%- if not field.repeated %}
|
2023-11-10 12:51:23 -08:00
|
|
|
// Parse {{field.name}}.
|
2024-01-11 20:59:20 -08:00
|
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{field.number}}, caps));
|
2024-01-11 19:59:36 -08:00
|
|
|
{%- else %}
|
|
|
|
// Parse {{field.name}}.
|
2024-01-11 20:59:20 -08:00
|
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{field.number}}, caps));
|
2024-01-11 19:59:36 -08:00
|
|
|
{%- endif %}
|
2023-11-10 12:51:23 -08:00
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
2023-12-01 09:30:52 -08:00
|
|
|
return glcr::Status::Ok();
|
2023-11-10 12:51:23 -08:00
|
|
|
}
|
|
|
|
|
2024-01-11 19:51:18 -08:00
|
|
|
glcr::Status {{message.name}}::ParseFromBytesInternal(const yunq::MessageView& message) {
|
|
|
|
RETURN_ERROR(message.CheckHeader());
|
2024-01-11 19:27:57 -08:00
|
|
|
|
2023-10-24 14:54:00 -07:00
|
|
|
{%- for field in message.fields %}
|
|
|
|
// Parse {{field.name}}.
|
2024-01-11 21:32:08 -08:00
|
|
|
{%- if field.type == Type.MESSAGE %}
|
|
|
|
|
|
|
|
{%- if not field.repeated %}
|
|
|
|
message.ReadMessage<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
|
|
{%- else %}
|
2024-01-11 22:09:42 -08:00
|
|
|
message.ReadRepeatedMessage<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
2024-01-11 21:32:08 -08:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{%- elif field.type != Type.CAPABILITY %}
|
2024-01-11 19:36:24 -08:00
|
|
|
|
|
|
|
{%- if not field.repeated %}
|
2024-01-11 20:59:20 -08:00
|
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadField<{{field.cpp_type()}}>({{field.number}}));
|
2023-11-10 12:26:59 -08:00
|
|
|
{%- else %}
|
2024-01-11 20:59:20 -08:00
|
|
|
ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeated<{{field.cpp_type()}}>({{field.number}}));
|
2023-11-10 12:26:59 -08:00
|
|
|
{% endif %}
|
2024-01-11 19:36:24 -08:00
|
|
|
|
|
|
|
{%- endif %}
|
2023-10-24 14:54:00 -07:00
|
|
|
{%- endfor %}
|
2023-11-10 12:51:23 -08:00
|
|
|
|
2023-12-01 09:30:52 -08:00
|
|
|
return glcr::Status::Ok();
|
2023-10-24 14:54:00 -07:00
|
|
|
}
|
|
|
|
|
2023-10-24 18:19:12 -07:00
|
|
|
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
2024-01-11 20:36:41 -08:00
|
|
|
yunq::Serializer serializer(bytes, offset, {{ message.fields | length }});
|
2024-01-11 20:47:39 -08:00
|
|
|
return SerializeInternal(serializer);
|
2023-10-24 14:54:00 -07:00
|
|
|
}
|
|
|
|
|
2023-10-24 18:19:12 -07:00
|
|
|
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
2024-01-11 20:36:41 -08:00
|
|
|
yunq::Serializer serializer(bytes, offset, {{ message.fields | length }}, caps);
|
2024-01-11 20:47:39 -08:00
|
|
|
return SerializeInternal(serializer);
|
|
|
|
}
|
2024-01-11 20:36:41 -08:00
|
|
|
|
2024-01-11 20:47:39 -08:00
|
|
|
uint64_t {{message.name}}::SerializeInternal(yunq::Serializer& serializer) const {
|
2023-10-24 14:54:00 -07:00
|
|
|
{%- for field in message.fields %}
|
|
|
|
// Write {{field.name}}.
|
2023-11-10 12:26:59 -08:00
|
|
|
{%- if not field.repeated %}
|
2024-01-11 20:36:41 -08:00
|
|
|
|
2024-01-11 21:32:08 -08:00
|
|
|
{%- if field.type == Type.MESSAGE %}
|
|
|
|
serializer.WriteMessage<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
|
|
{%- elif field.type == Type.CAPABILITY %}
|
2024-01-11 20:59:20 -08:00
|
|
|
serializer.WriteCapability({{field.number}}, {{field.name}}_);
|
2024-01-11 21:32:08 -08:00
|
|
|
{%- else %}
|
|
|
|
serializer.WriteField<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
2023-10-24 14:54:00 -07:00
|
|
|
{%- endif %}
|
2024-01-11 20:36:41 -08:00
|
|
|
|
2023-11-10 12:26:59 -08:00
|
|
|
{%- else %}
|
2024-01-11 20:36:41 -08:00
|
|
|
|
2024-01-11 22:09:42 -08:00
|
|
|
{%- if field.type == Type.MESSAGE %}
|
|
|
|
serializer.WriteRepeatedMessage<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
|
|
|
{%- elif field.type != Type.CAPABILITY %}
|
2024-01-11 20:59:20 -08:00
|
|
|
serializer.WriteRepeatedCapability({{field.number}}, {{field.name}}_);
|
2024-01-11 22:09:42 -08:00
|
|
|
{%- else %}
|
|
|
|
serializer.WriteRepeated<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_);
|
2024-01-11 20:36:41 -08:00
|
|
|
{%- endif %}
|
|
|
|
|
2023-11-10 12:26:59 -08:00
|
|
|
{%- endif %}
|
2023-10-24 14:54:00 -07:00
|
|
|
{%- endfor %}
|
|
|
|
|
2024-01-11 20:36:41 -08:00
|
|
|
serializer.WriteHeader();
|
2023-10-24 14:54:00 -07:00
|
|
|
|
2024-01-11 20:36:41 -08:00
|
|
|
return serializer.size();
|
2023-10-24 14:54:00 -07:00
|
|
|
}
|
2024-01-11 20:36:41 -08:00
|
|
|
|
2023-10-24 14:54:00 -07:00
|
|
|
{%- endfor %}
|
2023-11-30 08:50:15 -08:00
|
|
|
|
|
|
|
{% if package != None %}
|
|
|
|
} // namepace {{package.cpp_namespace()}}
|
|
|
|
{% endif %}
|