[Yunq] Move repeated field parsing to the yunq library.
This commit is contained in:
parent
9e9ef21a3d
commit
30b220b2fb
4 changed files with 31 additions and 27 deletions
|
|
@ -16,4 +16,19 @@ glcr::ErrorOr<glcr::String> MessageView::ReadField<glcr::String>(
|
|||
return buffer_.StringAt(offset_ + ptr.offset, ptr.length);
|
||||
}
|
||||
|
||||
template <>
|
||||
glcr::ErrorOr<glcr::Vector<uint64_t>> MessageView::ReadRepeated<uint64_t>(
|
||||
uint64_t field_index) {
|
||||
ExtensionPointer pointer =
|
||||
buffer_.At<ExtensionPointer>(field_offset(field_index));
|
||||
|
||||
glcr::Vector<uint64_t> v;
|
||||
v.Resize(pointer.length / sizeof(uint64_t));
|
||||
for (uint64_t i = offset_ + pointer.offset;
|
||||
i < offset_ + pointer.offset + pointer.length; i += sizeof(uint64_t)) {
|
||||
v.PushBack(buffer_.At<uint64_t>(i));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
} // namespace yunq
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/buffer/byte_buffer.h>
|
||||
#include <glacier/container/vector.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
|
||||
namespace yunq {
|
||||
|
|
@ -21,6 +22,9 @@ class MessageView {
|
|||
template <typename T>
|
||||
glcr::ErrorOr<T> ReadField(uint64_t field_index);
|
||||
|
||||
template <typename T>
|
||||
glcr::ErrorOr<glcr::Vector<T>> ReadRepeated(uint64_t field_index);
|
||||
|
||||
private:
|
||||
const glcr::ByteBuffer& buffer_;
|
||||
uint64_t offset_;
|
||||
|
|
@ -37,4 +41,8 @@ template <>
|
|||
glcr::ErrorOr<glcr::String> MessageView::ReadField<glcr::String>(
|
||||
uint64_t field_index);
|
||||
|
||||
template <>
|
||||
glcr::ErrorOr<glcr::Vector<uint64_t>> MessageView::ReadRepeated<uint64_t>(
|
||||
uint64_t field_index);
|
||||
|
||||
} // namespace yunq
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue