[Yunq] Move MessageView higher in call stack.
This commit is contained in:
parent
30b220b2fb
commit
0e6aa532a1
14 changed files with 181 additions and 160 deletions
|
|
@ -3,11 +3,20 @@
|
|||
#include <glacier/buffer/byte_buffer.h>
|
||||
#include <glacier/container/vector.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <glacier/status/status.h>
|
||||
|
||||
namespace yunq {
|
||||
|
||||
const uint64_t kHeaderSize = 24; // 4x uint32, 1x uint64
|
||||
|
||||
struct MessageHeader {
|
||||
uint32_t ident;
|
||||
uint32_t core_length;
|
||||
uint32_t length;
|
||||
uint32_t crc32;
|
||||
uint64_t options;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ExtensionPointer {
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
|
|
@ -18,31 +27,34 @@ class MessageView {
|
|||
MessageView(const glcr::ByteBuffer& buffer, uint64_t offset)
|
||||
: buffer_(buffer), offset_(offset) {}
|
||||
|
||||
[[nodiscard]] glcr::Status CheckHeader() const;
|
||||
|
||||
// TODO: Implement glcr::StatusOr
|
||||
template <typename T>
|
||||
glcr::ErrorOr<T> ReadField(uint64_t field_index);
|
||||
glcr::ErrorOr<T> ReadField(uint64_t field_index) const;
|
||||
|
||||
template <typename T>
|
||||
glcr::ErrorOr<glcr::Vector<T>> ReadRepeated(uint64_t field_index);
|
||||
glcr::ErrorOr<glcr::Vector<T>> ReadRepeated(uint64_t field_index) const;
|
||||
|
||||
private:
|
||||
const glcr::ByteBuffer& buffer_;
|
||||
uint64_t offset_;
|
||||
|
||||
uint64_t field_offset(uint64_t field_index) {
|
||||
uint64_t field_offset(uint64_t field_index) const {
|
||||
return offset_ + kHeaderSize + (8 * field_index);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
glcr::ErrorOr<uint64_t> MessageView::ReadField<uint64_t>(uint64_t field_index);
|
||||
glcr::ErrorOr<uint64_t> MessageView::ReadField<uint64_t>(
|
||||
uint64_t field_index) const;
|
||||
|
||||
template <>
|
||||
glcr::ErrorOr<glcr::String> MessageView::ReadField<glcr::String>(
|
||||
uint64_t field_index);
|
||||
uint64_t field_index) const;
|
||||
|
||||
template <>
|
||||
glcr::ErrorOr<glcr::Vector<uint64_t>> MessageView::ReadRepeated<uint64_t>(
|
||||
uint64_t field_index);
|
||||
uint64_t field_index) const;
|
||||
|
||||
} // namespace yunq
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue