Mercurial > hg > piper-cpp
diff vamp-client/CapnpMessageCompletenessChecker.h @ 90:6429a99abcad
Split out classes
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 13 Oct 2016 10:17:59 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vamp-client/CapnpMessageCompletenessChecker.h Thu Oct 13 10:17:59 2016 +0100 @@ -0,0 +1,38 @@ + +#ifndef CAPNP_MESSAGE_COMPLETENESS_CHECKER_H +#define CAPNP_MESSAGE_COMPLETENESS_CHECKER_H + +#include "SynchronousTransport.h" //!!! + +#include <capnp/serialize.h> + +#include <iostream> + +namespace piper { //!!! change + +class CapnpMessageCompletenessChecker : public MessageCompletenessChecker +{ +public: + bool isComplete(const std::vector<char> &message) const override { + + // a bit liberal with the copies here + size_t wordSize = sizeof(capnp::word); + size_t words = message.size() / wordSize; + kj::Array<capnp::word> karr(kj::heapArray<capnp::word>(words)); + memcpy(karr.begin(), message.data(), words * wordSize); + + size_t expected = capnp::expectedSizeInWordsFromPrefix(karr); + + if (words > expected) { + std::cerr << "WARNING: obtained more data than expected (" + << words << " " << wordSize << "-byte words, expected " + << expected << ")" << std::endl; + } + + return words >= expected; + } +}; + +} + +#endif