Skip to content

Commit

Permalink
libcore: Added a helper method for MD5 hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Oct 28, 2017
1 parent ef9d6f9 commit 001570e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doomsday/sdk/libcore/include/de/data/block.h
Expand Up @@ -23,6 +23,7 @@
#include "../IByteArray"
#include "../IBlock"
#include "../ISerializable"
#include "../Writer"

#include <QByteArray>

Expand Down Expand Up @@ -137,6 +138,14 @@ class DENG2_PUBLIC Block : public QByteArray, public IByteArray, public IBlock,
static Block join(QList<Block> const &blocks, Block const &sep = Block());
};

template <typename... Args>
Block md5Hash(Args... args) {
Block data;
Writer writer(data);
writer.writeMultiple(args...);
return data.md5Hash();
}

} // namespace de

#endif // LIBDENG2_BLOCK_H
11 changes: 11 additions & 0 deletions doomsday/sdk/libcore/include/de/data/writer.h
Expand Up @@ -239,6 +239,17 @@ class DENG2_PUBLIC Writer
return *this;
}

template <typename Type>
Writer &writeMultiple(Type const &value) {
return *this << value;
}

template <typename Type, typename... Args>
Writer &writeMultiple(Type const &value, Args... args) {
*this << value;
return writeMultiple(args...);
}

/**
* Returns the destination byte array used by the writer.
*/
Expand Down

0 comments on commit 001570e

Please sign in to comment.