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.
251BOOST_CHECK(!reader.ReadLine());252}253{254// If ReadLine fails, the iterator is reset and we can ReadLength instead255std::string_view input = "a\nbaboon\n";256LineReader reader(input, /*max_line_length=*/1);257BOOST_CHECK_EQUAL(reader.ReadLine(), "a");258// "baboon" is too long259BOOST_CHECK_EXCEPTION(reader.ReadLine(), std::runtime_error, HasReason{"max_line_length exceeded by LineReader"});260BOOST_CHECK_EQUAL(reader.ReadLength(1), "b");261BOOST_CHECK_EQUAL(reader.ReadLength(1), "a");262BOOST_CHECK_EQUAL(reader.ReadLength(2), "bo");263// "on" is too long264BOOST_CHECK_EXCEPTION(reader.ReadLine(), std::runtime_error, HasReason{"max_line_length exceeded by LineReader"});265BOOST_CHECK_EQUAL(reader.ReadLength(1), "o");266BOOST_CHECK_EQUAL(reader.ReadLine(), "n"); // now the remainder of the buffer fits in one line267BOOST_CHECK(!reader.ReadLine());268}269{270// The end of the buffer (EOB) does not count as end of line \n271std::string_view input = "once upon a time there";273LineReader reader(input, /*max_line_length=*/22);274// First line is exactly the length of max_line_length, but that doesn't matter because \n is missing275BOOST_CHECK(!reader.ReadLine());276// Data can still be read using ReadLength277BOOST_CHECK_EQUAL(reader.ReadLength(22), "once upon a time there");278// End of buffer reached279BOOST_CHECK_EQUAL(reader.Remaining(), 0);280}281{282// Read specific number of bytes regardless of max_line_length or \n unless buffer is too short283std::string_view input = "once upon a time\n there was a dog \r\nwho liked food";284LineReader reader(input, /*max_line_length=*/1);285BOOST_CHECK_EQUAL(reader.ReadLength(0), "");286BOOST_CHECK_EQUAL(reader.ReadLength(3), "onc");287BOOST_CHECK_EQUAL(reader.ReadLength(8), "e upon a");288BOOST_CHECK_EQUAL(reader.ReadLength(8), " time\n t");289BOOST_CHECK_EXCEPTION(reader.ReadLength(128), std::runtime_error, HasReason{"Not enough data in buffer"});290// After the error the iterator is reset so we can try again291BOOST_CHECK_EQUAL(reader.ReadLength(31), "here was a dog \r\nwho liked food");292// End of buffer reached293BOOST_CHECK_EQUAL(reader.Remaining(), 0);294}295}297BOOST_AUTO_TEST_SUITE_END()
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.