mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-19 17:37:43 +00:00
initial commit
This commit is contained in:
29
src/yesstr.h
Normal file
29
src/yesstr.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "golpe.h"
|
||||
|
||||
|
||||
inline void verifyYesstrRequest(std::string_view msg) {
|
||||
if (!msg.starts_with("Y")) throw herr("invalid yesstr magic char");
|
||||
msg = msg.substr(1);
|
||||
auto verifier = flatbuffers::Verifier(reinterpret_cast<const uint8_t*>(msg.data()), msg.size());
|
||||
bool ok = verifier.VerifyBuffer<Yesstr::Request>(nullptr);
|
||||
if (!ok) throw herr("yesstr request verification failed");
|
||||
}
|
||||
|
||||
inline void verifyYesstrResponse(std::string_view msg) {
|
||||
if (!msg.starts_with("Y")) throw herr("invalid yesstr magic char");
|
||||
msg = msg.substr(1);
|
||||
auto verifier = flatbuffers::Verifier(reinterpret_cast<const uint8_t*>(msg.data()), msg.size());
|
||||
bool ok = verifier.VerifyBuffer<Yesstr::Response>(nullptr);
|
||||
if (!ok) throw herr("yesstr response verification failed");
|
||||
}
|
||||
|
||||
|
||||
inline const Yesstr::Request *parseYesstrRequest(std::string_view msg) {
|
||||
return flatbuffers::GetRoot<Yesstr::Request>(msg.substr(1).data());
|
||||
}
|
||||
|
||||
inline const Yesstr::Response *parseYesstrResponse(std::string_view msg) {
|
||||
return flatbuffers::GetRoot<Yesstr::Response>(msg.substr(1).data());
|
||||
}
|
Reference in New Issue
Block a user