[ox/mc] Make read take const buffers

This commit is contained in:
Gary Talent 2021-04-17 16:37:58 -05:00
parent 772cc7d954
commit 394d13df9b
5 changed files with 9 additions and 8 deletions

View File

@ -114,7 +114,7 @@ static_assert(countBytes(0b01111111) == 8);
static_assert(countBytes(0b11111111) == 9);
template<typename I>
Result<I> decodeInteger(uint8_t buff[9], std::size_t buffLen, std::size_t *bytesRead) noexcept {
Result<I> decodeInteger(const uint8_t buff[9], std::size_t buffLen, std::size_t *bytesRead) noexcept {
const auto bytes = countBytes(buff[0]);
if (bytes == 9) {
*bytesRead = bytes;

View File

@ -12,8 +12,9 @@
namespace ox {
FieldPresenceIndicator::FieldPresenceIndicator(uint8_t *mask, std::size_t maxLen) {
m_mask = mask;
FieldPresenceIndicator::FieldPresenceIndicator(const uint8_t *mask, std::size_t maxLen) {
// TODO: have separate read only version of this class
m_mask = const_cast<uint8_t*>(mask);
m_maskLen = maxLen;
}

View File

@ -20,7 +20,7 @@ class FieldPresenceIndicator {
std::size_t m_fields = 0;
public:
FieldPresenceIndicator(uint8_t *mask, std::size_t maxLen);
FieldPresenceIndicator(const uint8_t *mask, std::size_t maxLen);
Result<bool> get(std::size_t i) const;

View File

@ -14,7 +14,7 @@
namespace ox {
MetalClawReader::MetalClawReader(uint8_t *buff, std::size_t buffLen, int unionIdx, MetalClawReader *parent) noexcept:
MetalClawReader::MetalClawReader(const uint8_t *buff, std::size_t buffLen, int unionIdx, MetalClawReader *parent) noexcept:
m_fieldPresence(buff, buffLen),
m_unionIdx(unionIdx),
m_buffLen(buffLen),

View File

@ -31,11 +31,11 @@ class MetalClawReader {
int m_unionIdx = -1;
std::size_t m_buffIt = 0;
std::size_t m_buffLen = 0;
uint8_t *m_buff = nullptr;
const uint8_t *m_buff = nullptr;
MetalClawReader *m_parent = nullptr;
public:
MetalClawReader(uint8_t *buff, std::size_t buffLen, int unionIdx = -1, MetalClawReader *parent = nullptr) noexcept;
MetalClawReader(const uint8_t *buff, std::size_t buffLen, int unionIdx = -1, MetalClawReader *parent = nullptr) noexcept;
~MetalClawReader() noexcept;
@ -273,7 +273,7 @@ void MetalClawReader::setTypeInfo(const char*, int fields) {
}
template<typename T>
Error readMC(uint8_t *buff, std::size_t buffLen, T *val) {
Error readMC(const uint8_t *buff, std::size_t buffLen, T *val) {
MetalClawReader reader(buff, buffLen);
return model(&reader, val);
}