/* * This file is part of the Flowee project * Copyright (C) 2020-2021 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 . */ #ifndef FLOWEE_P2PPARSER_H #define FLOWEE_P2PPARSER_H #include #include #include namespace Streaming { class ParsingException : public std::runtime_error { public: ParsingException(const char *message); }; class P2PParser { public: P2PParser(const Message &message); P2PParser(const ConstBuffer &data); double readDouble(); std::string readString(); uint8_t readByte(); uint16_t readWord(); /// read word, but in big-endian uint16_t readWordBE(); uint32_t readInt(); uint64_t readLong(); uint64_t readCompactInt(); bool readBool(); std::vector readBytes(int32_t count); std::vector readUnsignedBytes(int32_t count); uint256 readUint256(); inline void skip(int32_t bytes) { if (bytes < 0 || static_cast(bytes) > remaining()) throw Streaming::ParsingException("Out of range"); m_data += bytes; } private: Streaming::ConstBuffer m_constBuffer; const char *m_privData; const char *m_data; const char *m_end; inline size_t remaining() const { return static_cast(m_end - m_data); } }; } #endif