Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251{252std::ostringstream oss;253oss.imbue(std::locale::classic());254oss << t;255return oss.str();256}258/**259* Check whether a container begins with the given prefix.260*/261template <typename T1, size_t PREFIX_LEN>262[[nodiscard]] inline bool HasPrefix(const T1& obj,263const std::array<uint8_t, PREFIX_LEN>& prefix)264{265return obj.size() >= PREFIX_LEN &&266std::equal(std::begin(prefix), std::end(prefix), std::begin(obj));267}269class LineReader270{271const std::string_view m_str;272const size_t m_max_line_length;273std::string_view::iterator m_it;275public:276explicit LineReader(std::string_view str LIFETIMEBOUND, size_t max_line_length);278/**279* Returns a string from current iterator position up to (but not including) next \n280* and advances iterator to the character following the \n on success.281* Will not return a line longer than max_line_length.282* @returns the next string from the buffer.283* std::nullopt if end of buffer is reached without finding a \n.284* @throws a std::runtime_error if max_line_length + 1 bytes are read without finding \n.285*/286std::optional<std::string_view> ReadLine() LIFETIMEBOUND;288/**289* Returns string from current iterator position of specified length290* if possible and advances iterator on success.291* May exceed max_line_length but will not read past end of buffer.292* @param[in] len The number of bytes to read from the buffer293* @returns a string of the expected length.294* @throws a std::runtime_error if there is not enough data in the buffer.295*/296std::string_view ReadLength(size_t len) LIFETIMEBOUND;298/**299* Returns remaining size of bytes in buffer300*/301size_t Remaining() const;303/**304* Returns number of bytes already read from buffer305*/306size_t Consumed() const;307};308} // namespace util310#endif // BITCOIN_UTIL_STRING_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.