Skip to content

Commit

Permalink
Add comment about possible improvements in Get/SetBuf.
Browse files Browse the repository at this point in the history
  • Loading branch information
denravonska committed Jan 20, 2017
1 parent 6c457a9 commit a214584
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions N2kMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,25 +367,29 @@ int64_t byteswap(int64_t val) {
//*****************************************************************************
template<typename T>
T GetBuf(size_t len, int& index, const unsigned char* buf) {
T v{};
memcpy(&v, &buf[index], len);
T v{0};

// This could be improved by casting the buffer to a pointer of T and
// doing a direct copy. That is, if unaligned data access is allowed.
memcpy(&v, &buf[index], len);
index += len;

#if defined(HOST_IS_BIG_ENDIAN)
v = byteswap(v);
#endif

index += len;
return v;
}

//*****************************************************************************
template<typename T>
void SetBuf(T v, size_t len, int& index, unsigned char* buf) {

#if defined(HOST_IS_BIG_ENDIAN)
v = byteswap(v);
#endif


// This could be improved by casting the buffer to a pointer of T and
// doing a direct copy. That is, if unaligned data access is allowed.
memcpy(&buf[index], &v, len);
index += len;
}
Expand Down

0 comments on commit a214584

Please sign in to comment.