[Yunq] POC for moving yunq parsing to a library.
This commit is contained in:
parent
8a711266ef
commit
9e9ef21a3d
8 changed files with 125 additions and 59 deletions
40
lib/yunq/message_view.h
Normal file
40
lib/yunq/message_view.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/buffer/byte_buffer.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
|
||||
namespace yunq {
|
||||
|
||||
const uint64_t kHeaderSize = 24; // 4x uint32, 1x uint64
|
||||
|
||||
struct ExtensionPointer {
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
};
|
||||
|
||||
class MessageView {
|
||||
public:
|
||||
MessageView(const glcr::ByteBuffer& buffer, uint64_t offset)
|
||||
: buffer_(buffer), offset_(offset) {}
|
||||
|
||||
// TODO: Implement glcr::StatusOr
|
||||
template <typename T>
|
||||
glcr::ErrorOr<T> ReadField(uint64_t field_index);
|
||||
|
||||
private:
|
||||
const glcr::ByteBuffer& buffer_;
|
||||
uint64_t offset_;
|
||||
|
||||
uint64_t field_offset(uint64_t field_index) {
|
||||
return offset_ + kHeaderSize + (8 * field_index);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
glcr::ErrorOr<uint64_t> MessageView::ReadField<uint64_t>(uint64_t field_index);
|
||||
|
||||
template <>
|
||||
glcr::ErrorOr<glcr::String> MessageView::ReadField<glcr::String>(
|
||||
uint64_t field_index);
|
||||
|
||||
} // namespace yunq
|
||||
Loading…
Add table
Add a link
Reference in a new issue