netmessagemaker.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2018 The Bitcoin Core developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef BITCOIN_NETMESSAGEMAKER_H
  6. #define BITCOIN_NETMESSAGEMAKER_H
  7. #include <net.h>
  8. #include <serialize.h>
  9. class CNetMsgMaker
  10. {
  11. public:
  12. explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){}
  13. template <typename... Args>
  14. CSerializedNetMsg Make(int nFlags, std::string sCommand, Args&&... args) const
  15. {
  16. CSerializedNetMsg msg;
  17. msg.command = std::move(sCommand);
  18. CVectorWriter{ SER_NETWORK, nFlags | nVersion, msg.data, 0, std::forward<Args>(args)... };
  19. return msg;
  20. }
  21. template <typename... Args>
  22. CSerializedNetMsg Make(std::string sCommand, Args&&... args) const
  23. {
  24. return Make(0, std::move(sCommand), std::forward<Args>(args)...);
  25. }
  26. private:
  27. const int nVersion;
  28. };
  29. #endif // BITCOIN_NETMESSAGEMAKER_H