[Yunq] Add parse/serialize for i64 field along with tests.
This commit is contained in:
parent
e83720e67c
commit
a1f0197e83
9 changed files with 187 additions and 2 deletions
|
|
@ -3,3 +3,13 @@ package ex;
|
|||
message Basic {
|
||||
u64 field;
|
||||
}
|
||||
|
||||
message Types {
|
||||
u64 unsigned_int;
|
||||
i64 signed_int;
|
||||
string str;
|
||||
}
|
||||
|
||||
message Cap {
|
||||
capability cap;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,89 @@ uint64_t Basic::SerializeInternal(yunq::Serializer& serializer) const {
|
|||
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status Types::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::Status Types::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::Status Types::ParseFromBytesInternal(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(message.CheckHeader());
|
||||
// Parse unsigned_int.
|
||||
ASSIGN_OR_RETURN(unsigned_int_, message.ReadField<uint64_t>(0));
|
||||
// Parse signed_int.
|
||||
ASSIGN_OR_RETURN(signed_int_, message.ReadField<int64_t>(1));
|
||||
// Parse str.
|
||||
ASSIGN_OR_RETURN(str_, message.ReadField<glcr::String>(2));
|
||||
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
uint64_t Types::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
yunq::Serializer serializer(bytes, offset, 3);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t Types::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
yunq::Serializer serializer(bytes, offset, 3, caps);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t Types::SerializeInternal(yunq::Serializer& serializer) const {
|
||||
// Write unsigned_int.
|
||||
serializer.WriteField<uint64_t>(0, unsigned_int_);
|
||||
// Write signed_int.
|
||||
serializer.WriteField<int64_t>(1, signed_int_);
|
||||
// Write str.
|
||||
serializer.WriteField<glcr::String>(2, str_);
|
||||
|
||||
serializer.WriteHeader();
|
||||
|
||||
return serializer.size();
|
||||
}
|
||||
glcr::Status Cap::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
// Parse cap.
|
||||
ASSIGN_OR_RETURN(cap_, message.ReadCapability(0));
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::Status Cap::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
// Parse cap.
|
||||
ASSIGN_OR_RETURN(cap_, message.ReadCapability(0, caps));
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::Status Cap::ParseFromBytesInternal(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(message.CheckHeader());
|
||||
// Parse cap.
|
||||
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
uint64_t Cap::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t Cap::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t Cap::SerializeInternal(yunq::Serializer& serializer) const {
|
||||
// Write cap.
|
||||
serializer.WriteCapability(0, cap_);
|
||||
|
||||
serializer.WriteHeader();
|
||||
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
|
||||
} // namepace ex
|
||||
|
|
|
|||
|
|
@ -38,6 +38,66 @@ class Basic {
|
|||
|
||||
uint64_t SerializeInternal(yunq::Serializer& serializer) const;
|
||||
};
|
||||
class Types {
|
||||
public:
|
||||
Types() {}
|
||||
// Delete copy and move until implemented.
|
||||
Types(const Types&) = delete;
|
||||
Types(Types&&) = default;
|
||||
Types& operator=(Types&&) = 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& unsigned_int() const { return unsigned_int_; }
|
||||
uint64_t& mutable_unsigned_int() { return unsigned_int_; }
|
||||
void set_unsigned_int(const uint64_t& value) { unsigned_int_ = value; }
|
||||
|
||||
const int64_t& signed_int() const { return signed_int_; }
|
||||
int64_t& mutable_signed_int() { return signed_int_; }
|
||||
void set_signed_int(const int64_t& value) { signed_int_ = value; }
|
||||
|
||||
const glcr::String& str() const { return str_; }
|
||||
glcr::String& mutable_str() { return str_; }
|
||||
void set_str(const glcr::String& value) { str_ = value; }
|
||||
|
||||
private:
|
||||
uint64_t unsigned_int_;
|
||||
int64_t signed_int_;
|
||||
glcr::String str_;
|
||||
|
||||
// Parses everything except for caps.
|
||||
glcr::Status ParseFromBytesInternal(const yunq::MessageView& message);
|
||||
|
||||
uint64_t SerializeInternal(yunq::Serializer& serializer) const;
|
||||
};
|
||||
class Cap {
|
||||
public:
|
||||
Cap() {}
|
||||
// Delete copy and move until implemented.
|
||||
Cap(const Cap&) = delete;
|
||||
Cap(Cap&&) = default;
|
||||
Cap& operator=(Cap&&) = 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 z_cap_t& cap() const { return cap_; }
|
||||
z_cap_t& mutable_cap() { return cap_; }
|
||||
void set_cap(const z_cap_t& value) { cap_ = value; }
|
||||
|
||||
private:
|
||||
z_cap_t cap_;
|
||||
|
||||
// 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