[Yunq] Add a basic yunq test into libyunq.
This commit is contained in:
parent
9c860dd6a4
commit
fecaa387b0
21 changed files with 189 additions and 936 deletions
5
lib/yunq/test/example/example.yunq
Normal file
5
lib/yunq/test/example/example.yunq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package ex;
|
||||
|
||||
message Basic {
|
||||
u64 field;
|
||||
}
|
||||
58
lib/yunq/test/example/example.yunq.cpp
Normal file
58
lib/yunq/test/example/example.yunq.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Generated file -- DO NOT MODIFY.
|
||||
#include "example.yunq.h"
|
||||
|
||||
#include <yunq/message_view.h>
|
||||
#include <yunq/serialize.h>
|
||||
|
||||
|
||||
namespace ex {
|
||||
|
||||
namespace {
|
||||
|
||||
const uint64_t header_size = 24; // 4x uint32, 1x uint64
|
||||
|
||||
struct ExtPointer {
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
glcr::Status Basic::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::Status Basic::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::Status Basic::ParseFromBytesInternal(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(message.CheckHeader());
|
||||
// Parse field.
|
||||
ASSIGN_OR_RETURN(field_, message.ReadField<uint64_t>(0));
|
||||
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
uint64_t Basic::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t Basic::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t Basic::SerializeInternal(yunq::Serializer& serializer) const {
|
||||
// Write field.
|
||||
serializer.WriteField<uint64_t>(0, field_);
|
||||
|
||||
serializer.WriteHeader();
|
||||
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
|
||||
} // namepace ex
|
||||
43
lib/yunq/test/example/example.yunq.h
Normal file
43
lib/yunq/test/example/example.yunq.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Generated file - DO NOT MODIFY
|
||||
#pragma once
|
||||
|
||||
#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 <yunq/message_view.h>
|
||||
#include <yunq/serialize.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
|
||||
namespace ex {
|
||||
|
||||
class Basic {
|
||||
public:
|
||||
Basic() {}
|
||||
// Delete copy and move until implemented.
|
||||
Basic(const Basic&) = delete;
|
||||
Basic(Basic&&) = default;
|
||||
Basic& operator=(Basic&&) = default;
|
||||
|
||||
[[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message);
|
||||
[[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer&);
|
||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||
|
||||
const uint64_t& field() const { return field_; }
|
||||
uint64_t& mutable_field() { return field_; }
|
||||
void set_field(const uint64_t& value) { field_ = value; }
|
||||
|
||||
private:
|
||||
uint64_t field_;
|
||||
|
||||
// Parses everything except for caps.
|
||||
glcr::Status ParseFromBytesInternal(const yunq::MessageView& message);
|
||||
|
||||
uint64_t SerializeInternal(yunq::Serializer& serializer) const;
|
||||
};
|
||||
|
||||
|
||||
} // namepace ex
|
||||
Loading…
Add table
Add a link
Reference in a new issue