annotate 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
rev   line source
c@90 1
c@90 2 #ifndef CAPNP_MESSAGE_COMPLETENESS_CHECKER_H
c@90 3 #define CAPNP_MESSAGE_COMPLETENESS_CHECKER_H
c@90 4
c@90 5 #include "SynchronousTransport.h" //!!!
c@90 6
c@90 7 #include <capnp/serialize.h>
c@90 8
c@90 9 #include <iostream>
c@90 10
c@90 11 namespace piper { //!!! change
c@90 12
c@90 13 class CapnpMessageCompletenessChecker : public MessageCompletenessChecker
c@90 14 {
c@90 15 public:
c@90 16 bool isComplete(const std::vector<char> &message) const override {
c@90 17
c@90 18 // a bit liberal with the copies here
c@90 19 size_t wordSize = sizeof(capnp::word);
c@90 20 size_t words = message.size() / wordSize;
c@90 21 kj::Array<capnp::word> karr(kj::heapArray<capnp::word>(words));
c@90 22 memcpy(karr.begin(), message.data(), words * wordSize);
c@90 23
c@90 24 size_t expected = capnp::expectedSizeInWordsFromPrefix(karr);
c@90 25
c@90 26 if (words > expected) {
c@90 27 std::cerr << "WARNING: obtained more data than expected ("
c@90 28 << words << " " << wordSize << "-byte words, expected "
c@90 29 << expected << ")" << std::endl;
c@90 30 }
c@90 31
c@90 32 return words >= expected;
c@90 33 }
c@90 34 };
c@90 35
c@90 36 }
c@90 37
c@90 38 #endif