[Yunq] Add support for repeated nested fields
This commit is contained in:
parent
05f2403dc2
commit
9c860dd6a4
14 changed files with 207 additions and 61 deletions
|
|
@ -16,6 +16,7 @@ class MessageView {
|
|||
: buffer_(buffer), offset_(offset) {}
|
||||
|
||||
[[nodiscard]] glcr::Status CheckHeader() const;
|
||||
uint32_t MessageLength() const;
|
||||
|
||||
// TODO: Implement glcr::StatusOr
|
||||
template <typename T>
|
||||
|
|
@ -31,6 +32,10 @@ class MessageView {
|
|||
template <typename T>
|
||||
glcr::Status ReadMessage(uint64_t field_index, T& message) const;
|
||||
|
||||
template <typename T>
|
||||
glcr::Status ReadRepeatedMessage(uint64_t field_index,
|
||||
glcr::Vector<T>& messages) const;
|
||||
|
||||
private:
|
||||
const glcr::ByteBuffer& buffer_;
|
||||
uint64_t offset_;
|
||||
|
|
@ -61,4 +66,22 @@ glcr::Status MessageView::ReadMessage(uint64_t field_index, T& message) const {
|
|||
return message.ParseFromBytes(subview);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
glcr::Status MessageView::ReadRepeatedMessage(uint64_t field_index,
|
||||
glcr::Vector<T>& messages) const {
|
||||
ExtensionPointer ptr =
|
||||
buffer_.At<ExtensionPointer>(field_offset(field_index));
|
||||
|
||||
uint64_t ext_offset = ptr.offset;
|
||||
|
||||
while (ext_offset < ptr.offset + ptr.length) {
|
||||
MessageView subview(buffer_, offset_ + ext_offset);
|
||||
messages.EmplaceBack();
|
||||
RETURN_ERROR(messages.PeekBack().ParseFromBytes(subview));
|
||||
ext_offset += subview.MessageLength();
|
||||
}
|
||||
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
} // namespace yunq
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue