-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// zkInterface - integration helpers. | ||
// | ||
// @author Aurélien Nicolas <info@nau.re> for QED-it.com | ||
// @date 2020 | ||
|
||
#include "zkinterface_utils.hpp" | ||
|
||
namespace zkinterface_utils { | ||
|
||
uoffset_t read_size_prefix(void *buffer) { | ||
uoffset_t message_length = *reinterpret_cast<uoffset_t *>(buffer); | ||
return sizeof(uoffset_t) + message_length; | ||
} | ||
|
||
const Root *find_message(vector<char> &buffer, Message type) { | ||
auto offset = 0; | ||
|
||
while (offset + sizeof(uoffset_t) * 2 <= buffer.size()) { | ||
auto current = buffer.data() + offset; | ||
|
||
auto size = read_size_prefix(current); | ||
if (offset + size > buffer.size()) { | ||
throw "invalid offset"; | ||
} | ||
|
||
auto root = GetSizePrefixedRoot(current); | ||
|
||
if (root->message_type() == type) { | ||
return root; // Found. | ||
} | ||
|
||
offset += size; | ||
} | ||
|
||
throw MessageNotFoundException(); | ||
} | ||
} // namespace zkinterface_utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// zkInterface - integration helpers. | ||
// | ||
// @author Aurélien Nicolas <info@nau.re> for QED-it.com | ||
// @date 2020 | ||
|
||
#ifndef ZKINTERFACE_ZKINTERFACE_UTILS_HPP | ||
#define ZKINTERFACE_ZKINTERFACE_UTILS_HPP | ||
|
||
#include "zkinterface_generated.h" | ||
|
||
namespace zkinterface_utils { | ||
using namespace std; | ||
using namespace flatbuffers; | ||
using namespace zkinterface; | ||
|
||
|
||
// ==== Reading helpers ==== | ||
|
||
uoffset_t read_size_prefix(void *buffer); | ||
|
||
const Root *find_message(vector<char> &buffer, Message type); | ||
|
||
class MessageNotFoundException : public std::exception { | ||
public: | ||
inline const char *what() const throw() { | ||
return "message of the required type not found"; | ||
} | ||
}; | ||
|
||
} | ||
#endif //ZKINTERFACE_ZKINTERFACE_UTILS_HPP |