/* * This file is part of the Flowee project * Copyright (C) 2025 Tom Zander * * 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 . */ #include "BindingMessageParser.h" namespace Streaming { BindingMessageParser::BindingMessageParser(const Message &message) : m_parser(message) { } BindingMessageParser::BindingMessageParser(const ConstBuffer &data) : m_parser(data) { } BindingMessageParser::~BindingMessageParser() { while (m_parser.next() == FoundTag) { for (size_t x = 0; x < m_bindings.size(); ++x) { Binding &binding = m_bindings.at(x); if (binding.tag == m_parser.tag()) { if (binding.boundInt) *binding.boundInt = m_parser.intData(); if (binding.boundLong) *binding.boundLong = m_parser.longData(); if (binding.boundDataCallbackSet) binding.boundDataCallback(m_parser.bytesDataBuffer()); if (binding.hash) *binding.hash = m_parser.uint256Data(); } } } } BindingMessageParser &BindingMessageParser::bind(uint32_t tag, int32_t *target) { Binding binding; binding.boundInt = target; binding.tag = tag; m_bindings.push_back(binding); return *this; } BindingMessageParser &BindingMessageParser::bind(uint32_t tag, uint64_t *target) { Binding binding; binding.boundLong = target; binding.tag = tag; m_bindings.push_back(binding); return *this; } BindingMessageParser &BindingMessageParser::bind(uint32_t tag, const std::function &f) { Binding binding; binding.boundDataCallback = f; binding.boundDataCallbackSet = true; binding.tag = tag; m_bindings.push_back(binding); return *this; } BindingMessageParser &BindingMessageParser::bind(uint32_t tag, uint256 *hash) { Binding binding; binding.hash = hash; binding.tag = tag; m_bindings.push_back(binding); return *this; } }