/* * This file is part of the Flowee project * Copyright (C) 2016,2018-2020 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_P2PBUILDER_H #define FLOWEE_P2PBUILDER_H #include "ConstBuffer.h" #include #include namespace Streaming { enum LengthIndicator { RawBytes, WithLength }; class BufferPool; class P2PBuilder { public: P2PBuilder(const std::shared_ptr &pool); /// add an utf8 string void writeString(const std::string &value, LengthIndicator length); inline void writeString(const char *utf8String, LengthIndicator length) { return writeString(std::string(utf8String), length); } void writeByteArray(const ConstBuffer &data, LengthIndicator length); void writeByteArray(const void *data, int bytes, LengthIndicator length); inline void writeByteArray(const std::vector &data, LengthIndicator length) { writeByteArray(data.data(), static_cast(data.size()), length); } inline void writeByteArray(const std::vector &data, LengthIndicator length) { writeByteArray(reinterpret_cast(data.data()), static_cast(data.size()), length); } void writeLong(uint64_t value); void writeBool(bool value); void writeInt(int32_t value); void writeFloat(double value); template void writeByteArray(const base_blob &value, LengthIndicator length) { writeByteArray(static_cast(value.begin()), static_cast(value.size()), length); } inline void writeFloat(float value) { writeFloat((double) value); } void writeCompactSize(uint64_t value); void writeByte(uint8_t value); void writeWord(uint16_t value); ConstBuffer buffer(); /** * Create a message based on the build data and the argument header-data. */ Message message(int messageId = -1); private: std::shared_ptr m_buffer; }; } #endif