From fa6ba740688b86d3f5a9d94ce1cac130d91e1855 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Tue, 4 Mar 2025 11:44:40 +0100 Subject: [PATCH] operator<< for VarInt --- include/sp/common/VarInt.h | 6 ++++++ src/sp/common/VarInt.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/sp/common/VarInt.h b/include/sp/common/VarInt.h index 4d9e601..91e2673 100644 --- a/include/sp/common/VarInt.h +++ b/include/sp/common/VarInt.h @@ -7,6 +7,7 @@ #include #include +#include namespace sp { @@ -55,6 +56,11 @@ class VarInt { * \param var The variable integer to deserialize */ friend DataBuffer& operator>>(DataBuffer& in, VarInt& var); + + /** + * \brief overriding stream operator + */ + friend std::ostream& operator<<(std::ostream& a_Stream, const sp::VarInt& a_VarInt); }; } // namespace sp diff --git a/src/sp/common/VarInt.cpp b/src/sp/common/VarInt.cpp index 534a94d..4e6ea27 100644 --- a/src/sp/common/VarInt.cpp +++ b/src/sp/common/VarInt.cpp @@ -1,7 +1,7 @@ #include -#include #include +#include namespace sp { @@ -49,4 +49,9 @@ DataBuffer& operator>>(DataBuffer& in, VarInt& var) { return in; } +std::ostream& operator<<(std::ostream& a_Stream, const sp::VarInt& a_VarInt) { + a_Stream << a_VarInt.GetValue(); + return a_Stream; +} + } // namespace sp