diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-21 19:41:33 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-21 19:41:33 +0000 |
commit | e7c1a4fc8c55795f707e83ce6d5607e0b41f5099 (patch) | |
tree | 4c862cd6dadd3b8abf75c5431e07175d68391eec /document | |
parent | 28e18ba48168b6ea3ca09164c647c96fe261a74a (diff) |
Add stream method and use memcpy over casting.
Diffstat (limited to 'document')
-rw-r--r-- | document/src/vespa/document/util/bytebuffer.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/document/src/vespa/document/util/bytebuffer.cpp b/document/src/vespa/document/util/bytebuffer.cpp index c6d760d597c..45d86cdc41e 100644 --- a/document/src/vespa/document/util/bytebuffer.cpp +++ b/document/src/vespa/document/util/bytebuffer.cpp @@ -128,7 +128,8 @@ void ByteBuffer::getNumericNetwork(int16_t & v) { if (__builtin_expect(getRemaining() < sizeof(v), 0)) { throwOutOfBounds(getRemaining(), sizeof(v)); } else { - uint16_t val = *reinterpret_cast<const uint16_t *>(getBufferAtPos()); + uint16_t val; + memcpy(&val, getBufferAtPos(), sizeof(val)); v = ntohs(val); incPosNoCheck(sizeof(v)); } @@ -138,7 +139,8 @@ void ByteBuffer::getNumericNetwork(int32_t & v) { if (__builtin_expect(getRemaining() < sizeof(v), 0)) { throwOutOfBounds(getRemaining(), sizeof(v)); } else { - uint32_t val = *reinterpret_cast<const uint32_t *>(getBufferAtPos()); + uint32_t val; + memcpy(&val, getBufferAtPos(), sizeof(val)); v = ntohl(val); incPosNoCheck(sizeof(v)); } @@ -148,7 +150,7 @@ void ByteBuffer::getNumeric(int64_t& v) { if (__builtin_expect(getRemaining() < sizeof(v), 0)) { throwOutOfBounds(getRemaining(), sizeof(v)); } else { - v = *reinterpret_cast<const int64_t *>(getBufferAtPos()); + memcpy(&v, getBufferAtPos(), sizeof(v)); incPosNoCheck(sizeof(v)); } } |