#include "message_view.h" namespace yunq { namespace { const uint64_t kIdentByte = 0x33441122; } // namespace glcr::Status MessageView::CheckHeader() const { if (buffer_.At(offset_ + 0) != kIdentByte) { return glcr::InvalidArgument("Trying to parse an invalid yunq message."); } // TODO: Parse core size. // TODO: Parse extension size. // TODO: Check CRC32 // TODO: Parse options. return glcr::Status::Ok(); } uint32_t MessageView::MessageLength() const { return buffer_.At(offset_ + 8); } template <> glcr::ErrorOr MessageView::ReadField( uint64_t field_index) const { return buffer_.At(field_offset(field_index)); } template <> glcr::ErrorOr MessageView::ReadField( uint64_t field_index) const { return buffer_.At(field_offset(field_index)); } template <> glcr::ErrorOr MessageView::ReadField( uint64_t field_index) const { ExtensionPointer ptr = buffer_.At(field_offset(field_index)); return buffer_.StringAt(offset_ + ptr.offset, ptr.length); } template <> glcr::ErrorOr> MessageView::ReadRepeated( uint64_t field_index) const { ExtensionPointer pointer = buffer_.At(field_offset(field_index)); glcr::Vector 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(i)); } return v; } glcr::ErrorOr MessageView::ReadCapability( uint64_t field_index) const { return buffer_.At(field_offset(field_index)); } glcr::ErrorOr MessageView::ReadCapability( uint64_t field_index, const glcr::CapBuffer& caps) const { uint64_t offset = buffer_.At(field_offset(field_index)); return caps.At(offset); } } // namespace yunq