Files
thehub/libs/utils/streaming/BindingMessageParser.h

59 lines
1.7 KiB
C++

/*
* This file is part of the Flowee project
* Copyright (C) 2025 Tom Zander <tom@flowee.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BINDINGMESSAGEPARSER_H
#define BINDINGMESSAGEPARSER_H
#include "../Message.h"
#include "MessageParser.h"
#include "ConstBuffer.h"
#include <functional>
namespace Streaming {
class BindingMessageParser
{
public:
BindingMessageParser(const Message &message);
BindingMessageParser(const Streaming::ConstBuffer &data);
~BindingMessageParser();
BindingMessageParser &bind(uint32_t tag, int32_t *target);
BindingMessageParser &bind(uint32_t tag, uint64_t *target);
BindingMessageParser &bind(uint32_t tag,
const std::function<void(Streaming::ConstBuffer)> &f);
BindingMessageParser &bind(uint32_t tag, uint256 *hash);
private:
MessageParser m_parser;
struct Binding {
int *boundInt = nullptr;
uint64_t *boundLong = nullptr;
std::function<void(Streaming::ConstBuffer)> boundDataCallback;
bool boundDataCallbackSet = false;
uint256 *hash = nullptr;
uint32_t tag = 0;
};
std::vector<Binding> m_bindings;
};
}
#endif