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